Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,66 @@ concurrency:
cancel-in-progress: true

jobs:
test_database:
name: Test database compatibility
runs-on: ubuntu-24.04
timeout-minutes: 20
# Disposable databases; these passwords are local test credentials only.
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: ArtalkTestOnly123
POSTGRES_DB: artalk_test
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-timeout 5s --health-retries 20
mysql:
image: mysql:8.4
env:
MYSQL_ROOT_PASSWORD: ArtalkTestOnly123
MYSQL_DATABASE: artalk_test
ports: ["3306:3306"]
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -pArtalkTestOnly123"
--health-interval 5s --health-timeout 5s --health-retries 20
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
MSSQL_PID: Developer
MSSQL_SA_PASSWORD: ArtalkTestOnly123
ports: ["1433:1433"]
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ArtalkTestOnly123 -Q 'SELECT 1'"
--health-interval 5s --health-timeout 5s --health-retries 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
- name: PostgreSQL
env:
ARTALK_TEST_DB_TYPE: pgsql
ARTALK_TEST_DB_DSN: host=127.0.0.1 port=5432 user=postgres password=ArtalkTestOnly123 dbname=artalk_test sslmode=disable
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v
- name: MySQL
if: ${{ !cancelled() }}
env:
ARTALK_TEST_DB_TYPE: mysql
ARTALK_TEST_DB_DSN: root:ArtalkTestOnly123@tcp(127.0.0.1:3306)/artalk_test?charset=utf8mb4&parseTime=True&loc=UTC
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v
- name: SQL Server
if: ${{ !cancelled() }}
env:
ARTALK_TEST_DB_TYPE: mssql
ARTALK_TEST_DB_DSN: sqlserver://sa:ArtalkTestOnly123@127.0.0.1:1433?database=master&encrypt=disable
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v

test_app:
name: Test Go (${{ matrix.name }})
runs-on: ${{ matrix.runner }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Test Docs

on:
push:
paths: ["docs/**"]
paths: [".github/workflows/test-docs.yml", "docs/**", "ui/**", "package.json", "pnpm-lock.yaml"]
branches-ignore: ["release/*", "nightly"]
tags-ignore: ["v*"]
pull_request:
paths: ["docs/**"]
paths: [".github/workflows/test-docs.yml", "docs/**", "ui/**", "package.json", "pnpm-lock.yaml"]
branches-ignore: ["release/*", "nightly"]

permissions:
Expand Down
3 changes: 3 additions & 0 deletions conf/artalk.example.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ cache:
password: ""
db: 0
trusted_domains: []

# Auto-fetch page titles (Disabled by default for security; manual fetching remains available)
page_title_auto_fetch: false
ssl:
enabled: false
cert_path: ""
Expand Down
3 changes: 3 additions & 0 deletions conf/artalk.example.tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ cache:
# -- örn. ["https://artalk.example.com:23366"] sitenizin URL'sini buraya ekleyin --
trusted_domains: []

# Sayfa başlıklarını otomatik al (Güvenlik için varsayılan olarak kapalıdır; elle alma kullanılabilir)
page_title_auto_fetch: false

# SSL
ssl:
# SSL'i etkinleştir
Expand Down
3 changes: 3 additions & 0 deletions conf/artalk.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ cache:
# -- e.g. ["https://artalk.example.com:23366"] add url of your site her --
trusted_domains: []

# Auto-fetch page titles (Disabled by default for security; manual fetching remains available)
page_title_auto_fetch: false

# SSL
ssl:
# Enable SSL
Expand Down
3 changes: 3 additions & 0 deletions conf/artalk.example.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ cache:
# -- 例如:["https://artalk.example.com:23366"] --
trusted_domains: []

# 自动抓取页面标题 (关闭可禁用标题自动抓取功能(可以手动抓取),提高安全性)
page_title_auto_fetch: false

# SSL
ssl:
# 启用 SSL
Expand Down
3 changes: 3 additions & 0 deletions conf/artalk.example.zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ cache:
# -- 例如:["https://artalk.example.com:23366"] --
trusted_domains: []

# 自動擷取頁面標題 (關閉可停用標題自動擷取功能(可以手動擷取),提高安全性)
page_title_auto_fetch: false

# SSL
ssl:
# 啟用 SSL
Expand Down
17 changes: 17 additions & 0 deletions docs/docs/en/guide/backend/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ Note that environment variables will override the settings in the configuration

Technical details: `trusted_domains` configuration controls cross-origin requests by setting the HTTP response header `Access-Control-Allow-Origin` (refer to: [W3C Cross-Origin Resource Sharing](https://fetch.spec.whatwg.org/#http-cors-protocol) / [OWASP Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html)).

Page-title fetching uses the same trusted list: `trusted_domains` and the site URLs configured in the dashboard. The initial request and every HTTP or HTML redirect must match a listed scheme, host, and port. Paths in configuration entries are ignored; `*` does not authorize arbitrary destinations. If your pages redirect to another origin, add that site's URL as well.

Explicitly listed private-network sites and `localhost` remain supported, as do the server's `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment settings. Only add sites you trust Artalk to access: this list also authorizes outbound requests to those sites.

When enabled, automatic title discovery triggered by comments starts at most one task per second per Artalk instance, with at most four tasks running concurrently. An in-progress URL is not fetched again. When busy, automatic discovery is skipped without affecting comment submission; a later comment or a dashboard refresh can retry it. Manual and bulk administrator refreshes bypass the automatic-task rate limit but still check the trusted list. Each task follows at most 10 redirects and has a 30-second total deadline. Only the first 2 MiB of the document head are read, so a large body does not invalidate an already-read title.

## Auto-Fetch Page Titles `page_title_auto_fetch`

```yaml
# Disabled by default for security; manual fetching remains available.
page_title_auto_fetch: false
```

Disabled by default, including when omitted from an existing configuration. Setting it to `true` allows comments to trigger automatic fetching for pages without titles. Titles supplied by clients are still saved, and page creation and page-view counting are unaffected. Administrators can still manually refresh individual or all page titles. Manual fetching continues to enforce trusted origins, timeouts, size limits, and redirect limits.

Set `ATK_PAGE_TITLE_AUTO_FETCH=true` to enable it through an environment variable.

## Default Site `site_default`

If you think you won't use the multi-site feature of Artalk, you can directly set this item to your site name, for example:
Expand Down
1 change: 1 addition & 0 deletions docs/docs/en/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ATK_TRUSTED_DOMAINS_0="https://a.com"
| **ATK_HOST** | `"0.0.0.0"` | Listen host | host (Listen host) |
| **ATK_LOCALE** | `"en"` | Language (follow Unicode BCP 47) (可选:`["en", "zh-CN", "zh-TW", "ja", "fr", "ko", "ru", "tr"]`) | locale (Language) |
| **ATK_LOGIN_TIMEOUT** | `259200` | Login timeout (in seconds) | login_timeout (Login timeout) |
| **ATK_PAGE_TITLE_AUTO_FETCH** | `false` | Auto-fetch page titles (Disabled by default for security; manual fetching remains available) | page_title_auto_fetch (Auto-fetch page titles) |
| **ATK_PORT** | `23366` | Listen port | port (Listen port) |
| **ATK_SITE_DEFAULT** | `"Default Site"` | Default site name (create when app is first launched) | site_default (Default site name) |
| **ATK_SITE_URL** | `""` | Default site url | site_url (Default site url) |
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/en/guide/frontend/pv.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ In this case, the corresponding HTML code should be as follows:
```

Thus, the value of the `data-path` attribute will be used to query the specified page.

## Automatic page registration and abuse protection

Pages are still registered automatically on their first visit and start accumulating views without manual setup. To limit database writes from random page keys, each server process allows PV requests to create up to 60 pages per IP and 600 pages in total per one-minute window, shared across sites. These quotas are independent of captcha settings.

Once a quota is reached, that new-page registration is skipped and the request returns a PV of 0 without prompting for a captcha. A later visit can try again after the window resets; skipped views are not counted retroactively. Existing pages continue accumulating views, and comment submissions follow their existing validation flow. Behind a reverse proxy, configure trusted proxies correctly so the server can identify visitors' IP addresses.

The control center page list shows only pages with comments, including pages with only pending comments. Filtering does not delete records or change page views, votes, or other statistics. The page list API keeps `has_comments` optional: omitting it still returns all pages for existing clients.
17 changes: 17 additions & 0 deletions docs/docs/zh/guide/backend/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ ATK_TRUSTED_DOMAINS="https://a.com https://b.org" artalk server

技术细节:`trusted_domains` 配置通过控制 HTTP 响应标头 `Access-Control-Allow-Origin` 来对跨域请求进行限制 (参考:[W3C Cross-Origin Resource Sharing](https://fetch.spec.whatwg.org/#http-cors-protocol) / [OWASP 安全备忘单](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html)).

页面标题抓取也使用这份可信名单,包括 `trusted_domains` 和后台配置的站点 URL。首次请求、HTTP 跳转及 HTML 跳转的目标都必须匹配名单中的协议、主机和端口;配置中的路径不参与匹配,不支持用 `*` 放行任意地址。跨域跳转到另一个自己的站点时,也需要加入该站点的 URL。

明确加入名单的内网站点及 `localhost` 可以正常抓取,服务器上的 `HTTP_PROXY`、`HTTPS_PROXY`、`NO_PROXY` 配置仍然生效。请只加入你信任并允许 Artalk 访问的站点:这份名单同时授权服务器向这些站点发起请求。

开启自动抓取后,评论触发的自动补标题每个 Artalk 实例每秒最多启动一个任务,最多同时执行四个,相同 URL 的进行中任务不会重复执行。繁忙时跳过本次自动补标题,不影响评论提交,后续评论或后台刷新可以重试。管理员手动、批量刷新不受自动任务频率限制,但仍检查可信名单。每个任务最多跟随 10 次跳转,总耗时最多 30 秒;只读取页面头部的前 2 MiB,大页面的正文不会导致已读取的标题失效。

## 自动抓取页面标题 `page_title_auto_fetch`

```yaml
# 关闭可禁用标题自动抓取功能(可以手动抓取),提高安全性
page_title_auto_fetch: false
```

默认关闭,旧配置省略此项也不会自动抓取。只有设为 `true` 后,提交评论才可能为缺少标题的页面触发自动抓取。客户端提交的页面标题仍正常保存,页面创建和 PV 统计不受影响。管理员仍可在后台手动更新单个页面或全部页面的标题,手动抓取仍受可信域名检查及抓取超时、大小和跳转限制约束。

也可通过环境变量 `ATK_PAGE_TITLE_AUTO_FETCH=true` 开启。

## 默认站点 `site_default`

如果你觉得大概是不会用到 Artalk 的多站点功能,可以直接将该项配置为你的站点名,例如:
Expand Down
1 change: 1 addition & 0 deletions docs/docs/zh/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ ATK_TRUSTED_DOMAINS_0="https://a.com"
| **ATK_HOST** | `"0.0.0.0"` | 服务器地址 | host (服务器地址) |
| **ATK_LOCALE** | `"zh-CN"` | 语言 (可选:`["en", "zh-CN", "zh-TW", "ja", "fr", "ko", "ru"]`) | locale (语言) |
| **ATK_LOGIN_TIMEOUT** | `259200` | 登录有效时长 (单位:秒) | login_timeout (登录有效时长) |
| **ATK_PAGE_TITLE_AUTO_FETCH** | `false` | 自动抓取页面标题 (关闭可禁用标题自动抓取功能(可以手动抓取),提高安全性) | page_title_auto_fetch (自动抓取页面标题) |
| **ATK_PORT** | `23366` | 服务器端口 | port (服务器端口) |
| **ATK_SITE_DEFAULT** | `"默认站点"` | 默认站点名 | site_default (默认站点名) |
| **ATK_SITE_URL** | `""` | 默认站点地址 | site_url (默认站点地址) |
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/zh/guide/frontend/pv.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ Artalk.loadCountWidget({
```

这样,`data-path` 属性值将被用于查询指定的页面。

## 自动登记页面与防滥用

页面首次访问时仍会自动登记并累计 PV,无需预先创建页面。为限制通过随机页面地址批量写入数据,每个服务进程在一分钟窗口内最多允许每个 IP 通过 PV 请求创建 60 个页面,总计 600 个页面;不同站点共用此额度。额度独立于验证码设置。

达到额度后,仅跳过该次新页面登记,返回 PV 为 0,不弹出验证码。窗口重置后的访问可以重新尝试;跳过的访问不会事后补计。已有页面继续正常累计 PV,评论提交仍按原有验证流程处理。使用反向代理时,请正确配置可信代理,以便服务器识别访问者 IP。

控制中心的页面列表只显示有评论的页面(包括只有待审核评论的页面)。过滤不会删除记录或改变 PV、投票等统计。页面列表 API 的 `has_comments` 是可选参数;省略时仍返回全部页面,兼容已有客户端。
41 changes: 39 additions & 2 deletions docs/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,12 @@ const docTemplate = `{
},
"/notifies": {
"get": {
"description": "Get a list of notifies for user",
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Get unread notifications owned by the authenticated user or anonymous comment credential",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -1294,7 +1299,12 @@ const docTemplate = `{
},
"/notifies/read": {
"post": {
"description": "Mark all notifies as read for user",
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Mark owned notifications as read using a login or anonymous comment credential",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -1342,6 +1352,24 @@ const docTemplate = `{
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.Map"
},
{
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
Expand Down Expand Up @@ -1474,6 +1502,12 @@ const docTemplate = `{
"summary": "Get Page List",
"operationId": "GetPages",
"parameters": [
{
"type": "boolean",
"description": "Only include pages with comments (including pending comments)",
"name": "has_comments",
"in": "query"
},
{
"type": "integer",
"description": "The limit for pagination",
Expand Down Expand Up @@ -5153,6 +5187,9 @@ const docTemplate = `{
"anonymous": {
"type": "boolean"
},
"callback_origin": {
"type": "string"
},
"providers": {
"type": "array",
"items": {
Expand Down
41 changes: 39 additions & 2 deletions docs/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,12 @@
},
"/notifies": {
"get": {
"description": "Get a list of notifies for user",
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Get unread notifications owned by the authenticated user or anonymous comment credential",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -1287,7 +1292,12 @@
},
"/notifies/read": {
"post": {
"description": "Mark all notifies as read for user",
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Mark owned notifications as read using a login or anonymous comment credential",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -1335,6 +1345,24 @@
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.Map"
},
{
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
Expand Down Expand Up @@ -1467,6 +1495,12 @@
"summary": "Get Page List",
"operationId": "GetPages",
"parameters": [
{
"type": "boolean",
"description": "Only include pages with comments (including pending comments)",
"name": "has_comments",
"in": "query"
},
{
"type": "integer",
"description": "The limit for pagination",
Expand Down Expand Up @@ -5146,6 +5180,9 @@
"anonymous": {
"type": "boolean"
},
"callback_origin": {
"type": "string"
},
"providers": {
"type": "array",
"items": {
Expand Down
Loading
Loading