Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(conf/upgit): disallow custom executable path of upgit for security #817

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/artalk.example.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ img_upload:
public_path: null
upgit:
enabled: false
exec: "./upgit -c UPGIT_CONF_FILE_PATH -t /artalk-img"
exec: "upgit -c UPGIT_CONF_FILE_PATH -t /artalk-img"
del_local: true
email:
enabled: false
Expand Down
2 changes: 1 addition & 1 deletion conf/artalk.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ img_upload:
# Enable Upgit
enabled: false
# Command line arguments
exec: "./upgit -c UPGIT_CONF_FILE_PATH -t /artalk-img"
exec: "upgit -c UPGIT_CONF_FILE_PATH -t /artalk-img"
# Delete local image after upload success
del_local: true

Expand Down
2 changes: 1 addition & 1 deletion conf/artalk.example.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ img_upload:
# 启用 Upgit
enabled: false
# 命令行参数
exec: "./upgit -c <upgit配置文件路径> -t /artalk-img"
exec: "upgit -c <upgit配置文件路径> -t /artalk-img"
# 上传后删除本地的图片
del_local: true

Expand Down
32 changes: 26 additions & 6 deletions docs/docs/guide/backend/img-upload.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 图片上传

Artalk 提供图片上传功能,支持限制图片大小、上传频率等,你还能结合 upgit 将图片上传到图床。
Artalk 提供图片上传功能,支持限制图片大小、上传频率等,你还能结合 UpGit 将图片上传到图床。

你可以在[控制中心](/guide/frontend/sidebar.md#控制中心)找到「设置」界面修改此配置。

Expand All @@ -18,25 +18,45 @@ img_upload:
# 使用 upgit 将图片上传到 GitHub 或图床
upgit:
enabled: false # 启用 upgit
exec: "./upgit -c <upgit配置文件路径> -t /artalk-img"
exec: "upgit -c <upgit配置文件路径> -t /artalk-img"
del_local: true # 上传后删除本地的图片
```

## 使用 Upgit 上传到图床

[Upgit](https://github.com/pluveto/upgit) 支持将图片上传到 Github、Gitee、腾讯云 COS、七牛云、又拍云、SM.MS 等图床或代码仓库。
[UpGit](https://github.com/pluveto/upgit) 支持将图片上传到 Github、Gitee、腾讯云 COS、七牛云、又拍云、SM.MS 等图床或代码仓库。

首先,根据 [README.md](https://github.com/pluveto/upgit) 的说明,下载 Upgit 并完成你需要上传的目标图床的配置。
首先,根据 [README.md](https://github.com/pluveto/upgit) 的说明,下载 UpGit 并完成你需要上传的目标图床的配置。

然后在 Artalk 的 `img_upload.upgit` 字段填入 Upgit 启动参数 (建议使用程序绝对路径),例如:
然后,将 UpGit 加入系统的环境变量中,在 `~/.bashrc` 加入:

```bash
export PATH=$PATH:/path/to/upgit
```

(或者直接移入 `/usr/bin`)

最后,在 Artalk 的 `img_upload.upgit` 字段填入 UpGit 启动参数:

```yaml
upgit:
enabled: true # 启用 upgit
exec: "/root/upgit -c <upgit配置文件路径> -t /artalk-img"
exec: "upgit -c <upgit配置文件路径> -t /artalk-img"
del_local: true # 上传后删除本地的图片
```

::: warning 更新注意
从 `v2.8.4` 版本开始,为了增强安全性,Artalk 不再允许指定 UpGit 的可执行文件路径,请将其加入系统的环境变量中。:)
:::

### Docker 挂载 UpGit

如果你使用 Docker 部署 Artalk,可以将 UpGit 可执行文件挂载到容器中:

```bash
docker run -d --name artalk -v /path/to/upgit:/usr/bin/upgit -v /path/to/artalk:/app/data -p 8080:23366 artalk
```

## 上传频率限制

频率限制跟随 `captcha` 验证码配置,当超出限制将弹出验证码。
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guide/frontend/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ artalk.update({ ... })

::: warning 更新注意

v2.2.6+ 的后续版本,请填入不带 `/api/` 路径的后端 URL
v2.2.6 版本开始,`server` 无需在结尾带上 `/api/` 路径

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guide/frontend/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Artalk.init({
```js
Artalk.init({
locale: {
placeholder: 'こんにちは',
email: 'Eメール',
//...
}
})
Expand Down
19 changes: 9 additions & 10 deletions server/handler/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,21 @@ func Upload(app *core.App, router fiber.Router) {
}))
}

// 调用 upgit 上传图片获得 URL
// Call UpGit to upload images
func execUpgitUpload(execCommand string, filename string) string {
LogTag := "[IMG_UPLOAD] [upgit] "

// 处理参数
// Separate the command and arguments
cmdStrSplitted := strings.Split(execCommand, " ")
execApp := cmdStrSplitted[0]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An attacker may modify the configuration file and enter rm -rf /* if Artalk gives high permissions. So remove it!

execArgs := []string{}
for i, arg := range cmdStrSplitted {
if i > 0 {
execArgs = append(execArgs, arg)
}
}

// For security reasons, Artalk no longer allows you to specify the executable file path of UpGit.
// execApp := cmdStrSplitted[0]
execApp := "upgit"

execArgs := cmdStrSplitted[1:]
execArgs = append(execArgs, filename)

// 执行命令
// Execute the command
cmd := exec.Command(execApp, execArgs...)
stdout, _ := cmd.StdoutPipe()

Expand Down