feat: add first-run setup security flow

This commit is contained in:
Lan committed 2026-06-16 00:49:43 +08:00
1 parent 1b6d8e7277
commit cdaf3638b8
24 files changed
+1127 -64

No files matched your search

+2 -2
View File
@@ -22,7 +22,7 @@ Authorization: Bearer <token>
```bash
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
-d '{"password": "<初始化时设置的管理员密码>"}'
```
**响应示例:**
@@ -329,4 +329,4 @@ curl -L "http://localhost:12345/share/select/?code=abc123" -o downloaded_file
- 403: 禁止访问
- 404: 资源不存在
- 422: 请求参数验证错误
- 500: 服务器内部错误
- 500: 服务器内部错误
+2 -2
View File
@@ -22,7 +22,7 @@ When guest upload is disabled in admin panel (`openUpload=0`), you need to login
```bash
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
-d '{"password": "<admin-password-set-during-setup>"}'
```
**Response Example:**
@@ -329,4 +329,4 @@ When an error occurs, the API will return corresponding error message:
- 403: Forbidden
- 404: Not Found
- 422: Validation Error
- 500: Internal Server Error
- 500: Internal Server Error
+2 -2
View File
@@ -109,11 +109,11 @@ Default available themes:
| Setting | Type | Default | Description |
|---------|------|---------|-------------|
| `admin_token` | string | `FileCodeBox2023` | Admin login password |
| `admin_token` | string | Set during setup | Admin login password |
| `showAdminAddr` | int | `0` | Show admin panel entry on homepage (1=show, 0=hide) |
::: danger Security Warning
Always change the default `admin_token` in production environments! Using the default password poses serious security risks.
The setup page is shown automatically while the system is uninitialized. Complete setup before exposing a production service to the public internet.
:::
## Security Settings
+3 -2
View File
@@ -55,8 +55,9 @@ python main.py
- Download file
4. Admin Panel
- Open `http://localhost:12345` on first run and complete setup
- Visit `http://localhost:12345/#/admin`
- Enter admin password: `FileCodeBox2023`
- Enter the admin password set during setup
- Enter admin panel
- View system information, file list, user management, etc.
@@ -64,4 +65,4 @@ python main.py
- [Storage Configuration](/en/guide/storage) - Learn how to configure different storage methods
- [Security Settings](/en/guide/security) - Learn how to enhance system security
- [API Documentation](/en/api/) - Learn how to integrate through API
- [API Documentation](/en/api/) - Learn how to integrate through API
+5 -4
View File
@@ -8,12 +8,13 @@ FileCodeBox provides a fully-featured admin panel that allows administrators to
The admin panel is located at the `/admin` path. Access method:
1. Visit `http://your-domain.com/admin` in your browser
2. Enter the admin password (the value of the `admin_token` configuration)
3. Click the login button
1. On first run, set the admin password on the setup page
2. Visit `http://your-domain.com/admin` in your browser
3. Enter the admin password (the value of the `admin_token` configuration)
4. Click the login button
::: tip Tip
The default admin password is `FileCodeBox2023`. Be sure to change this password in production environments. See [Security Settings](/en/guide/security) for details.
The setup page is shown automatically while the system is uninitialized. Complete setup before exposing a production service to the public internet.
:::
### Show Admin Entry
+3 -3
View File
@@ -4,10 +4,10 @@ FileCodeBox provides multiple layers of security mechanisms to protect your file
## Admin Password
### Change Default Password
### First-Run Setup
::: danger Important Security Warning
FileCodeBox's default admin password is `FileCodeBox2023`. **You must change this password immediately in production environments!** Using the default password allows anyone to access your admin panel.
FileCodeBox does not ship with a default admin password. Open the site in your browser on first run and set the admin password on the setup page.
:::
There are two ways to change the admin password:
@@ -272,7 +272,7 @@ your-domain.com {
Before deploying FileCodeBox, confirm the following security configurations:
- [ ] Changed default admin password `admin_token`
- [ ] Completed first-run setup and set the admin password `admin_token`
- [ ] Hidden admin entry `showAdminAddr: 0`
- [ ] Configured appropriate upload rate limiting
- [ ] Configured error rate limiting to prevent brute-force attacks
+1 -1
View File
@@ -149,7 +149,7 @@ If guest upload is disabled in admin panel (`openUpload=0`), you need to login f
# 1. Login to get token
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
-d '{"password": "<admin-password-set-during-setup>"}'
# Returns: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}
+2 -2
View File
@@ -108,11 +108,11 @@ FileCodeBox 支持两种配置方式:
| 配置项 | 类型 | 默认值 | 说明 |
|--------|------|--------|------|
| `admin_token` | string | `FileCodeBox2023` | 管理员登录密码 |
| `admin_token` | string | 初始化页面设置 | 管理员登录密码(哈希存储) |
| `showAdminAddr` | int | `0` | 是否在首页显示管理入口(1=显示,0=隐藏) |
::: danger 安全警告
请务必在生产环境中修改默认的 `admin_token`!使用默认密码会导致严重的安全风险。
未初始化时会自动显示初始化页面。生产环境请在服务对外开放前完成初始化。
:::
## 安全设置
+3 -2
View File
@@ -109,8 +109,9 @@ python main.py
- 下载文件
4. 后台管理
- 首次访问 `http://localhost:12345` 完成初始化
- 访问 `http://localhost:12345/#/admin`
- 输入管理员密码:`FileCodeBox2023`
- 输入初始化时设置的管理员密码
- 进入后台管理页面
- 查看系统信息、文件列表、用户管理等
@@ -118,4 +119,4 @@ python main.py
- [存储配置](/guide/storage) - 了解如何配置不同的存储方式
- [安全设置](/guide/security) - 了解如何增强系统安全性
- [API 文档](/api/) - 了解如何通过 API 集成
- [API 文档](/api/) - 了解如何通过 API 集成
+6 -5
View File
@@ -8,12 +8,13 @@ FileCodeBox 提供了功能完善的管理面板,让管理员可以方便地
管理面板位于 `/admin` 路径。访问方式:
1. 在浏览器中访问 `http://your-domain.com/admin`
2. 输入管理员密码(`admin_token` 配置项的值)
3. 点击登录按钮
1. 首次访问站点时,按初始化页面设置管理员密码
2. 在浏览器中访问 `http://your-domain.com/admin`
3. 输入管理员密码(`admin_token` 配置项的值)
4. 点击登录按钮
::: tip 提示
默认管理员密码是 `FileCodeBox2023`。请务必在生产环境中修改此密码,详见 [安全设置](/guide/security)。
未初始化时会自动进入初始化页面。生产环境请先完成初始化,再开放公网访问。
:::
### 显示管理入口
@@ -384,7 +385,7 @@ Content-Type: application/json
-- 查看当前配置
SELECT * FROM keyvalue WHERE key = 'settings';
-- 或者删除配置,恢复默认密码
-- 或者删除配置,重启后重新进入初始化流程
DELETE FROM keyvalue WHERE key = 'settings';
```
+3 -3
View File
@@ -4,10 +4,10 @@ FileCodeBox 提供了多层安全机制来保护您的文件分享服务。本
## 管理员密码
### 修改默认密码
### 首次初始化
::: danger 重要安全警告
FileCodeBox 的默认管理员密码是 `FileCodeBox2023`。**在生产环境中必须立即修改此密码!**使用默认密码会导致任何人都可以访问您的管理面板。
FileCodeBox 首次启动时不会生成默认管理员密码。请在浏览器中打开站点,按初始化页面设置管理员密码,并妥善保存。
:::
修改管理员密码有两种方式:
@@ -271,7 +271,7 @@ your-domain.com {
部署 FileCodeBox 前,请确认以下安全配置:
- [ ] 已修改默认管理员密码 `admin_token`
- [ ] 已完成首次初始化并设置管理员密码 `admin_token`
- [ ] 已隐藏管理入口 `showAdminAddr: 0`
- [ ] 已配置合适的上传频率限制
- [ ] 已配置错误次数限制防止暴力破解
+1 -1
View File
@@ -149,7 +149,7 @@ curl -L "http://localhost:12345/share/select/?code=取件码" -o downloaded_file
# 1. 登录获取 token
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
-d '{"password": "<初始化时设置的管理员密码>"}'
# 返回: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}