mirror of
https://github.com/vastsa/FileCodeBox.git
synced 2026-11-21 22:47:13 +08:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
648d578d53 | ||
|
|
031d300cae |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "2.7.0"
|
||||
".": "2.7.1"
|
||||
}
|
||||
+2
-9
@@ -59,17 +59,13 @@ COPY --from=frontend-builder /build/fronted-2023/dist ./themes/2023
|
||||
|
||||
# 安装系统安全更新 + Python 依赖
|
||||
# 依赖从带哈希的锁定文件安装(--require-hashes),保证构建可复现、防供应链篡改。
|
||||
# gosu 用于入口脚本的数据卷属主修正后降权;清理 apt 缓存,降低镜像噪音与扫描面
|
||||
# 清理 apt 缓存,降低镜像噪音与扫描面
|
||||
RUN apt-get update \
|
||||
&& apt-get upgrade -y --no-install-recommends \
|
||||
&& apt-get install -y --no-install-recommends gosu \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& pip install --no-cache-dir --require-hashes -r requirements.lock.txt \
|
||||
&& pip cache purge || true
|
||||
|
||||
# 非 root 运行用户;数据卷属主由 docker-entrypoint.sh 按需修正(兼容存量 root 卷)
|
||||
RUN useradd --system --uid 10001 --home-dir /app app
|
||||
|
||||
# 环境变量配置
|
||||
ENV HOST="0.0.0.0" \
|
||||
PORT=12345 \
|
||||
@@ -81,11 +77,8 @@ ENV HOST="0.0.0.0" \
|
||||
|
||||
EXPOSE 12345
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
|
||||
# 生产环境启动命令
|
||||
# FORWARDED_ALLOW_IPS 默认为空:仅信任直连 IP,避免任意客户端伪造 X-Forwarded-*。
|
||||
# 若前面有反向代理,请显式设置为代理网段,例如 "10.0.0.0/8,172.16.0.0/12"。
|
||||
# 容器以 root 运行:兼容存量 root 属主的数据卷,以及 NAS/只读 bind mount。
|
||||
CMD ["sh", "-c", "access_log_arg=--no-access-log; if [ \"${APP_ENV:-development}\" != \"production\" ] || [ \"${ACCESS_LOG:-false}\" = \"true\" ]; then access_log_arg=--access-log; fi; exec uvicorn main:app --host \"$HOST\" --port \"$PORT\" --workers \"$WORKERS\" --log-level \"$LOG_LEVEL\" \"$access_log_arg\" --proxy-headers --forwarded-allow-ips \"${FORWARDED_ALLOW_IPS:-}\""]
|
||||
+9
-5
@@ -96,14 +96,18 @@ async def not_found_handler(request, exc=None):
|
||||
(负路径测试抓到的存量 bug)。浏览器(Accept 含 text/html)仍拿到
|
||||
主题首页做 SPA 兜底;API 客户端拿到 JSON 404。
|
||||
"""
|
||||
if request is not None and request.method in {"GET", "HEAD"} and "text/html" in (
|
||||
request.headers.get("accept", "")
|
||||
):
|
||||
return await index(request, exc)
|
||||
return JSONResponse(
|
||||
json_404 = JSONResponse(
|
||||
status_code=404,
|
||||
content={"code": 404, "message": "Not Found", "detail": "资源不存在"},
|
||||
)
|
||||
if request is not None and request.method in {"GET", "HEAD"} and "text/html" in (
|
||||
request.headers.get("accept", "")
|
||||
):
|
||||
try:
|
||||
return await index(request, exc)
|
||||
except HTTPException:
|
||||
return json_404
|
||||
return json_404
|
||||
|
||||
|
||||
@router.get("/")
|
||||
|
||||
+2
-2
@@ -155,8 +155,8 @@ def validate_outbound_hostname(value: Any) -> str:
|
||||
if os.environ.get("APP_ENV", "development") != "production":
|
||||
return hostname
|
||||
|
||||
if "://" in hostname or "/" in hostname:
|
||||
raise ValueError(f"s3_hostname 应为裸主机名,不含协议或路径:{hostname}")
|
||||
if "://" in hostname or "/" in hostname or "@" in hostname:
|
||||
raise ValueError(f"s3_hostname 应为裸主机名,不含协议、路径或 userinfo:{hostname}")
|
||||
# 取主机部分:[v6] 形态取括号内;host:port 取冒号前;裸 IPv6(多个冒号)整体
|
||||
if "[" in hostname:
|
||||
host = hostname.split("[", 1)[1].split("]", 1)[0]
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
version: "3"
|
||||
services:
|
||||
file-code-box:
|
||||
image: lanol/filecodebox:2.7.0 # x-release-please-version
|
||||
image: lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
volumes:
|
||||
- fcb-data:/app/data:rw
|
||||
# NAS 已有文件:把共享目录挂到 /app/data/local,即可在后台「本地分享」里生成提取码,无需再上传
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
# FileCodeBox 容器入口:兼容式非 root 降权。
|
||||
#
|
||||
# 默认以 root 进入(兼容存量 root 属主的数据卷),按需修正 data 目录属主后
|
||||
# 用 gosu 降权到 app 用户运行;若部署方显式指定了 user(非 root),则直接运行
|
||||
# 不做任何 chown,保证两种形态都可预期。
|
||||
set -e
|
||||
|
||||
DATA_DIR="${DATA_DIR:-/app/data}"
|
||||
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
mkdir -p "$DATA_DIR"
|
||||
# 仅当存在非 app 属主的文件时才 chown,避免大卷启动变慢
|
||||
if [ -n "$(find "$DATA_DIR" ! -uid "$(id -u app)" -print -quit 2>/dev/null)" ]; then
|
||||
chown -R app:app "$DATA_DIR"
|
||||
fi
|
||||
exec gosu app "$@"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [2.7.1](https://github.com/vastsa/FileCodeBox/compare/v2.7.0...v2.7.1) (2026-09-19)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* keep Docker as root, close s3_hostname SSRF, unbreak 404 tests ([031d300](https://github.com/vastsa/FileCodeBox/commit/031d300caea99117e82b3bddc3e5d0532cf3efa6))
|
||||
|
||||
## [2.7.0](https://github.com/vastsa/FileCodeBox/compare/v2.6.1...v2.7.0) (2026-09-16)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## [Unreleased]
|
||||
|
||||
<!-- Current release: 2.7.0 x-release-please-version -->
|
||||
<!-- Current release: 2.7.1 x-release-please-version -->
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.7.0 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
Open `http://localhost:12345` and complete the first-run setup.
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.7.0 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
打开 `http://localhost:12345`,按引导完成首次初始化。
|
||||
|
||||
@@ -32,7 +32,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.7.0 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
访问 `http://localhost:12345`,完成首次初始化。生产环境建议固定版本号;`latest` 指向最新正式版。
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.7.0 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
Open `http://localhost:12345` and complete first-run setup. Pin a version in production; `latest` tracks the newest stable release.
|
||||
|
||||
@@ -138,9 +138,23 @@ class TestNotFoundHandlerBranches:
|
||||
assert "text/html" not in response.headers["content-type"]
|
||||
|
||||
async def test_browser_accept_gets_theme_page(self, initialized_client):
|
||||
response = await initialized_client.get("/no-such-path", headers={"Accept": "text/html"})
|
||||
assert response.status_code == 200
|
||||
assert "text/html" in response.headers["content-type"]
|
||||
from core.settings import BASE_DIR
|
||||
|
||||
theme_dir = BASE_DIR / "themes" / "2024"
|
||||
theme_dir.mkdir(parents=True, exist_ok=True)
|
||||
index = theme_dir / "index.html"
|
||||
created = not index.exists()
|
||||
if created:
|
||||
index.write_text("<!doctype html><title>{{title}}</title>", encoding="utf-8")
|
||||
try:
|
||||
response = await initialized_client.get(
|
||||
"/no-such-path", headers={"Accept": "text/html"}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert "text/html" in response.headers["content-type"]
|
||||
finally:
|
||||
if created:
|
||||
index.unlink(missing_ok=True)
|
||||
|
||||
async def test_default_star_accept_gets_json_404(self, initialized_client):
|
||||
"""curl 默认 */* 不含 text/html——必须走 JSON 分支(防误伤脚本调用方)。"""
|
||||
|
||||
@@ -90,6 +90,12 @@ def test_hostname_tier_rejects_url_forms(production_env):
|
||||
validate_outbound_hostname("http://127.0.0.1:9000")
|
||||
|
||||
|
||||
def test_hostname_tier_rejects_userinfo(production_env):
|
||||
"""存储层拼 https://{s3_hostname},@ 会被当成 userinfo,实际连 @ 后的地址。"""
|
||||
for hostname in ("evil.com@127.0.0.1", "attacker.example@127.0.0.1:8443"):
|
||||
with pytest.raises(ValueError):
|
||||
validate_outbound_hostname(hostname)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestChangedOnlyEnforcement:
|
||||
"""changed-only 集成回归:存量内网 endpoint 不得挡死无关设置保存。
|
||||
|
||||
Reference in new issue
Block a user