Skip to content

Fix #8: tighten validation and stop leaking internals (6a-6f) - #15

Open
xiaoyao-666-coder wants to merge 2 commits into
zhengdaodeguL:mainfrom
xiaoyao-666-coder:fix/issue-8-validation-exposure
Open

xiaoyao-666-coder wants to merge 2 commits into
zhengdaodeguL:mainfrom
xiaoyao-666-coder:fix/issue-8-validation-exposure

Conversation

@xiaoyao-666-coder

Copy link
Copy Markdown

Closes #8. 六个子项:

  • 6a 年龄无上限:年龄抽取只接受 0–120 岁(项目内既定口径),超范围忽略。
  • 6b base_url 归一化太松:仅接受 http/https;query/fragment 从返回 URL 中丢弃;拼错的 .../completions 后缀直接报 ValueError,不再静默截断(拼错的 /chaat/completions 后缀已删除)。
  • 6c create_session 不校验用户:SQLite 与 MySQL 两版都先查用户,不存在抛新增的 UnknownUserError("user does not exist");重试循环只对唯一约束冲突重试,其他 IntegrityError 立即原样抛出。
  • 6d /api/query 暴露 SQL、样例数据无标识:as_dict() 去掉 sql 字段(内部仍可读 .sql 属性);新增 sample_data 字段,内置样例库时为 true,前端在样例结果旁显示“以下为内置样例数据,仅供演示,非实时业务数据。”
  • 6e 引用 URL 嵌套凭证绕过:前后端同改,分隔符加入 # 与 /,并对解码后的嵌套值额外检测 ://[^/]*@ 形式的 userinfo。
  • 6f test 模式本地向量是死代码:去掉两处 provider != "local" 排除,本地向量真正参与融合,引用 retrieval 现为 hybrid;本地向量用 0.25/0.60 低权重融合(64 维 token-hash 向量噪声大,全权重会压过 BM25 导致排序回归),远程保持原权重。

验证:新增 backend/tests/test_validation_exposure.py(14 个测试);MEDGUIDE_MODE=test python -m pytest -q backend/tests 537 passed(基线 521 + 16 新);前端 npm test 10/10,npm run build 成功。

说明:6d 选的是“标注样例数据”而非“默认不 seeding”(样例库是 test/local 模式默认的唯一数据源);6f 的本地权重是手工取舍,如上游换成真实本地 embedding 模型应重新评估;6b 的 query/fragment 选的是丢弃而非报错(拼错 endpoint 才报错)。

…a-6f)

6a. Age extraction accepts only 0-120 (project's established
    range); out-of-range ages are ignored.
6b. base_url normalizers accept only http/https, drop query/fragment,
    and reject misspelled .../completions endpoints instead of
    silently truncating them.
6c. create_session checks the user exists first (new UnknownUserError)
    and only retries on unique-constraint conflicts, in both SQLite
    and MySQL stores.
6d. SQLQueryResult.as_dict no longer exposes 'sql'; responses carry
    sample_data=true for the built-in sample database, shown in the
    UI as demo data.
6e. Nested-credential check covers '#' and '/' separators and
    userinfo in decoded nested URLs, in both frontend and backend.
6f. Local (Hash) embedding provider is no longer excluded from vector
    retrieval; local vectors fuse with a lower weight (0.25/0.60) so
    BM25 ranking quality is preserved.

Closes zhengdaodeguL#8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][中] 后端多处校验与信息暴露问题(年龄上限、base_url、会话创建、SQL 暴露、引用 URL)

1 participant