mirror of
https://github.com/vastsa/FileCodeBox.git
synced 2026-11-25 00:27:43 +08:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40f22de7f8 | ||
|
|
da374b4595 | ||
|
|
d3f9e7902c | ||
|
|
2f5eab18b1 | ||
|
|
6bb1ef06c1 | ||
|
|
63e72c1455 | ||
|
|
648d578d53 | ||
|
|
031d300cae |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "2.7.0"
|
||||
".": "2.8.2"
|
||||
}
|
||||
+3
-10
@@ -54,22 +54,18 @@ RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo 'Asia/Shanghai' > /etc/timezone
|
||||
|
||||
# 从构建阶段复制编译好的前端主题
|
||||
COPY --from=frontend-builder /build/fronted-2024/dist ./themes/2024
|
||||
COPY --from=frontend-builder /build/FileCodeBox/themes/2024 ./themes/2024
|
||||
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:-}\""]
|
||||
@@ -40,6 +40,7 @@ class ConfigService:
|
||||
"max_save_seconds",
|
||||
"onedrive_proxy",
|
||||
"open_upload",
|
||||
"mcp_require_token",
|
||||
"port",
|
||||
"s3_proxy",
|
||||
"server_port",
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
"""Stateless MCP Streamable HTTP endpoint for quick share uploads."""
|
||||
import base64
|
||||
import binascii
|
||||
import html
|
||||
import io
|
||||
import json
|
||||
from typing import Any
|
||||
from html.parser import HTMLParser
|
||||
from urllib.parse import quote, urlsplit
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request, UploadFile
|
||||
from starlette.datastructures import Headers
|
||||
from starlette.responses import JSONResponse, Response
|
||||
|
||||
from apps.base.auth import _require_admin_payload
|
||||
from apps.base.file_validation import validate_file_type, validate_upload_file
|
||||
from apps.base.services import FileUploadService, validate_file_size
|
||||
from apps.base.utils import ip_limit, validate_expire_style
|
||||
from core.settings import settings
|
||||
from core.utils import sanitize_filename
|
||||
|
||||
router = APIRouter(tags=["MCP"])
|
||||
|
||||
MCP_PROTOCOL_VERSION = "2025-03-26"
|
||||
TEXT_SHARE_MAX_BYTES = 222 * 1024
|
||||
MAX_MCP_BODY_BYTES = 64 * 1024 * 1024
|
||||
|
||||
|
||||
def _jsonrpc_error(request_id, code: int, message: str) -> dict:
|
||||
return {"jsonrpc": "2.0", "id": request_id, "error": {"code": code, "message": message}}
|
||||
|
||||
|
||||
def _jsonrpc_result(request_id, result: dict) -> dict:
|
||||
return {"jsonrpc": "2.0", "id": request_id, "result": result}
|
||||
|
||||
|
||||
def _validate_origin(request: Request) -> None:
|
||||
"""Reject browser cross-site POSTs before parsing any upload tool."""
|
||||
origin = request.headers.get("origin")
|
||||
fetch_site = request.headers.get("sec-fetch-site", "").lower()
|
||||
if fetch_site == "cross-site":
|
||||
raise HTTPException(status_code=403, detail="跨站请求已拒绝")
|
||||
if not origin:
|
||||
return # Native MCP clients do not send Origin and use no ambient cookies.
|
||||
try:
|
||||
parsed = urlsplit(origin)
|
||||
host = request.headers.get("host", "").lower()
|
||||
if (
|
||||
parsed.scheme not in {"http", "https"}
|
||||
or not parsed.netloc
|
||||
or parsed.netloc.lower() != host
|
||||
or parsed.username is not None
|
||||
or parsed.password is not None
|
||||
or parsed.path not in {"", "/"}
|
||||
or parsed.query
|
||||
or parsed.fragment
|
||||
):
|
||||
raise ValueError("origin mismatch")
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=403, detail="跨站请求已拒绝")
|
||||
|
||||
|
||||
async def _read_limited_body(request: Request) -> bytes:
|
||||
max_size = min(
|
||||
MAX_MCP_BODY_BYTES,
|
||||
max(1024 * 1024, int(settings.upload_size * 4 / 3) + 256 * 1024),
|
||||
)
|
||||
declared_size = request.headers.get("content-length")
|
||||
if declared_size:
|
||||
try:
|
||||
if int(declared_size) > max_size:
|
||||
raise HTTPException(status_code=413, detail="MCP 请求体过大")
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="Content-Length 无效")
|
||||
body = bytearray()
|
||||
async for chunk in request.stream():
|
||||
body.extend(chunk)
|
||||
if len(body) > max_size:
|
||||
raise HTTPException(status_code=413, detail="MCP 请求体过大")
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def _tool_definitions() -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"name": "share_text",
|
||||
"description": "将文本快速上传到 FileCodeBox 并创建分享链接。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {"type": "string", "description": "要分享的文本"},
|
||||
"expire_value": {"type": "integer", "minimum": 1, "default": 1},
|
||||
"expire_style": {"type": "string", "enum": ["day", "hour", "minute", "forever", "count"], "default": "day"},
|
||||
},
|
||||
"required": ["text"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "share_file",
|
||||
"description": "将 Base64 编码的文件上传到 FileCodeBox 并创建分享链接。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"filename": {"type": "string", "description": "文件名"},
|
||||
"content_base64": {"type": "string", "description": "文件内容的标准 Base64 编码"},
|
||||
"content_type": {"type": "string", "default": "application/octet-stream"},
|
||||
"expire_value": {"type": "integer", "minimum": 1, "default": 1},
|
||||
"expire_style": {"type": "string", "enum": ["day", "hour", "minute", "forever", "count"], "default": "day"},
|
||||
},
|
||||
"required": ["filename", "content_base64"],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _share_result(request: Request, code: str, name: str) -> dict:
|
||||
base_url = str(request.base_url).rstrip("/")
|
||||
share_url = f"{base_url}/#/?code={quote(code, safe='')}"
|
||||
markdown_name = html.escape(name).replace("[", "\\[").replace("]", "\\]")
|
||||
return {
|
||||
"code": code,
|
||||
"name": name,
|
||||
"url": share_url,
|
||||
"markdown": f"[{markdown_name}]({share_url})",
|
||||
}
|
||||
|
||||
|
||||
async def _call_tool(request: Request, tool_name: str, arguments: dict) -> dict:
|
||||
authorization = request.headers.get("authorization", "")
|
||||
if settings.mcp_require_token or not settings.open_upload:
|
||||
_require_admin_payload(authorization)
|
||||
ip = ip_limit["upload"](request)
|
||||
|
||||
if tool_name == "share_text":
|
||||
text = arguments.get("text")
|
||||
if not isinstance(text, str):
|
||||
raise ValueError("text 必须是字符串")
|
||||
if len(text.encode("utf-8")) > TEXT_SHARE_MAX_BYTES:
|
||||
raise ValueError("内容过多,请改用文件分享")
|
||||
expire_value = int(arguments.get("expire_value", 1))
|
||||
expire_style = str(arguments.get("expire_style", "day"))
|
||||
if expire_value < 1:
|
||||
raise ValueError("expire_value 必须大于 0")
|
||||
validate_expire_style(expire_style)
|
||||
code = await FileUploadService.create_text_share(text, expire_value, expire_style)
|
||||
ip_limit["upload"].add_ip(ip)
|
||||
return _share_result(request, code, "Text")
|
||||
|
||||
if tool_name == "share_file":
|
||||
filename = arguments.get("filename")
|
||||
encoded_content = arguments.get("content_base64")
|
||||
content_type = str(arguments.get("content_type", "application/octet-stream"))
|
||||
if not isinstance(filename, str) or not filename.strip():
|
||||
raise ValueError("filename 不能为空")
|
||||
if not isinstance(encoded_content, str):
|
||||
raise ValueError("content_base64 必须是字符串")
|
||||
try:
|
||||
content = base64.b64decode(encoded_content, validate=True)
|
||||
except (ValueError, binascii.Error):
|
||||
raise ValueError("content_base64 不是有效的标准 Base64")
|
||||
safe_name = await sanitize_filename(filename.rsplit("/", 1)[-1].rsplit("\\", 1)[-1])
|
||||
validate_file_type(safe_name, content_type)
|
||||
upload = UploadFile(filename=safe_name, file=io.BytesIO(content), size=len(content), headers=Headers({"content-type": content_type}))
|
||||
size = await validate_file_size(upload, settings.upload_size)
|
||||
await validate_upload_file(upload)
|
||||
expire_value = int(arguments.get("expire_value", 1))
|
||||
expire_style = str(arguments.get("expire_style", "day"))
|
||||
if expire_value < 1:
|
||||
raise ValueError("expire_value 必须大于 0")
|
||||
validate_expire_style(expire_style)
|
||||
share = await FileUploadService.create_file_share(upload, size=size, expire_value=expire_value, expire_style=expire_style)
|
||||
ip_limit["upload"].add_ip(ip)
|
||||
return _share_result(request, share["code"], share["name"])
|
||||
|
||||
raise LookupError(f"未知工具:{tool_name}")
|
||||
|
||||
|
||||
@router.post("/mcp", include_in_schema=False)
|
||||
async def mcp_endpoint(request: Request):
|
||||
_validate_origin(request)
|
||||
media_type = request.headers.get("content-type", "").split(";", 1)[0].strip().lower()
|
||||
if media_type != "application/json":
|
||||
raise HTTPException(status_code=415, detail="MCP 请求必须使用 application/json")
|
||||
try:
|
||||
message = json.loads(await _read_limited_body(request))
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
return JSONResponse(_jsonrpc_error(None, -32700, "Parse error"), status_code=400)
|
||||
if not isinstance(message, dict) or message.get("jsonrpc") != "2.0" or not isinstance(message.get("method"), str):
|
||||
return JSONResponse(_jsonrpc_error(message.get("id") if isinstance(message, dict) else None, -32600, "Invalid Request"), status_code=400)
|
||||
|
||||
request_id = message.get("id")
|
||||
method = message["method"]
|
||||
if request_id is None and method.startswith("notifications/"):
|
||||
return Response(status_code=202)
|
||||
result: dict[str, Any] = {}
|
||||
try:
|
||||
if method == "initialize":
|
||||
result = {
|
||||
"protocolVersion": MCP_PROTOCOL_VERSION,
|
||||
"capabilities": {"tools": {"listChanged": False}},
|
||||
"serverInfo": {"name": "filecodebox", "version": "1.0.0"},
|
||||
}
|
||||
elif method == "ping":
|
||||
result = {}
|
||||
elif method == "tools/list":
|
||||
result = {"tools": _tool_definitions()}
|
||||
elif method == "tools/call":
|
||||
params = message.get("params")
|
||||
if not isinstance(params, dict) or not isinstance(params.get("name"), str):
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, "Invalid params"))
|
||||
arguments = params.get("arguments", {})
|
||||
if not isinstance(arguments, dict):
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, "Invalid params"))
|
||||
try:
|
||||
tool_value = await _call_tool(request, params["name"], arguments)
|
||||
result = {"content": [{"type": "text", "text": json.dumps(tool_value, ensure_ascii=False)}], "structuredContent": tool_value}
|
||||
except LookupError as exc:
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, str(exc)))
|
||||
except HTTPException as exc:
|
||||
if exc.status_code in {401, 403}:
|
||||
raise
|
||||
result = {"content": [{"type": "text", "text": str(exc.detail)}], "isError": True}
|
||||
except (TypeError, ValueError) as exc:
|
||||
result = {"content": [{"type": "text", "text": str(exc)}], "isError": True}
|
||||
else:
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32601, "Method not found"))
|
||||
return JSONResponse(_jsonrpc_result(request_id, result), headers={"MCP-Protocol-Version": MCP_PROTOCOL_VERSION})
|
||||
except HTTPException as exc:
|
||||
return JSONResponse(
|
||||
_jsonrpc_error(request_id, -32001 if exc.status_code == 401 else -32003, str(exc.detail)),
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
|
||||
|
||||
_SAFE_TAGS = {
|
||||
"a", "abbr", "article", "b", "blockquote", "br", "caption", "code", "dd", "del", "details",
|
||||
"div", "dl", "dt", "em", "figcaption", "figure", "h1", "h2", "h3", "h4", "h5", "h6",
|
||||
"hr", "i", "img", "li", "main", "mark", "ol", "p", "pre", "s", "section", "small", "span",
|
||||
"strong", "sub", "summary", "sup", "table", "tbody", "td", "th", "thead", "tr", "u", "ul",
|
||||
}
|
||||
_VOID_TAGS = {"br", "hr", "img"}
|
||||
_DROP_CONTENT_TAGS = {"script", "style", "iframe", "object", "embed", "svg", "math", "form", "template"}
|
||||
_SAFE_ATTRS = {"alt", "title", "class", "id", "colspan", "rowspan", "width", "height", "scope", "dir", "lang"}
|
||||
|
||||
|
||||
class _HTMLPreviewSanitizer(HTMLParser):
|
||||
"""Whitelist-only HTML serializer; scripts, active embeds and URL attrs are removed."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(convert_charrefs=True)
|
||||
self.output: list[str] = []
|
||||
self.drop_depth = 0
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
tag = tag.lower()
|
||||
if self.drop_depth:
|
||||
if tag in _DROP_CONTENT_TAGS:
|
||||
self.drop_depth += 1
|
||||
return
|
||||
if tag in _DROP_CONTENT_TAGS:
|
||||
self.drop_depth = 1
|
||||
return
|
||||
if tag not in _SAFE_TAGS:
|
||||
return
|
||||
safe_attrs = []
|
||||
for name, value in attrs:
|
||||
name = name.lower()
|
||||
if value is None or name.startswith("on") or name not in _SAFE_ATTRS:
|
||||
continue
|
||||
safe_attrs.append(f' {name}="{html.escape(value, quote=True)}"')
|
||||
self.output.append(f"<{tag}{''.join(safe_attrs)}>")
|
||||
|
||||
def handle_startendtag(self, tag, attrs):
|
||||
self.handle_starttag(tag, attrs)
|
||||
if tag.lower() in _SAFE_TAGS and tag.lower() not in _VOID_TAGS:
|
||||
self.handle_endtag(tag)
|
||||
|
||||
def handle_endtag(self, tag):
|
||||
tag = tag.lower()
|
||||
if self.drop_depth:
|
||||
if tag in _DROP_CONTENT_TAGS:
|
||||
self.drop_depth -= 1
|
||||
return
|
||||
if tag in _SAFE_TAGS and tag not in _VOID_TAGS:
|
||||
self.output.append(f"</{tag}>")
|
||||
|
||||
def handle_data(self, data):
|
||||
if not self.drop_depth:
|
||||
self.output.append(html.escape(data))
|
||||
|
||||
def handle_entityref(self, name):
|
||||
if not self.drop_depth:
|
||||
self.output.append(f"&{html.escape(name)};")
|
||||
|
||||
def handle_charref(self, name):
|
||||
if not self.drop_depth:
|
||||
self.output.append(f"&#{html.escape(name)};")
|
||||
|
||||
|
||||
def sanitize_html_preview(source: str) -> str:
|
||||
parser = _HTMLPreviewSanitizer()
|
||||
parser.feed(source)
|
||||
parser.close()
|
||||
return "<!doctype html><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><body>" + "".join(parser.output) + "</body>"
|
||||
+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("/")
|
||||
|
||||
+48
-1
@@ -1,4 +1,5 @@
|
||||
import hashlib
|
||||
import asyncio
|
||||
import hmac
|
||||
import os
|
||||
import uuid
|
||||
@@ -10,7 +11,7 @@ from typing import Optional, Tuple, Union
|
||||
from fastapi import APIRouter, Form, Request, UploadFile, File, Depends, HTTPException
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from starlette import status
|
||||
from starlette.responses import Response
|
||||
from starlette.responses import HTMLResponse, Response
|
||||
from tortoise.expressions import Case, F, Q, When
|
||||
|
||||
from apps.base.auth import share_required_login
|
||||
@@ -39,6 +40,7 @@ from apps.base.utils import (
|
||||
validate_expire_style,
|
||||
)
|
||||
from apps.base.local_share import is_local_ref
|
||||
from apps.base.mcp import sanitize_html_preview
|
||||
from core.response import APIResponse
|
||||
from core.settings import settings
|
||||
from core.storage import storages, FileStorageInterface
|
||||
@@ -194,6 +196,51 @@ async def post_file_metadata(
|
||||
return APIResponse(detail=build_file_metadata(file_code))
|
||||
|
||||
|
||||
@share_api.get("/preview/html/{code}", include_in_schema=False)
|
||||
async def preview_html(code: str):
|
||||
has, file_code = await get_code_file_by_code(code)
|
||||
if not has or not isinstance(file_code, FileCodes):
|
||||
raise HTTPException(status_code=404, detail="文件不存在")
|
||||
if file_code.text is not None or (file_code.suffix or "").lower() not in {".html", ".htm"}:
|
||||
raise HTTPException(status_code=415, detail="仅支持 HTML 文件预览")
|
||||
preview_limit = 2 * 1024 * 1024
|
||||
if file_code.size > preview_limit:
|
||||
raise HTTPException(status_code=413, detail="HTML 文件过大,无法在线预览")
|
||||
download = await get_stored_download(file_code)
|
||||
if download.path is not None:
|
||||
if download.path.stat().st_size > preview_limit:
|
||||
raise HTTPException(status_code=413, detail="HTML 文件过大,无法在线预览")
|
||||
content = await asyncio.to_thread(download.path.read_bytes)
|
||||
elif download.content is not None:
|
||||
content = download.content
|
||||
elif download.stream_factory is not None:
|
||||
stream = download.stream_factory()
|
||||
if hasattr(stream, "__aiter__"):
|
||||
chunks = bytearray()
|
||||
async for chunk in stream:
|
||||
chunks.extend(chunk)
|
||||
if len(chunks) > preview_limit:
|
||||
raise HTTPException(status_code=413, detail="HTML 文件过大,无法在线预览")
|
||||
content = bytes(chunks)
|
||||
else:
|
||||
raise HTTPException(status_code=500, detail="HTML 预览读取失败")
|
||||
else:
|
||||
raise HTTPException(status_code=500, detail="HTML 预览读取失败")
|
||||
if len(content) > preview_limit:
|
||||
raise HTTPException(status_code=413, detail="HTML 文件过大,无法在线预览")
|
||||
safe_html = sanitize_html_preview(content.decode("utf-8-sig", errors="replace"))
|
||||
return HTMLResponse(
|
||||
safe_html,
|
||||
headers={
|
||||
"Content-Security-Policy": "sandbox; default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; base-uri 'none'; form-action 'none'",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"Cache-Control": "private, no-store",
|
||||
"Content-Disposition": 'inline; filename="preview.html"',
|
||||
},
|
||||
background=download.background,
|
||||
)
|
||||
|
||||
|
||||
@share_api.get("/select/")
|
||||
async def get_code_file(code: str, ip: str = Depends(ip_limit["error"])):
|
||||
file_storage: FileStorageInterface = storages[settings.file_storage]()
|
||||
|
||||
+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]
|
||||
|
||||
@@ -48,6 +48,7 @@ DEFAULT_CONFIG: dict[str, Any] = {
|
||||
"jwt_secret": "",
|
||||
"admin_session_expire": ADMIN_SESSION_EXPIRE_DEFAULT,
|
||||
"open_upload": 1,
|
||||
"mcp_require_token": 0,
|
||||
"upload_size": 1024 * 1024 * 10,
|
||||
"allowed_file_types": ["*"],
|
||||
"expire_style": ["day", "hour", "minute", "forever", "count"],
|
||||
|
||||
+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.8.2 # 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,33 @@
|
||||
# Changelog
|
||||
|
||||
## [2.8.2](https://github.com/vastsa/FileCodeBox/compare/v2.8.1...v2.8.2) (2026-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* type MCP protocol results ([da374b4](https://github.com/vastsa/FileCodeBox/commit/da374b459537ee079e1d03da121a935c8fb18f0e))
|
||||
|
||||
## [2.8.1](https://github.com/vastsa/FileCodeBox/compare/v2.8.0...v2.8.1) (2026-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* restore lint and Docker theme build ([2f5eab1](https://github.com/vastsa/FileCodeBox/commit/2f5eab18b1ab28fcb4f416248076ce574998d718))
|
||||
|
||||
## [2.8.0](https://github.com/vastsa/FileCodeBox/compare/v2.7.1...v2.8.0) (2026-10-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add MCP quick share and safe HTML preview ([63e72c1](https://github.com/vastsa/FileCodeBox/commit/63e72c145576d169265e4fa8cf373e33531a06a0))
|
||||
|
||||
## [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.8.2 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.8.2 # 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.8.2 # x-release-please-version
|
||||
```
|
||||
|
||||
打开 `http://localhost:12345`,按引导完成首次初始化。
|
||||
|
||||
@@ -28,6 +28,7 @@ from apps.base.tasks import (
|
||||
delete_expire_files,
|
||||
)
|
||||
from apps.base.views import share_api, chunk_api, presign_api
|
||||
from apps.base.mcp import router as mcp_router
|
||||
from core.database import db_startup_lock, get_db_config, init_db
|
||||
from core.errors import StorageError
|
||||
from core.logger import get_log_level_name, is_access_log_enabled, logger
|
||||
@@ -139,6 +140,7 @@ app.include_router(presign_api)
|
||||
app.include_router(presign_api, prefix="/api")
|
||||
app.include_router(admin_api)
|
||||
app.include_router(pages_router)
|
||||
app.include_router(mcp_router)
|
||||
|
||||
# 404 时返回主题首页(index 兼任 exception handler 与 GET / 路由)
|
||||
app.add_exception_handler(404, not_found_handler)
|
||||
|
||||
@@ -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.8.2 # 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.8.2 # x-release-please-version
|
||||
```
|
||||
|
||||
Open `http://localhost:12345` and complete first-run setup. Pin a version in production; `latest` tracks the newest stable release.
|
||||
|
||||
+121
-138
@@ -652,144 +652,127 @@ pydantic==2.13.5 \
|
||||
# via
|
||||
# -r requirements.txt
|
||||
# fastapi
|
||||
pydantic-core==2.49.0 \
|
||||
--hash=sha256:0014dd75b23f336314956bed232bda1b0138be774bb66746f9c01f7a651d6532 \
|
||||
--hash=sha256:04106a4dfb7c40a0a61834c25f43f121fdb494978657015c9e3847124bd5813a \
|
||||
--hash=sha256:062c2a4b2de23bfa10418fafe63d8873c9f95780dcd5bf6ae66537b44e40f3ed \
|
||||
--hash=sha256:0b93de748aa4a13ec72384ecca7e9fa52e2983b154b5f878621097bb25ac71ec \
|
||||
--hash=sha256:0bb4a60b0abdb41c237e28fd8c86e223d2994143ed863d0168c0b03b759d2620 \
|
||||
--hash=sha256:0c3f75d3b7a818d57ae45693358508d1d0e809ac2dae05bf5bbd3c687bc75110 \
|
||||
--hash=sha256:0e9956faf9840dbdce5a88c2a68fd28c3cdb16eac41ac5f85831291762021805 \
|
||||
--hash=sha256:106a0a7b51b293662ff5380255bf8f4e215d7d6afa8e6588f3b9511621bf6b4f \
|
||||
--hash=sha256:119505798feabc587642e03579a9acff7da6ef6816a70ef2de50960037b4b0c8 \
|
||||
--hash=sha256:13b5a234f4f0332f509396c8127c92b90674e4f2636d9d67a7be1a8537e2439c \
|
||||
--hash=sha256:19310addacce11fd11f181eda18f2f190cdce0150b0808399756e1a530430c17 \
|
||||
--hash=sha256:1acfae18c0fc6855e4586d2b7cc10393e921f883c56c1ea4eb75115a7b344552 \
|
||||
--hash=sha256:1af1d427be9a0bc55fd20015a1f61ffb3bcb7ddec83cae03f27b1a833893688c \
|
||||
--hash=sha256:2005d526103ea0057f5e51d0b9c469234e890d8d8a76c4ec474696e4cab2449a \
|
||||
--hash=sha256:24ce45e6967bb2ac68f1f1c199dec05399d32bc826342f455035afcbda5ab3f5 \
|
||||
--hash=sha256:2aa0c16c7cd70865e3e13ccb5b48a73a847c98ccf2804692d812bb85a9fd3832 \
|
||||
--hash=sha256:2b0e0c56cb113441a93ce198cf8b515edb5f670905cbe66f35c26d78bd9bb30a \
|
||||
--hash=sha256:2b2af00c6d1736f5a18e812252fd48a756814424b519d0ed876feb253ea2cdc4 \
|
||||
--hash=sha256:2b72dc8f8dba268bcb040c2cb715e96de9a69299d1d0b60ca4e12517f10b8834 \
|
||||
--hash=sha256:2f9df5909999efe8f84aa28ef3249b12c9801911a8a7be8f386792220c831af4 \
|
||||
--hash=sha256:321c2a9f7c99afb97773fdf003df9a54569b17c2d067bb04109571c307a9c599 \
|
||||
--hash=sha256:327648d97e9d64e1a4a9be16e882715fa6fb2fe83c405f577018beedb0e699d5 \
|
||||
--hash=sha256:35473d3949d065d78c0c039de13ea60bbf6b9fc9d274f62d14500544bbf7374f \
|
||||
--hash=sha256:376340e6682b4d9ea85c72636014c9487826f55fc93228aa308920e6db440a4e \
|
||||
--hash=sha256:38f28fe80d8b0d193c83b4f93f1e2a70ce8bbc1e107ccff43853d6eecfe1c683 \
|
||||
--hash=sha256:3928d009bdedbfe7eff17f1ec75871612b91786106c529137ea58d70770d02cf \
|
||||
--hash=sha256:39adbfec1383df3ac7d8ae0df72e91b0fbf503f9786754ff8d0cb6cae0ae523c \
|
||||
--hash=sha256:39b16867c2d305bb6997ecbaa09a6edec79be1f7dfa51e12778abd8d32275911 \
|
||||
--hash=sha256:3a147c3f4ff17f6ebd1120dab11b9bb7db318303dfd8d1a853fe167694f6bc9e \
|
||||
--hash=sha256:3a3e9b4167b5d7a355863846494b046af5071cbfc4f30c8554634b2796eb163f \
|
||||
--hash=sha256:3aa610f5abbe154fb35eca0b060351b9f8b6e5e7de63a0ab8a3f14f9304c01f3 \
|
||||
--hash=sha256:3c0cf7c39364028404ef953adaa126aaa037a20bdbb4c073c7f3b88814c30a34 \
|
||||
--hash=sha256:3c6cba4051e8b473151e2f745e70d2f5e9e24389c38be835d5dca90a5ff31389 \
|
||||
--hash=sha256:3cdd59f86a24c7ae250ecb02d94f2ce764ba32b139c24029c23637fcb7670f36 \
|
||||
--hash=sha256:3faf66e8ff6c3c86cc5bfab0b61541a389b30540b5e06aa62c0562d3403be098 \
|
||||
--hash=sha256:40ca7e5bddc63dea88aa3f9778d75dffe725d79d167398dde33f41f10034a0eb \
|
||||
--hash=sha256:45137bb8182ae8b8631550d54d82d654db7e8bcbff2a8ebce5e56c85e25fc7ab \
|
||||
--hash=sha256:458986e1d8ba85ba4b5c369c881a1f49ae9cc5b0c00231e13736b0c6557c1a3d \
|
||||
--hash=sha256:46836736bca8a7ebab55d0ea76cd04e89bae0ea3d6dcfdedcd1bb1b1244a4239 \
|
||||
--hash=sha256:477cdaf34c8ff40a17183397ea16be355c89b58a6939128ede251d75581ccde2 \
|
||||
--hash=sha256:4a801a8410e16e22a231aef577127fcf02c85ee237a1b73cb0790173be700b3e \
|
||||
--hash=sha256:4d8a90e645670ac9e2e59a9188b3c30b4aff56229535050c5b355cbbe7711e49 \
|
||||
--hash=sha256:4db357431b1949628cd7dd326b92a5fcea1d693fa96848b3d2272d83b9f136e6 \
|
||||
--hash=sha256:4fe53ec1ed34aa8e3db349305c38202711ef3009ae5ee9956e69032aeab246d5 \
|
||||
--hash=sha256:51a7e44c0fc802de672cd34bc3fa283bdf6a5c0e975413d124181573e3b9a28b \
|
||||
--hash=sha256:52984e1335adb925c6089a44d167668a1f8cc6bbbca25657936e51922c0d07bc \
|
||||
--hash=sha256:531d351eaaece0a6bcc535d80bdbaf9d0db78ad4752ff737216c70dfea7887e5 \
|
||||
--hash=sha256:53794f62d97aa49b6b86b4114e06ae0ea0f4cdc72c29dfa76180e6ffa95a50f0 \
|
||||
--hash=sha256:5597c5695fbc75cf5d624b7600eebfb0e1f2280e4e7a1aa3ecc2636ce5156d64 \
|
||||
--hash=sha256:58cd25e42316673b5614d6bb0ccee0ec15d9dc60182ab967807dc0e222578ce2 \
|
||||
--hash=sha256:592827666d336312d5fd3976b42be19501c51db69c420660e283b5d31aeb9733 \
|
||||
--hash=sha256:59c1594065e4a95a055c74e659e81d098ab028e439fdcd1ed5d4d3d97a3472b9 \
|
||||
--hash=sha256:5a807d09a516f93614bbc8e83401afdbe7325373d36ec54727f3f5147a57dd52 \
|
||||
--hash=sha256:5a8c26d1a86d4f078d363e6b97608db340deb6336dd2bbbf45b8f0f88c1db4d1 \
|
||||
--hash=sha256:5ab1f5555c083b9bc6aae809beb00aef77e81a10dbbd16a6da9ad239620468cd \
|
||||
--hash=sha256:5bf86181aab670eb9c3b1a3e84342bc934134b50b9c08f39aa56e66fd3c4f6d2 \
|
||||
--hash=sha256:60550432855bc323ce9aa813e14e0bf2b806de59727aab850a1c83c0fd7dc0c1 \
|
||||
--hash=sha256:60c30f0977f6bf6d74c81f5c797f862724cf59ad5d7ff37f3eab9595994f6261 \
|
||||
--hash=sha256:6165e75e29c361b8d4077a19c3a9a98f93d019522f952c13a6c8ff680a40fa0b \
|
||||
--hash=sha256:62535ce2294441c986da1aeb743f7255ac99f3e0a3119bd8c44b36406d9f3721 \
|
||||
--hash=sha256:64804fc948c723dbf763a40d0747e7a73807667148831a836e5b856259247837 \
|
||||
--hash=sha256:67440399d87a2c160ddff9dc013d12812785cfde18b648a295d57043f034a9fb \
|
||||
--hash=sha256:68639bdfc4475b1497debc0f70f01c04b2544730a819ebbde6113172e0a1a13e \
|
||||
--hash=sha256:68c53d957497e4001e4104c5fb64e90239461b128de0d5151bb8bc8053d70b4a \
|
||||
--hash=sha256:69bdb8c9ad333b29118f1e85f79c476d739c1ccd14d9d0042d6b4b710dfd2698 \
|
||||
--hash=sha256:6aef64b4b948db5c243d184a92326a4666b0467d9f6503f68d048b23ba18a928 \
|
||||
--hash=sha256:6d1433f3d022d1f946bda84bf50b83d9f0f77599e6bfe96c53b384a760b116fd \
|
||||
--hash=sha256:6dac978538b8c4f61680da02fe11da8d04c3629eb16ddb49da797636256c9403 \
|
||||
--hash=sha256:70507b191705d0ef220f85c915395109b439b8c9802a5e97645ac0e44288dc81 \
|
||||
--hash=sha256:7123c611f3933dc66a8e587c6c255acdaac20aeb1b2505ac01fe59c1f9b7b83e \
|
||||
--hash=sha256:73407e73aca3383df974bb69a02ae426371f477cee0bc868361014fc5a86dd0b \
|
||||
--hash=sha256:7392a37a455f71e64a7cf70da1df89ece89f46c9163c4f7b8988e4de4012fb7f \
|
||||
--hash=sha256:7a4b87881bcdde33caa8d1900cef4166ea34575f1926c390b8f486ce911cba82 \
|
||||
--hash=sha256:7cab96cc03d0bdb31b4d1130f65004f496558b267073df3fe65d4981276819a3 \
|
||||
--hash=sha256:7d75adfd02d96906d33ba637e1d873078d46a531ac4efe2e373220c4505c8caf \
|
||||
--hash=sha256:7e912019d9262611ea419a0e440e552b5d41f3671d2d88b96a99ef67b6d3ad71 \
|
||||
--hash=sha256:7f2ff0f42e14b2694d99743dd8c808faa9fad989236e3b6bb6f0e19ab036d9b0 \
|
||||
--hash=sha256:7fd7218d785928c2c57b5f4c3682745f106b4192b7647372c1e6d1109d309c81 \
|
||||
--hash=sha256:801d35337e6f732db4598e5a7cccb235be6bbac6ec03734e6bd731412e2fbbc1 \
|
||||
--hash=sha256:80c23a141ff99bfe21749f668784ecacf0e0347740bb541bbbe03523450edcd7 \
|
||||
--hash=sha256:813081b90803d858f6917f46b16fc4b47de679a2e76058570a4a46344305b650 \
|
||||
--hash=sha256:813c1243fd93ee720edbfe771d9bf0cc5bc6d9bddc0acafb4c0085796471c2a4 \
|
||||
--hash=sha256:82f8bd51e8d3baebf622b52469bdc316c6c1c6e48102d33c76611f37f5924582 \
|
||||
--hash=sha256:8846c1f9c02ec0b73ccaaa1fccecf98f323f2b230a7c6cb19c3917f35d38c4b7 \
|
||||
--hash=sha256:890b0dabdac056908c45b79e07e6dfb51c1dbd7e769d7a4878cdfaf7d1e9ec76 \
|
||||
--hash=sha256:8b9ade32c16df4ad98c72fa08a6558a06534f00d3dabffc2abec8fe6d3c3e242 \
|
||||
--hash=sha256:8c658588d0f4d59a668e8f0e854672a528a92018ad379b40886723a429ca9273 \
|
||||
--hash=sha256:92503a642b207cf9d085f4f79f9b66c972208262bb1b12bca95c3a0c6deddea3 \
|
||||
--hash=sha256:96a548e9243889fec7622abb7e10d362a33f755ffff5092874f3dc0e8e05cc10 \
|
||||
--hash=sha256:98e0f4f424fed81b72345b8a249ab8a6bf40f2faf5caa96b8bede344a755ec61 \
|
||||
--hash=sha256:a1bc9d4ae658b3309e354a6cf70e300ca69d680f05235ec8945f4e2d8c05e246 \
|
||||
--hash=sha256:a4af8feff8bf9970b9cb7be1fd1613dcedf3a49233de37dee9198c962d30f661 \
|
||||
--hash=sha256:a5de408dc8b8da86665d402746c84f8258874410c11fead98f4ab6a74db29b96 \
|
||||
--hash=sha256:a716ed58512bd33bd9736e245db15acfec542e54d10623b9faa42632404efcc8 \
|
||||
--hash=sha256:a7826bda0f21625499db4c9b46a60025f2c83f7b6139c777a21e9c2c5e1a67c5 \
|
||||
--hash=sha256:ab51a50fbe2bd45c649dc0e8624fbef5cb9553e046ad1cf7fb658b6c8b0273de \
|
||||
--hash=sha256:ab7a65a669a03400507b4e573119ba3b26e156797526e71669476de8605bbe1d \
|
||||
--hash=sha256:ad272f556b10a7eb68b6240ea5777f59d89d59b780987459225ab8650681b373 \
|
||||
--hash=sha256:adae5a2f5f7c5d6307c360cc1f1cc3b1d91961b23c25c44dee5066ea039bddfc \
|
||||
--hash=sha256:aec1570d4986f4ab000b0adac485c4b6bf5520b12305bae3defbe6a5e4816d55 \
|
||||
--hash=sha256:af8507908c84da92eacb366586a455080a237003497d19b0738c4d5b187a3cbb \
|
||||
--hash=sha256:b1cda2c0c0c646d36745425eff94f78ef3df58489c78316181a6caa8cdfd9cc2 \
|
||||
--hash=sha256:b26764004a7bd6450769c47a470b0ce8984146baae7d0063ca70bfdbbb0e56dc \
|
||||
--hash=sha256:b4f6b36f37436093e2ad2471118e9fa13055fc4dcd452ed4ced148c8d73684b9 \
|
||||
--hash=sha256:bbc789b2b36baba17377ab63f3dcbbaa8e3a72e5f2963ee24ff4aeb7e9a9bb91 \
|
||||
--hash=sha256:bc3472058534dec5fe414cd7de626ecbc20330effe05de66cbfe36c6aaeb0d78 \
|
||||
--hash=sha256:bdc94de8d11ebeb704d6696641164a8ad4640616f407569d41330eb9390408bd \
|
||||
--hash=sha256:bdd922cbe6ba23c3c827f75ca692f881885009c83c7d0fc1fe0520d80ca36b33 \
|
||||
--hash=sha256:c33ecdec5779328131e575ec133ea4a134370058c9a8f6b7c80761c5f992389b \
|
||||
--hash=sha256:c5e9b40518489f5bf6bf8e2cb4f2ea7ae935fb063c4d18d2593d52db136ed7b1 \
|
||||
--hash=sha256:c6a30b314e8d68a29c7c612ed91ea0f83c8b84f2d83750a7584d325ecca6bda3 \
|
||||
--hash=sha256:c6ce996aeae20af75fb1f0b69201bf0fc2936783533e0f1f171ab7cda6e5ed14 \
|
||||
--hash=sha256:c7ff90e1f4162377af38b0381c7f95353228206e76aa8c3eabf9945f1409461f \
|
||||
--hash=sha256:c8b4390b0e79235acb8c4d2337e76efdf00fd17936b19227726ec63f23840acb \
|
||||
--hash=sha256:ca9c34cc98ce7776d4a1468dd281eb39a3af6fbb75faac5d69bd4c0ef22a2621 \
|
||||
--hash=sha256:cbe55c9da4521be16f79c91618d7c3f9471d9302d6495d6f52cf97c36d054f49 \
|
||||
--hash=sha256:ce79aaa77a6fc6f2784f3c87933aca2e61b6cec5a89d91c730fc051379f181a5 \
|
||||
--hash=sha256:d3eca18e218b10bb96d8d5cb441968ed4ccbcd83c89076f3c86cd5545e0b12ab \
|
||||
--hash=sha256:d629945094190237ec0b3a6d7656ec13b6d2711ac62998005adf5a4ebfe7b836 \
|
||||
--hash=sha256:db47b8fa2f99ade35e3d3d05ca62245e7431c9c8528578aaf3a937602b87a314 \
|
||||
--hash=sha256:db9453ac96ef4e0e9da1ce1b62e5595af1ad2d55bd1dcdfef595d0515d2d3995 \
|
||||
--hash=sha256:dbf8be064709ef364b68acc7b753dbe044ca01d2875afdad50222ae3ce7bc374 \
|
||||
--hash=sha256:dc35dfc110dd744e709824ea56453ca2ff8e4f8175c950485d4916f19689b4c6 \
|
||||
--hash=sha256:dc3d0cf03cee06dcb33a0ed73bb706d15c799684510dd1f8d4ce86cc03fbda91 \
|
||||
--hash=sha256:dcdc5148510e5ada01ce89d52f86cd50a04dfcdc7f689d2607e72cbfe307e594 \
|
||||
--hash=sha256:e2b3e73c7a6cf2ed5ac8ab57aece1feff46c709c60cc88602bebd29f733ad340 \
|
||||
--hash=sha256:e2d59dc834612f4846d823d29d90d9de5527efdb46b51fa661e9dcfe853e8211 \
|
||||
--hash=sha256:e4e460a2709fc62802409c2ace7935d76087f317f907884da660e580a9bcda06 \
|
||||
--hash=sha256:e7a6af029d80758314e9363a36652944002faff7f1cf6c5add11f5ab15ef3170 \
|
||||
--hash=sha256:ea008d686f2c3b0fb9a306a4ea81201344cd4e1a93026017d469b1211721dd46 \
|
||||
--hash=sha256:ee165057e76dc133b18726f2283036d3cccdbe70613b940d73c729d51b011b81 \
|
||||
--hash=sha256:f391937c761ae69e5416b8900a8441b78baa334349e068be9d72ebb3006d62aa \
|
||||
--hash=sha256:f4052ef252d9225562f73c6235a8606ea3735f7f24a07c6dc08af3567eb2031b \
|
||||
--hash=sha256:f45d6552e58e13015105bea5b8c6d012ac547e1b3c5d653b094daacc8c7de1d6 \
|
||||
--hash=sha256:f45ddfdf69dac79736c3365f4b73a5f849f488c427535bc426d685a6101c68ff \
|
||||
--hash=sha256:f63e2bae46f4ba6353869c6441d81c027fce74a2edac1b20bfac2c0098581a27 \
|
||||
--hash=sha256:f7e577bc4d08eb25c06f32f19726e3b2bbbb01a719873efbd4514ef7dc372729
|
||||
pydantic-core==2.46.5 \
|
||||
--hash=sha256:013d6f3483d81e02e7c328831808f336c8596ee33b4bd4026b9ffb1e960b8942 \
|
||||
--hash=sha256:03b9666e41e35d8909852ba191a0607520f81b74eaf12ccf8737005dbb313821 \
|
||||
--hash=sha256:045ab3b6d308439e32b81cc173bba5b9018bc6ed896afd0c65b3b009b1699af5 \
|
||||
--hash=sha256:0bddb4020d8f04175865ccd17eff3040874fc11fb593f424edb452653b4b947c \
|
||||
--hash=sha256:0cdbada856a1c69a7624a64d3d9aefe79300bd6ef827b43a4f265010b9b55184 \
|
||||
--hash=sha256:0fc5be0abd4a407e200d844b404e33639a554e7bd0d448e7b9ae181be4789ac2 \
|
||||
--hash=sha256:10416c15b8839ecc4ef4d0885da76da6fd0f67333a0eb8aff6d93c4b8f2910fc \
|
||||
--hash=sha256:15f4a94963c95accac15b7b657bb177d3ad82bb90b0d0526d9a9b85079925db5 \
|
||||
--hash=sha256:18a09e1e1011b462f2e32774f25859ef1223d5c2b0546a633cf56654710721e0 \
|
||||
--hash=sha256:193375f3548919d3f0b60936ca113ada3e38f264f91b9b8e0508efaad57be931 \
|
||||
--hash=sha256:1a353f84de772f423b5ffb11d7ae352fbbef0f446f3c0b0af0f8236d7233606e \
|
||||
--hash=sha256:1e449def1945a462c464331254e5a44fca7c3b4f9aedf59ec2f50f8066dd8e25 \
|
||||
--hash=sha256:1e5aad1220a1192c42341c8fd4a8686657e73ab2a920c970bdc4de334fe3193d \
|
||||
--hash=sha256:200aa3dc9f8d54f0754f43247c0bad0999fdcfbfd2488384dd44f37279271fe6 \
|
||||
--hash=sha256:2471fd51c61c610e1dcf7de44d7299283661654d11264ab4802b303368d69c47 \
|
||||
--hash=sha256:24922243639cbdac66c75fcb6fd6495a9cb52b213d62f9a0d16f0310b1ff8038 \
|
||||
--hash=sha256:28a6a556cd3b6066bea827857f9d9cce027c96f776e512f544a581f9e42161f8 \
|
||||
--hash=sha256:2bc9419666990c06d7397831f2126a1ecc3594aaa3ff7de5bf2d066802f4e07b \
|
||||
--hash=sha256:2cbd9a5eff05e51c447c34dfa4632145b26b09120cf04bd0c871e44c1a5e1c9a \
|
||||
--hash=sha256:2d330aaba8621b1edcec8ae2c4050f63b84ccf6d98723a8f212e9684713abf0e \
|
||||
--hash=sha256:2d5d76654becf5efd62c9e51c3756c67b49498b0c9a40884934c40807adbd074 \
|
||||
--hash=sha256:337639ba62a11acde6ef3aeb08c8ea755f8ef1fe5e513356c0f36a2b0d7568b0 \
|
||||
--hash=sha256:347ec774390c87326a2e4929d58d3f7e8763a104d5d35f4cd595a4c952366433 \
|
||||
--hash=sha256:356c8368cbc321050b169595683a2e1d63413b1e0e2868b330af9fc14c616d3f \
|
||||
--hash=sha256:37ae34309d7bd8c0d61ab839668058f2a7962ea1fc51d105d2db228fe0618034 \
|
||||
--hash=sha256:37ea7b83c935e5b0d68c9449b82651accf78a10828b2c02b2f2d9e9496446c21 \
|
||||
--hash=sha256:3a3e26b6a8274211bddee2d0e4d0d42778f17a34510f49d2ec44b58abfc41736 \
|
||||
--hash=sha256:3aa166e99c4f2985407fb8714aebede877ecb5455cf321b606adca926d30d5a0 \
|
||||
--hash=sha256:3d2652072b2d774947ba5cf78a9e59644ac62ee572daf6dd2e1dfe905e15b2b7 \
|
||||
--hash=sha256:40375c2d05acec10323e45dfe2077ac44bc74659008614af5069034e2cfc781c \
|
||||
--hash=sha256:413a717a410d0c817ef5b786a059415550b3794e1d0c2abffd9efb93a3d9f7b4 \
|
||||
--hash=sha256:46c25dda9d092a06c08db76ffe0a197107904d0dfac653f7d5306bbcd6d6119c \
|
||||
--hash=sha256:49776eab08766a08dfff7012f8b422dcd7e25e43b316eedf0477c24fcfa84b7c \
|
||||
--hash=sha256:4d44cf99ddebf875f9b68cc267aa684c99b7b44fe63ee1cac4ec163807290069 \
|
||||
--hash=sha256:4dedce55295becb61921e386b99d4f2706045306e7fa52249a33004c837379fb \
|
||||
--hash=sha256:4f8507560a9284e1370bb048ed4282012fbef4e8d109875b95e884d228552061 \
|
||||
--hash=sha256:4fdc8b93a41521988916eeaa271173fcca7fa0803d62f87675aac8dcec1c8e29 \
|
||||
--hash=sha256:5086029a57366b8cf81b130a43908738095c270c21a8d7f0e8bdfdb89718e2f3 \
|
||||
--hash=sha256:52e24eacdb536cade636aa90fb851835222becff8484b7001fdc78cb0290f2aa \
|
||||
--hash=sha256:53feb344243bb9510a9dec7bf3cf1b64d88a98af5dc7872a5160465f8b198c8e \
|
||||
--hash=sha256:545f26c504b27c3758439a5e6d9349931f0a04f855668d5fe323c89e82300a38 \
|
||||
--hash=sha256:54d510bac3ee52247af28ed4bb18a1e799f040ac60fd2bf5ccd4c92f1fbe786f \
|
||||
--hash=sha256:5cb482e9e84c851f4e623fe4acc1ced89168cf1fe18f7089db4548c8f5bbb65b \
|
||||
--hash=sha256:5e81740c09e310f5aa5cbd3e434a01c154d4bef93241c7877b39f211d2b78ba8 \
|
||||
--hash=sha256:5ee239d575f80b08eca11f6e20f90c4c695de7825c67eefe6091fbf20dda648e \
|
||||
--hash=sha256:5f194189415698233dd1114a093a9b56e61e2c57e11b469be3b0506f46f0771c \
|
||||
--hash=sha256:5f93c5fe914d75fbec9a49209b00da5f08e9e467d69da2b1510c81940cfd10be \
|
||||
--hash=sha256:657b40d6240c0a7b6a64b30f22d1e3aa631c7e846c621b0c0f6d1d75e2e15ea6 \
|
||||
--hash=sha256:6d30e1a4f138b8951063e9a394752a9179b51da288ffa507b1e659222f4c1793 \
|
||||
--hash=sha256:6f7b393a8b3da82f5c1fc0751e6d01ac6c55b93c18226a60bdfba4a724efafd1 \
|
||||
--hash=sha256:701b2e04b560eeb4bddf7a25ab8ca476176e34fdbd9a0e18196f0d12d4685f0b \
|
||||
--hash=sha256:771cf63ae0b1b50dd22e5f3e3549fab5f3f4ff1635d352a9e1a97fe01c7b2e64 \
|
||||
--hash=sha256:79bdfa52f843137045b2d081cc05c120ba6665d29b7559c2c47690906f39279f \
|
||||
--hash=sha256:7ac031912d54f3d83ef3b3eb98dfabc1608802e2202263d25957eeed40b94761 \
|
||||
--hash=sha256:7b0fc826b16c55e561e5d2a0c5c77b051ba1d92808118c4e4b5390f5e0cf191d \
|
||||
--hash=sha256:7c6be839a5a8312626b32029a415644a0846b420bc8b52b95b28cd92da162168 \
|
||||
--hash=sha256:816ff0a6550ffc06c098ccd2e0698600f9aa7da192a79eaa6f9af504a35db869 \
|
||||
--hash=sha256:82a36973cf8a2ef5406f4fe2edbf8ed0c99629535d959e0b100c76a32535a111 \
|
||||
--hash=sha256:837b396ca3d7b74091ca623f6cbd8351bd42d670a79c2683e79fb089f06a2de5 \
|
||||
--hash=sha256:850a08d167dde16db8702c274f320c7be9d7da6f6dff2b58b18f9e815bd94f5b \
|
||||
--hash=sha256:8816f3d218beb4b787de5c9759c259b8fa61f9dec42dc7811f320a33771778b7 \
|
||||
--hash=sha256:892a881d5f68c2b9ea304b7a6c2c60d9343df578a311b0f86b94bc8f1ffe8129 \
|
||||
--hash=sha256:895395f8918627b04efb1ad2a4cf605387143300ba03304cd1dfa6d03f5e095e \
|
||||
--hash=sha256:8b10e3e8fd7ddc2bd915848a2768e44c15b22936f1cc54c462ad1164deb02655 \
|
||||
--hash=sha256:8e24d8f05fa2d28513d94e877e9c75ad66175376209b3977f916e240e623193c \
|
||||
--hash=sha256:8feeac04b5794e513e710af2f9c87d49f31a6dc47967bb264a1fed61a8989bec \
|
||||
--hash=sha256:9432f3598db432cb51c5b37fdbf29a60fcccc79e30d37a05022776a6bc4ab689 \
|
||||
--hash=sha256:976e1128455aa595ea04c79ccfedff1aaeab96ee013fcc916bed120c4f0ad94f \
|
||||
--hash=sha256:978e7b97d4824b5be09c69fb70507cbde3b0323fc147332ca40a94d9a6a0ebbf \
|
||||
--hash=sha256:97bf8de4d541598c94a59344eeb988a94c08ff76b5723c41f6567ec18c7892ea \
|
||||
--hash=sha256:97cf3eb53a8cccacf9d46686a0926186c9bfb5574f2ed66d3639d5fe117cd3a9 \
|
||||
--hash=sha256:9b68938dd5b0c783d88ff8e2dcc69451b5eb936fe212d516b21b9d5567f6d464 \
|
||||
--hash=sha256:9c4b71f10dd532fb7a5cbc8f58707779e64f03a258c2bf8bfbaecfcd9970b519 \
|
||||
--hash=sha256:9f47b8a949e60f027f0aa0a6f6c7b7e9c55cbf4380d10b344e282fa4e7ab1e1b \
|
||||
--hash=sha256:a1dee1b804ff4d11c663636cf15d2ea47e9f79cd56c033fb1cbf08924842a48f \
|
||||
--hash=sha256:a2468d93d181667a7abd66e1b64bb9f76f361b0fef8faddf687456453576f5ee \
|
||||
--hash=sha256:a2a5e1d0ff29adddc9f6d6821a66302e4493f8ca898b715b6b1182c2c201ea0a \
|
||||
--hash=sha256:a39ac25a9a2fa4072efdb429833c4a4c8009a51ff9eea3eeae131713cd27991e \
|
||||
--hash=sha256:a445486499897b88a7d6c310c88ed64dd37b1b59bfd7ae9107490bbb362f47d6 \
|
||||
--hash=sha256:a91c17edf6eea2402cb5457b4c89e99bc5ed1004aa34c4adf1d4258c1a5c22c2 \
|
||||
--hash=sha256:ab4b66edffb32d9e951efb3814bd104b8367a7501b81b955cacb5726d897389f \
|
||||
--hash=sha256:aca6c767f552b21b10f774aeac128e828eafb796adfa1b666a18bf6321453c3a \
|
||||
--hash=sha256:acf8a67ba51f4ca9ddbd0e6b3000a65ac51ab734661778b3e7ba64d99a710f2f \
|
||||
--hash=sha256:b10ec717381bdbfafef34607824db4c91de69ff085e4fca3b2af91b4fa17e68a \
|
||||
--hash=sha256:b49924c73a235e969511bf2aabdff3beebf9820931f646c80274d5d780010c47 \
|
||||
--hash=sha256:b6acfb46a814762367fb7ba0828b0a17d441b92ce249a0e007474c9072662dda \
|
||||
--hash=sha256:b7ca9034437b6022f941f4857459562ee00a560b97e7cce8a0ec5a74fc6766e0 \
|
||||
--hash=sha256:b98134087d9de723658d17a42c7d0da8d6e2ef08015dee7dc93889047315f5e4 \
|
||||
--hash=sha256:b9fe6fb92520e3fd61f2e49000b6911b188824f089b75973ea06d6267f0b476d \
|
||||
--hash=sha256:bce57638e08ac148e5778cce7feb968307a727d66f8e2274a543d0cf0c9ad6a3 \
|
||||
--hash=sha256:c14ad3bdc85ee7f318742c457ca3968a92126d144b15721c759033bfb06296c2 \
|
||||
--hash=sha256:c1c43ad4339643d70ebb8124e1305a7dab423001eff58bb41a0f731adbc98355 \
|
||||
--hash=sha256:c3471e5c4a949c26ec00a77f01df59096aa9495877de76fd60a980f8ee6be461 \
|
||||
--hash=sha256:c583b927a8838dab890706a6fa7573fbb8b70e24000ef9f7238e2d6f6435a5ed \
|
||||
--hash=sha256:c76fe65e607be28c7fd4d56fc3c42b1583aa058ce3408b7ad0fd540171d31f9f \
|
||||
--hash=sha256:c7ea57fc63aa7da93a1bd2d644e6577befae10c52c4e36377635eea1056a74f5 \
|
||||
--hash=sha256:cd5214352ae68f3b5e9af7768bdc5253695ee069675db3480518420b3be881f2 \
|
||||
--hash=sha256:cdbb78909f52b981d3b2d56b97328d71eb0b974c36bd77c920123a7ebb192829 \
|
||||
--hash=sha256:cdc8b74ecc48c0cb1e9607a05ec4e9e88db60a19ffcc9a1d5f9088ede40c8dc0 \
|
||||
--hash=sha256:d0a24b40877af2de4950252be9d21eaf7fb07660f3c2cae1f56c6b599ada5266 \
|
||||
--hash=sha256:d22a945598fb91236b4dd793a6e42e4f3dd7740bb5aace5ebd7d4c08d13bb575 \
|
||||
--hash=sha256:d2f9fc07a8042a8f95925b35c4f04f469707c981fc33245b6ca187cf5d2dd290 \
|
||||
--hash=sha256:d625a186a65201c23a9e3b8ed9c47e90a026e03256608cc91851c6709096844f \
|
||||
--hash=sha256:d925f3d9afd05a8c0fb3a1031463a8d59ebe5e2afad297e29c78be19e13b4e62 \
|
||||
--hash=sha256:e64e88d5585bea9ce95861079de72006c7fa6d3df4e3a3b65ba31eb979c15c9f \
|
||||
--hash=sha256:e652ab17569c94bff5475520f907b7148b8c24036a8ebbe5cf7cf7493d28579a \
|
||||
--hash=sha256:e7b891faeedeafba41b2983e5001a81b6a915b69544c7e7570d1989ce1c36ac7 \
|
||||
--hash=sha256:e80675d75ae2cd14372cb65cad5400d9347a3d3f6c13000183f22dfd027283ed \
|
||||
--hash=sha256:e9c134bb666dd54b778b9fc0d2b50cbb7f979b9e3716f26a88c9ab3b6fc1dd0f \
|
||||
--hash=sha256:eb7d8d0e5886a89a55d2eef490e272fa965a9d57c6b29a5b5088a7997ec2cad1 \
|
||||
--hash=sha256:ecb42011e12ee19cafbc312887cbf3546959fe02fbad44f272d4be5baa997615 \
|
||||
--hash=sha256:ef3fbbf161dc9351a2fe0422e51b129f9e97e42385bd0320b309c15f7d287dd8 \
|
||||
--hash=sha256:efd62a42486f1bda5d24cb4f63d15a3c7768375fe83d36f9417b4ad7a2fb20b3 \
|
||||
--hash=sha256:f077d0b97ab11fa7dcc633fca53515f290bca8a8a633e966d5b6d1879d9ed01a \
|
||||
--hash=sha256:f332f0e72a5a0400141f830744e141bf9f97917878dbe968669e8a7fefea78ff \
|
||||
--hash=sha256:f7b0ec93a2893de856652154d73b7ba622f26fa97726487dcac373de5f4c6084 \
|
||||
--hash=sha256:fa10ef4112775900e7a0661068635eb67b2ab824fbde764de6e0e21982a93db0 \
|
||||
--hash=sha256:fc5d783bd4a2387e97b8a2d5ec781cfb92b3d893bf82370548e99db5915935d3 \
|
||||
--hash=sha256:fc8515076c11f3cfdf4fb142dcca0fe384b1230a3b5415458ac84f3e0903ec13 \
|
||||
--hash=sha256:ff218293c9c806138dca139765e3b067621be52bcd93cdc14c7711be7ddc90a9
|
||||
# via pydantic
|
||||
pypika-tortoise==0.6.5 \
|
||||
--hash=sha256:64d96c9b88450f6360ad22a7063933b6a90961a7317f04b2b63c98fd5d705506 \
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import base64
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.base.models import KeyValue
|
||||
from apps.base.mcp import sanitize_html_preview
|
||||
|
||||
|
||||
def test_html_preview_sanitizer_removes_active_content_and_event_handlers():
|
||||
output = sanitize_html_preview(
|
||||
'<h1 onclick="alert(1)">Hello</h1><script>alert(2)</script>'
|
||||
'<iframe src="https://attacker.invalid"></iframe><a href="javascript:alert(3)">link</a>'
|
||||
)
|
||||
assert "Hello" in output
|
||||
assert "<script" not in output.lower()
|
||||
assert "onclick" not in output.lower()
|
||||
assert "attacker.invalid" not in output
|
||||
assert "javascript:" not in output.lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_initialize_and_list_tools(initialized_client):
|
||||
init_response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}},
|
||||
)
|
||||
assert init_response.status_code == 200
|
||||
assert init_response.json()["result"]["capabilities"]["tools"]
|
||||
|
||||
tools_response = await initialized_client.post(
|
||||
"/mcp", json={"jsonrpc": "2.0", "id": 2, "method": "tools/list"}
|
||||
)
|
||||
assert tools_response.status_code == 200
|
||||
assert {tool["name"] for tool in tools_response.json()["result"]["tools"]} == {
|
||||
"share_text",
|
||||
"share_file",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_rejects_cross_origin_requests(initialized_client):
|
||||
response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={"jsonrpc": "2.0", "id": 3, "method": "tools/list"},
|
||||
headers={"origin": "https://attacker.invalid"},
|
||||
)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_token_can_be_required(initialized_client):
|
||||
from core.settings import settings
|
||||
|
||||
record = await KeyValue.filter(key="settings").first()
|
||||
config = dict(record.value)
|
||||
config["mcp_require_token"] = 1
|
||||
record.value = config
|
||||
await record.save()
|
||||
settings.user_config = config
|
||||
|
||||
response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": 4,
|
||||
"method": "tools/call",
|
||||
"params": {"name": "share_text", "arguments": {"text": "private"}},
|
||||
},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
from apps.admin.dependencies import create_token
|
||||
|
||||
token = create_token({"is_admin": True})
|
||||
authorized = await initialized_client.post(
|
||||
"/mcp",
|
||||
headers={"authorization": f"Bearer {token}"},
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": 6,
|
||||
"method": "tools/call",
|
||||
"params": {"name": "share_text", "arguments": {"text": "private"}},
|
||||
},
|
||||
)
|
||||
assert authorized.status_code == 200
|
||||
assert "/#/?code=" in authorized.json()["result"]["structuredContent"]["url"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_html_share_has_sandboxed_safe_preview(initialized_client):
|
||||
dangerous_html = '<h1>Hello</h1><script>alert(1)</script><img src=x onerror="alert(2)">'
|
||||
response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": 5,
|
||||
"method": "tools/call",
|
||||
"params": {
|
||||
"name": "share_file",
|
||||
"arguments": {
|
||||
"filename": "preview.html",
|
||||
"content_type": "text/html",
|
||||
"content_base64": base64.b64encode(dangerous_html.encode()).decode(),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
code = response.json()["result"]["structuredContent"]["code"]
|
||||
|
||||
preview = await initialized_client.get(f"/share/preview/html/{code}")
|
||||
assert preview.status_code == 200
|
||||
assert preview.headers["content-type"].startswith("text/html")
|
||||
assert "sandbox" in preview.headers["content-security-policy"]
|
||||
assert "Hello" in preview.text
|
||||
assert "<script" not in preview.text.lower()
|
||||
assert "onerror" not in preview.text.lower()
|
||||
assert "nosniff" in preview.headers["x-content-type-options"]
|
||||
@@ -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