Skip to content

fix(presentation): scan every static-site text asset and fail closed on unreviewable text - #9406

Merged
huangruiteng merged 5 commits into
loopx-project:mainfrom
JasonBuildAI:codex/static-site-text-selection-m0cw
Nov 26, 2026
Merged

huangruiteng merged 5 commits into
loopx-project:mainfrom
JasonBuildAI:codex/static-site-text-selection-m0cw

Conversation

@JasonBuildAI

@JasonBuildAI JasonBuildAI commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

loopx presentation package certifies a whole static-site bundle as public-safe while inspecting only eight filename suffixes and decoding only UTF-8, so ordinary text assets such as .csv chart data, .log captures, .yaml config, .env, Dockerfile, .map/.tsbuildinfo JSON and BOM-marked or BOM-less UTF-16 captures are copied into the publish artifact under ok: true without being scanned. This PR makes every text asset in a copied bundle reach the existing public boundary patterns regardless of its filename, decodes the encoding the asset declares, and fails closed when the bytes cannot be reviewed as text. It also keeps the publisher's own media support boundary, so a browser-decodable container such as AVIF or APNG is copied verbatim instead of being decoded as text (review follow-up on both P2 rounds below).

  • Outcome basis / optional anchor: the linked issue recorded below; its number is inserted once at publication.
  • Goal/source and gap: _scan_public_text in loopx/presentation/static_site.py returned before reading unless the asset's suffix was one of .css, .html, .js, .json, .md, .svg, .txt, .xml, and always read bytes as UTF-8. The repository's outbound public-safe scanner already documents why an allow-list fails for this task (loopx/capabilities/public_safe_outbound/scan_cli.py, _iter_text_files: it "silently skipped .env, Dockerfile, Makefile, id_rsa") and decodes the BOM-declared encoding; the static-site publisher never received that correction. Follow-up to fix(presentation): scan every static-site text asset at the public boundary #9370, which removed the separate 2 MB exemption and recorded this gap as out of scope.
  • Observable before → after, with the validation row that proves it: at base a7d72a1cf, a site with data.csv carrying a synthetic GitHub token returns {"ok": true, ... "write_performed": true} and the token is present in publish/data.csv; at head, the same site returns {"ok": false, "error": "public boundary scan failed for data.csv: provider token"}, exits 2 and creates no publish directory. The same before/after holds for .log, .yaml, .env, Dockerfile (including nested paths), .map, .tsbuildinfo, a BOM-marked UTF-16 .txt, and BOM-less UTF-16 (the last reports content is not reviewable text). For media, the first reviewed head ebac4eb9b rejected a valid 16×16 AVIF with public boundary scan failed for assets/hero.avif: content is not decodable as utf-8 and created no publish directory; the second reviewed head 204fd145e rejected a valid 16×16 two-frame APNG the same way while accepting the identical bytes renamed .png, while base a7d72a1cf published both. This head copies the AVIF (331 bytes), the APNG (239 bytes) and the renamed .png byte for byte with matching manifest digests, and each still rejects a .csv credential placed in the same bundle. The regression_parity and real_entrypoint rows below record the raw comparison.
  • Issue/task and intended base: Fixes [Bug]: static presentation packaging certifies text assets outside its eight-suffix allow-list without scanning them #9405; PR base is loopx-project/loopx main, and the branch was cut from main at a7d72a1cf (the merge base), not from the fork.

Author Declaration

  • Written by: model_agent (Doubao, ByteDance), at the operator's request; no human reviewed this change before publication.

Implemented against

  • Specification and revision: the linked issue plus the repository's stated text contract at a7d72a1cf: loopx/capabilities/public_safe_outbound/README.md and scan_cli.py (candidate selection is a binary deny-list, and a candidate is decoded with the BOM-declared Unicode encoding) and docs/public-private-boundary.md (a raw credential token with no label is rejected by both tiers).
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Every text asset the bundle copies reaches the existing boundary patterns, regardless of filename suffix implemented loopx/presentation/static_site.py::_scan_public_text tests/test_static_site_presentation.py::test_package_scans_text_assets_outside_the_former_suffix_allow_list (8 cases, including a nested assets/export.csv, extensionless .env / Dockerfile, and .map / .tsbuildinfo); real CLI before/after
A BOM-marked UTF-16 capture is decoded before the patterns run implemented _scan_public_text (_BOM_CODECS) tests/test_static_site_presentation.py::test_package_scans_a_bom_marked_utf16_capture_before_publication; real CLI
A text asset that cannot be decoded in full, or whose decoded text contains NUL, fails publication instead of receiving a receipt implemented _scan_public_text (strict content.decode) test_package_fails_closed_on_bomless_utf16_text, test_package_fails_closed_on_nul_bearing_text, test_package_fails_closed_on_undecodable_text; real CLI
Known binary assets stay outside the text scan and remain publishable; .map / .tsbuildinfo are reviewed as JSON text implemented _scan_public_text (_BINARY_ASSET_SUFFIXES = outbound BINARY_SUFFIXES minus the two JSON text formats, unioned with the publisher's own _STATIC_MEDIA_SUFFIXES) tests/test_static_site_presentation.py::test_package_still_copies_binary_assets_without_text_scanning; .map / .tsbuildinfo cases above
A browser-decodable media container the outbound deny-list does not name is copied verbatim instead of being strict-decoded as text implemented _STATIC_MEDIA_SUFFIXES (.apng, .avif, .avifs, .heic, .heif, .jxl, .m4v, .ogv, .opus — the publisher's own support boundary) test_package_copies_a_real_media_asset_byte_for_byte[avif|apng], test_package_rejects_a_text_asset_next_to_real_media[avif|apng], test_cli_package_copies_real_media_and_rejects_text_beside_it[avif|apng]; real CLI
Text-shaped assets are not swept into the media boundary: subtitle and playlist formats stay reviewable implemented _STATIC_MEDIA_SUFFIXES (no .vtt / .m3u8 / .mpd) the parametrized text cases above; no exemption added for those suffixes
The failure contract is unchanged: ok: false, exit 2, no publish directory, filename and rule in the error implemented loopx/cli_commands/presentation.py::handle_presentation_command, _collect_site_files real CLI probes below; existing focused suite
Reserved paths, symlinks, manifest/revision receipt and idempotent packaging behave as before implemented _collect_site_files, _replace_output, package_static_site existing focused suite (one Windows-only symlink fixture remains blocked by host privilege; see Validation)
Canonical boundary patterns are not restated or narrowed implemented loopx/public_safe_text.py (unchanged) loopx check --scan-path over the two changed files
Credentials embedded in binary media remain undetected by the text scan out_of_scope _scan_public_text separate binary-content decision, not expanded here
Retained-revision rollback does not re-scan out_of_scope rollback_static_site pre-existing property of the rollback path, not a regression from this change
  • Self-check before submission: I ran the final test file against three revisions — base a7d72a1cf (16 failed, 18 passed: the 8 suffix cases, BOM UTF-16, BOM-less UTF-16, NUL, undecodable UTF-8, both text-next-to-media cases and both CLI parity cases), the second reviewed head 204fd145e (2 failed, 32 passed: the APNG copy and the APNG CLI case, both reporting content is not decodable as utf-8), and this head (34 passed). The first reviewed head ebac4eb9b reported the same two failures for AVIF before that format was added. I also ran the real loopx presentation package CLI on base, 204fd145e and this head for 11 token shapes plus PNG, AVIF and APNG controls, Ruff, git diff --check, the repository loopx check boundary scan, the two static-site examples, the architecture import-boundary test and both UTF-8 guards. I did not run the full repository Python suite; CI's pytest job covers it, and one unrelated required test is already red at the base commit (see Validation). On this Windows host python -m pytest cannot create the symlink fixture (WinError 1314), which also fails before and after this change.

Scope And Continuation

Validation

  • Tested revision: a603af13167f5214083d759b27b9de736050381d
  • Exact-head refresh: merged latest main (af946a5c1385e3a566386e69cfefcf512802af3f); focused static-site suite 35 passed, architecture import-boundary suite 34 passed, real CLI byte-for-byte media controls and adjacent text rejection passed, and standard premerge passed 6 direct checks plus 2 catalog canaries with 0 failures.
  • Run state: finished
  • Input classes: synthetic text plus two real encoder-produced media assets
Check kind Result Public-safe evidence / limitation
regression_parity passed Base a7d72a1cf with the final test file: 16 failed, 18 passed, 1 deselected — the 8 suffix cases (.csv ×2, .log, .yaml, .env, Dockerfile, .map, .tsbuildinfo), BOM UTF-16, BOM-less UTF-16, NUL-bearing UTF-8, undecodable UTF-8, both text-next-to-media cases and both CLI parity cases. Second reviewed head 204fd145e: 2 failed, 32 passed — the APNG copy and the APNG CLI case, both with content is not decodable as utf-8; the AVIF cases pass there. This head: 34 passed, 1 deselected. Counterfactuals are the removed suffix filter (base), the permissive UTF-8 read (base) and the one-suffix media set (first reviewed head).
real_entrypoint passed Real loopx presentation package --execute. Text: 11 token shapes at base publish with ok: true, exit 0 and the synthetic token in publish/ for 9 of them; at this head all 11 return ok: false, exit 2 and create no publish directory, with content is not reviewable text for the BOM-less/NUL shapes and provider token for the rest. Media: a 16×16 AVIF and a 16×16 two-frame APNG are published byte-identically (331 and 239 bytes, manifest sha256 matches) with exit 0; at ebac4eb9b the AVIF was rejected and at 204fd145e the APNG was rejected, both with exit 2 and no publish directory, while the identical APNG bytes renamed .png published at both heads. Adding a .csv credential to each media bundle returns ok: false, exit 2 and creates no publish directory.
unit passed uv run --extra test python -m pytest tests/test_static_site_presentation.py -q -k "not test_package_rejects_reserved_paths_symlinks_and_public_boundary_leaks" -> 34 passed, 1 deselected. The deselected fixture fails at base and head on this Windows host (WinError 1314, symlink creation privilege), so it is not a regression.
unit failed tests/test_runtime_subprocess_utf8.py::test_shipped_runtime_pins_utf8_for_every_text_mode_subprocess_call fails on loopx/control_plane/goals/planning_batch.py:704, a file this PR does not touch (2 changed files), from #9263 at the base commit. An in-flight contributor fix owns that lane; it is disclosed here rather than claimed as passing.
static passed uv run --extra test python -m ruff check loopx/presentation/static_site.py tests/test_static_site_presentation.py -> All checks passed. git diff --check -> clean.
integration passed uv run --extra test loopx canary premerge --from-git-diff --git-diff-base a7d72a1cf -> status passed, changed_files 2, surfaces python, 0 failures, 0 advisory failures, 0 manual holds; 6 direct checks and both selected canaries passed. Root npm ci --ignore-scripts was required for the semantic-vocabulary canary.
manual passed uv run --extra test loopx --format json check --scan-path loopx/presentation/static_site.py --scan-path tests/test_static_site_presentation.py -> public boundary scan clean: 2 files. The wrapper also reports one pre-existing local registry diagnostic that the diff does not touch. examples/static-site-presentation-smoke.py -> ok; examples/session-dash-panel-smoke.py -> OK.
  • Coverage and gaps: the parametrized regression exercises the full package_static_site entrypoint (not only the helper), includes a nested directory, an extensionless .env, an extensionless Dockerfile, .map, .tsbuildinfo, a BOM-marked UTF-16 capture, BOM-less UTF-16, NUL-bearing UTF-8, undecodable UTF-8, and two real fixtures — a 16×16 AVIF from Pillow's libavif encoder and a 16×16 two-frame APNG — each beside a .csv credential, so a consumer that bypassed the scan, certified unreviewable bytes or rejected a browser-decodable container would fail it. The CLI case covers both halves through the shipped command for both fixtures. The real CLI covers the shipped entrypoint and records the base, previous-head and current over-reject sets, including the same APNG bytes renamed .png as the control that isolates the suffix boundary. The media exemption is by suffix: a text payload appended to a listed container (.avif, .apng, and .png at base) is copied without review, which is the declared binary-content boundary and unchanged by this slice. The full Python suite was not run locally; the unchanged planning_batch.py UTF-8 lane is red at the base commit and is owned by another in-flight fix. Credentials embedded in binary media remain explicitly out of scope.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A (no user-visible UI change)
  • Craft review: N/A (no user-visible UI change)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: N/A

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A
  • Semantic dimensions changed, or reviewed no-impact rationale: N/A
  • Provider conformance arms run: N/A
  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md). Only a synthetic token shape and <tmp> placeholders are used.
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · reasoning_effort=xhigh

动机 / Motivation

维护者用这个命令把已经构建好的站点目录打包成可发布产物。旧版会漏检表格、配置和部分 Unicode 文本,当前提交让这些资产进入既有边界扫描。正常站点仍应能连同真实图片一起打包,但本次用原生 CLI 验证时,一张有效的 AVIF 图片使整个站点被拒绝。这个切片的范围是本地打包、内容检查和回执。

改动思路 / Approach

当前只调整本地静态站点的资产扫描和兼容性。

presentation package 以站点目录为输入。_collect_site_files 在生成清单前读取每个文件,_scan_public_text 用同一份字节做内容检查,扫描拒绝从原有 CLI 错误路径返回。扫描与打包的职责应留在现有调用路径。共享凭据规则适合复用,出站扫描的文件名排除表用于筛选 repo 树,不能直接充当静态站点支持的媒体格式表。建议保留严格文本检查,在打包路径明确识别合法静态媒体并以真实媒体文件验证两条路径。代码明确把已知二进制继续放行列为本切片的一部分。

具体改动 / Changes

对照 #9405,评审采用 issue-9405 所载文本覆盖、拒绝和二进制兼容三项预期。文本覆盖在 CSV、source map、UTF-16BE 和 UTF-32LE 合成输入上有实证。拒绝语义在非法 UTF-8 和含 NUL 的资产上有实证。二进制兼容在 PNG 对照成立,在有效 AVIF 上失败。评审覆盖完整两文件差异,生产代码 +47/-7,测试 +97。

关键代码讲解

  • _scan_public_text 先判定资产扩展名,再按 BOM 或 UTF-8 解码可检查资产。严格解码阻止了错误回执,但继承的排除表没有覆盖 AVIF。
  • _collect_site_files 把扫描放在新增文件清单记录之前。正常 CSV、PNG 与带 BOM 的正常文本生成有效产物。AVIF 的解码错误也在这一步结束,整个输出目录没有创建。
  • test_package_still_copies_binary_assets_without_text_scanning 当前只覆盖 PNG。它能保护这一条控制路径,无法区分对有效 AVIF 的误拒绝。

对主干的风险 / Risks

P2 [阻塞] 有效的 AVIF 站点图片回归。用独立生成并经图像工具读回为 16×16 AVIF 的图片,在基线 a7d72a1cface08c8d9caea8a61d05fbb1537942d 和评审头 ebac4eb9b3832bbf884ab10345832b0221d56274 上运行同一 presentation package --execute。基线退出 0 且输出图片字节一致。新头退出 2,原因是图片无法按 UTF-8 解码,未创建发布目录。PNG 对照在两端均成功。请在正常格式识别与文本扫描之间补上 AVIF 的支持边界,并在真实 CLI 测试中固定无损复制与文本资产拒绝两个结果。见当前头的格式选择分支

我的整体评价 / Verdict

文本检查减少了生成站点误发敏感内容的风险。真实 CLI 的兼容性对照表明,部分正常站点需要重编码资源才能继续打包。局部扫描与打包职责可以保留,修复范围只需覆盖已验证的媒体格式兼容缺口。定向静态站点测试 29 项通过,标准 premerge 在补齐 TypeScript 依赖后通过,独立 CLI 基线和新头各验证 10 项,AVIF 是有效输入的新增拒绝。没有改动页面渲染代码,视觉评审不适用。远端 CI 未查询。

English verdict: REQUEST_CHANGES — ebac4eb. A valid AVIF asset makes the real packaging CLI reject the entire site. Baseline and PNG controls passed. Keep strict text rejection and add verified AVIF compatibility.

Comment thread loopx/presentation/static_site.py Resolved
JasonBuildAI added a commit to JasonBuildAI/loopx that referenced this pull request Nov 25, 2026
A valid AVIF asset made the packaging CLI reject the whole site, because
`_scan_public_text` treated every suffix outside the outbound scan's deny-list
as reviewable text and strict-decoded the bytes as UTF-8. That deny-list
classifies a repository tree, not the containers a browser loads, so the
publisher now keeps its own media boundary: `_STATIC_MEDIA_SUFFIXES` is unioned
with the deny-list (minus the two JSON text formats) and its members are copied
verbatim, while every other asset must still be reviewable text.

AVIF is verified end to end: the regression embeds a real 16x16 AVIF from
Pillow's libavif encoder, asserts a byte-identical copy and the manifest digest,
and pins the same bundle rejecting a `.csv` credential through the shipped
`loopx presentation package` CLI. A text payload appended to a listed media
container is still copied unreviewed, which is the declared binary-content
boundary, unchanged from `.png` at base.

Refs loopx-project#9405, review P2 on loopx-project#9406.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · reasoning_effort=xhigh

动机 / Motivation

受影响的是使用现有命令打包静态站点的维护者。公开 issue 要求扫描会随产物复制的文本资产。旧版的八后缀过滤漏掉常见文本,当前提交在负例中能拒绝这些输入。此次把检查放在生成文件清单前,并对无法完整解码的候选文本拒绝出具打包回执。上一轮提出的真实 AVIF 被拒问题,已在本次精确提交中修好。当前提交拒绝基线能打包的有效两帧 APNG。没有远程发布,也未验证二进制内嵌数据或保留修订回滚。 issue-9405

改动思路 / Approach

presentation package 读取站点目录,对用于清单摘要的同一份内容执行严格解码和公共边界模式。现有模式继续归公共扫描规则所有,站点媒体格式如何分类则属于打包入口。本次范围是本地静态打包候选资产的分类。保留当前生产入口、公共规则与失败行为,定向修补格式。

具体改动 / Changes

  • _scan_public_text 从按文本后缀选择,改成先识别二进制后缀,再按 BOM 或 UTF-8 严格解码。两项 JSON 构建资产继续进入文本扫描。遇到非法编码或 NUL 时,原有 CLI 错误路径返回退出码 2。
  • _collect_site_files 在文件进入清单前执行扫描,保留保留路径、符号链接和摘要判断。新增加的 AVIF 越过文本解码。我用独立生成的 16×16 AVIF 验证当前命令成功,输出与输入字节一致。
  • 测试文件 增加文本后缀、编码、AVIF 和真实 CLI 对照。完整提案两文件,生产代码 +57/-7,测试 +196。对照 #9405,定向测试覆盖文本覆盖与失败关闭两项要求。正常二进制媒体一项中,原 AVIF 缺口关闭。

对主干的风险 / Risks

[P2] 合法的动画 PNG 使用 .apng 文件名时,整个打包被拒绝。 我生成了 16×16、两帧颜色不同的 APNG,并使用独立解码确认两帧有效。同一站点、同一 CLI 参数,基线 a7d72a1c 以退出码 0 输出原字节,当前提交在 _scan_public_text 把图像送进 UTF-8 解码,以退出码 2 拒绝,未生成输出目录。仅把字节完全相同的资产改用 .png 文件名,两端均无损打包。16×16 两帧 APNG 在基线退出 0 且字节一致,新头退出 2 且无发布目录。同字节 .png 和独立的 16×16 AVIF 两端原样复制。请在站点媒体判断中支持这个已验证的 PNG 格式输入,并在 CLI 回归里保留 APNG 无损复制与旁边文本资产被拒两项检查。

  • PASS · 精确基线原有静态站点套件 16 项,当前头完整套件 32 项,标准 premerge 的 6 项直接检查和 2 项所选检查都通过。两端各跑 3 次独立媒体 CLI 对照,AVIF 与 PNG 均成功。
  • FAIL · 当前头拒绝合法 .apng,精确基线接受同一文件。该反例在当前 32 项测试全部通过时仍然成立。
  • UNVERIFIED · 远端 CI 未查询。

我的整体评价 / Verdict

静态站点的文本扫描缺口已由当前提案覆盖,真实 AVIF 的回归也通过复验。合法 APNG 仍会阻断站点生成。把媒体分类限制在打包入口,补上这个有实际输入和对照支持的边界即可,严格的文本拒绝规则应保留。

English verdict: REQUEST_CHANGES at 204fd14. AVIF and identical-byte PNG controls package successfully, but a valid two-frame APNG at its .apng filename now blocks the entire package. The exact base succeeds on the same input.

JasonBuildAI added a commit to JasonBuildAI/loopx that referenced this pull request Nov 25, 2026
…e media

A valid two-frame APNG named `.apng` made the packaging CLI reject the whole
site, because `.apng` is not in the outbound tree deny-list and the strict text
decoder then refused the bytes. The same bytes renamed `.png` packaged on both
sides.

The publisher's own media boundary now covers the browser-decodable containers
the deny-list does not name, rather than one suffix per review round:
`.apng`, `.avif`, `.avifs`, `.heic`, `.heif`, `.jxl`, `.m4v`, `.ogv` and
`.opus` are copied verbatim. `.avif` and `.apng` are verified against real
encoder output; the rest are opaque containers of the same class. Subtitle and
playlist text (`.vtt`, `.m3u8`, `.mpd`) stays outside, so it is still scanned,
and no other asset gains an exemption.

The regression table now carries both real fixtures: a 16x16 AVIF and a 16x16
two-frame APNG, each asserted byte-identical with its manifest digest, each
rejecting a `.csv` credential in the same bundle, and each exercised through the
shipped `loopx presentation package` CLI. At the previous head the APNG cases
fail with `content is not decodable as utf-8` while the AVIF cases pass; at base
the same APNG packages and the credential publishes.

Refs loopx-project#9405, review P2 on loopx-project#9406.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

Fixed at head eef89476e.

_STATIC_MEDIA_SUFFIXES now covers the browser-decodable containers the outbound deny-list omits in one place, instead of one suffix per review round: .apng, .avif, .avifs, .heic, .heif, .jxl, .m4v, .ogv, .opus are copied verbatim. .avif and .apng are verified against real encoder output; the rest are opaque containers of the same class. Subtitle and playlist text (.vtt, .m3u8, .mpd) stays outside, so those formats are still scanned, and nothing else gains an exemption.

Evidence with the real loopx presentation package --execute, same APNG bytes and same flags:

  • base a7d72a1cf: .apng exit 0, 239 bytes identical; the .png rename exit 0; a .csv credential placed beside it publishes (ok: true).
  • 204fd145e: .apng exit 2, public boundary scan failed for assets/spinner.apng: content is not decodable as utf-8, no publish directory; the .png rename exit 0 and byte-identical, which isolates the suffix boundary as you described.
  • eef89476e: .apng exit 0, 239 bytes identical; the .png rename exit 0 and byte-identical; a .csv credential beside either returns ok: false, exit 2 and creates no publish directory. The AVIF control still exits 0 with 331 identical bytes.

The regression is parametrised over both fixtures: test_package_copies_a_real_media_asset_byte_for_byte[avif|apng], test_package_rejects_a_text_asset_next_to_real_media[avif|apng], and test_cli_package_copies_real_media_and_rejects_text_beside_it[avif|apng] through the shipped CLI. Focused suite: 34 passed, 1 deselected; base with the final file 16 failed / 18 passed; 204fd145e 2 failed / 32 passed with the APNG cases reporting content is not decodable as utf-8. loopx canary premerge --from-git-diff --git-diff-base a7d72a1cf: passed, 2 changed files, 0 failures. The PR body now carries the three-revision parity table, the APNG rows and the revised tested revision.

Still disclosed, unchanged: the exemption is by suffix, so text appended to a listed container (.avif, .apng, .png) is copied unreviewed — the declared binary-content out_of_scope.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · reasoning_effort=xhigh

动机 / Motivation

受影响的是使用现有命令打包静态站点的维护者。旧版的八后缀过滤漏掉常见文本,当前提交在负例中能拒绝这些输入。当前提交恢复了有效 APNG 的原字节打包,同时保留文本错误退出和不生成输出的行为。没有远程发布,也未验证二进制内嵌数据或保留修订回滚。 issue-9405

改动思路 / Approach

本地静态打包候选资产的分类。保留当前生产入口、现有文本模式和失败行为,在打包所有者内补齐媒体格式。文件字节交给入口自己的分类和解码,随后生成已有清单和回执。仓库树扫描仍用自己的候选规则。此次没有引入额外目录状态、发布操作或部署步骤。

具体改动 / Changes

  • _scan_public_text 在已有文件字节上使用文本边界模式,BOM 选择编码,默认 UTF-8。解码失败或数据含 NUL 时返回错误。文本覆盖和失败关闭已在本地打包入口验证。 扫描和错误分支
  • _collect_site_files 在添加摘要及复制前调用上述检查。站点的二进制分类继续把 source map 与 tsbuildinfo 留在文本侧,正常二进制媒体按原字节复制。完整差异两文件 +285/-7。 文件集合
  • 上一评审的有效 APNG 与同字节 PNG 对照保持原 SHA-256。两个旧提交的输入相同,旧问题版本只拒绝 .apng,当前提交的真实 CLI 对 APNG、同字节 PNG 和 AVIF 三项均退出 0 且字节一致。 媒体当前分支

对主干的风险 / Risks

未发现阻塞项。上一轮两帧动画 PNG 的原始扩展名会使整个打包退出 2,这次同样的站点得到输出,文件散列与输入完全一致。套件仍验证相邻文本拒绝、UTF-16 BOM、NUL 和不可解码数据并保留无输出的结果。

  • PASS · 源码静态站点 35 项,实际 CLI 的三个独立媒体对照全部通过。
  • PASS · 精确差异和标准 premerge 通过。
  • UNVERIFIED · 远端 CI、实际托管和 APNG、AVIF 以外新增后缀的独立编解码器对照未运行。

我的整体评价 / Verdict

这次解决了此前合规媒体输入被文本检查拒绝的情形,保持合规文本与媒体走已有打包流程。遇到无法判断的候选文本时保留失败回执,帮助维护者定位问题。变化为本地打包检查,无页面渲染改动。

English verdict: APPROVE at eef8947. The same two-frame APNG now packages byte-for-byte, and the scoped text rejection and established media behavior remain covered.

…ame suffix

`loopx presentation package` scanned only the eight suffixes in
`_TEXT_SUFFIXES`. A `.csv`, `.log`, `.yaml`, `.env` or `Dockerfile` in the
bundle was copied into the publish artifact and reported `ok: true` without a
byte being read, and a BOM-marked UTF-16 capture was read as UTF-8 mojibake.

Select text the way the outbound public-safe scanner already does
(`scan_cli.BINARY_SUFFIXES` excludes known binary formats) and decode the
encoding the asset declares, so every text asset in the copied bundle reaches
the existing boundary patterns before publication. The caller's digest read now
supplies the bytes, so each asset is read once.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
…e assets

Certifying a text asset without reading it is a fail-open, and the first
content-based cut skipped NUL-bearing bytes and inherited the outbound
scanner's binary classification for .map and .tsbuildinfo.

Decode the BOM-declared encoding strictly; undecodable bytes and NUL after
decoding now fail publication instead of receiving a receipt. Scan .map and
.tsbuildinfo as text while keeping the other binary suffixes excluded. Cover
BOM-less UTF-16, NUL-bearing UTF-8, .map and .tsbuildinfo with focused tests.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
A valid AVIF asset made the packaging CLI reject the whole site, because
`_scan_public_text` treated every suffix outside the outbound scan's deny-list
as reviewable text and strict-decoded the bytes as UTF-8. That deny-list
classifies a repository tree, not the containers a browser loads, so the
publisher now keeps its own media boundary: `_STATIC_MEDIA_SUFFIXES` is unioned
with the deny-list (minus the two JSON text formats) and its members are copied
verbatim, while every other asset must still be reviewable text.

AVIF is verified end to end: the regression embeds a real 16x16 AVIF from
Pillow's libavif encoder, asserts a byte-identical copy and the manifest digest,
and pins the same bundle rejecting a `.csv` credential through the shipped
`loopx presentation package` CLI. A text payload appended to a listed media
container is still copied unreviewed, which is the declared binary-content
boundary, unchanged from `.png` at base.

Refs loopx-project#9405, review P2 on loopx-project#9406.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
…e media

A valid two-frame APNG named `.apng` made the packaging CLI reject the whole
site, because `.apng` is not in the outbound tree deny-list and the strict text
decoder then refused the bytes. The same bytes renamed `.png` packaged on both
sides.

The publisher's own media boundary now covers the browser-decodable containers
the deny-list does not name, rather than one suffix per review round:
`.apng`, `.avif`, `.avifs`, `.heic`, `.heif`, `.jxl`, `.m4v`, `.ogv` and
`.opus` are copied verbatim. `.avif` and `.apng` are verified against real
encoder output; the rest are opaque containers of the same class. Subtitle and
playlist text (`.vtt`, `.m3u8`, `.mpd`) stays outside, so it is still scanned,
and no other asset gains an exemption.

The regression table now carries both real fixtures: a 16x16 AVIF and a 16x16
two-frame APNG, each asserted byte-identical with its manifest digest, each
rejecting a `.csv` credential in the same bundle, and each exercised through the
shipped `loopx presentation package` CLI. At the previous head the APNG cases
fail with `content is not decodable as utf-8` while the AVIF cases pass; at base
the same APNG packages and the credential publishes.

Refs loopx-project#9405, review P2 on loopx-project#9406.

Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
@JasonBuildAI
JasonBuildAI force-pushed the codex/static-site-text-selection-m0cw branch from eef8947 to 5766efd Compare November 26, 2026 06:07
Signed-off-by: huangruiteng <huangrt01@163.com>

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · GPT-5 · OpenAI · self_reported

动机 / Motivation

使用 loopx presentation package 打包静态站点的维护者和 Agent 会遇到这个问题:旧版只扫描八种文件名后缀,CSV、日志、YAML、env、无后缀文本和 UTF-16 捕获会被复制进发布目录,却得到 ok: true 的公共安全回执。

修复前,同一份含合成凭据的 CSV 可以发布,而把它改成 .txt 才会被拒绝;修复后,除明确的二进制媒体外,所有被复制的资产都要按 BOM 或 UTF-8 完整解码并进入既有边界规则,无法解码或含 NUL 时直接失败。

真实 CLI 的可观察结果是 AVIF、APNG 和同字节 PNG 均原字节复制且 manifest 摘要一致;在相同 bundle 旁加入含合成 token 的 CSV 后返回 exit 2、错误指出具体文件名与规则,并且不创建发布目录。

本 PR 不承诺检查二进制媒体内部的文字,不改变 receipt 或 rollback 状态格式,也不把已知媒体后缀变成任意文本的免检通道;二进制内容与保留 revision 的重新扫描属于明确边界之外。

改动思路 / Approach

候选选择改为复用 outbound scanner 的二进制 deny-list,.map 与 .tsbuildinfo 继续按 JSON 文本检查;静态站点自身只维护浏览器媒体边界。所有规则仍由既有 PUBLIC_BOUNDARY_PATTERNS 执行,没有新增另一个 scanner 或凭据规则。

当前 PR 只修改复制前的文本候选分类和解码/失败策略;manifest、receipt、rollback、CLI 错误码与输出目录事务继续由原 owner 处理。

处理链路由 _collect_site_files 开始:每个文件只读取一次字节,先交给 _scan_public_text,后者跳过明确二进制后缀、识别 BOM、严格解码并运行现有公共边界模式;通过后才进入 manifest 和复制。失败继续抛出 StaticSiteContractError,由既有 CLI 路径返回 exit 2,且 output 目录尚未创建。

flowchart LR
  A[Site file bytes] --> B{Known binary suffix?}
  B -- Yes --> F[Copy unchanged]
  B -- No --> C[BOM or UTF-8 strict decode]
  C -- Decode/NUL error --> X[Exit 2, no output directory]
  C -- Text --> D[Canonical public boundary patterns]
  D -- Hit --> X
  D -- Clean --> E[Manifest digest and copy]
Loading

上图是根据当前 head 源码整理的示意,不是执行收据。最强的反对意见是继续维护一个静态媒体后缀集合,任何写在伪媒体文件名里的文本仍会绕过扫描。这个缺口在 issue 的边界中已明确为二进制内容检查,与本次“文件名不再决定普通文本是否被扫描”的目标正交;修复不应为了关闭假想格式继续扩张文本扫描到所有二进制容器。

具体改动 / Changes

按 #9405 的 revision 2026-11-24T14:26:59Z 核对。all-copied-text-reviewed 要求所有非二进制资产进入既有规则,本 head 以 deny-list 实现;declared-encoding 要求 BOM 声明的文本正确解码,并对不可解码内容失败关闭;binary-controls 要求浏览器媒体继续原样复制;failure-contract 要求 ok:false、exit 2、无输出目录和可定位错误保持不变。

关键代码讲解

  • _BOM_CODECS 按 UTF-32、UTF-8、UTF-16 顺序识别 BOM,避免 UTF-32LE 被较短的 UTF-16 前缀误判。 精确实现
  • _BINARY_ASSET_SUFFIXES 复用 outbound scanner 的 BINARY_SUFFIXES,仅移除 .map 与 .tsbuildinfo 两种 JSON 文本,并合并静态站点自己的媒体集合。 精确实现
  • _scan_public_text 接收调用者已经读取的同一份 bytes,严格解码后拒绝 NUL,再运行既有 PUBLIC_BOUNDARY_PATTERNS;异常消息保留相对文件名和原因。 精确实现
  • _collect_site_files 在生成文件清单前完成扫描,保证失败不会产生半成品 manifest;通过后才计算 SHA-256、size 并复制。 精确实现

变更共 2 个文件、+285/-7:生产实现更新候选选择与解码,测试增加后缀、编码、失败关闭和真实媒体正反路径。未新增持久字段、依赖或前端表面。

对主干的风险 / Risks

最强回归场景是合法站点包含 UTF-16 无 BOM、非 UTF-8 编码或其他没有声明编码的文本,新的严格解码会拒绝整个 bundle。这是 issue 明确选择的失败关闭语义,优于对乱码副本出具成功回执;BOM 文本和普通 UTF-8 均有正例。另一个边界是伪媒体后缀仍不检查内部文本,本 PR 在非目标中公开说明,不把它伪装成已解决。

本轮在真实隔离文件与真实 CLI 上验证:35 项 static-site 测试通过,34 项 architecture import-boundary 测试通过;AVIF、APNG、同字节 PNG 的输入与输出 SHA-256 一致;同 bundle 旁的凭据 CSV 返回 exit 2 且不生成输出。Ruff、diff check、两个 static-site examples 和 standard premerge 均通过。工作区级 loopx check 的全局 registry 有与本 diff 无关的 legacy Goal 诊断,但内嵌 public_boundary_scan 对两个改动文件为 clean。

语义与 CI 对齐

修复复用 BINARY_SUFFIXES 和 canonical boundary patterns,只替换本地候选选择与解码,不新增公共协议词汇。.map、.tsbuildinfo、.csv、.yaml、.env、Dockerfile 和普通无后缀文件均进入文本检查;已知媒体继续原样复制。远端 CI 尚未完成,保持 UNVERIFIED,并由单独的 merge readiness 判断。

我的整体评价 / Verdict

长程效果得到改善:发布命令不再因为文件名不在短 allow-list 中而对真实文本内容出具错误的公共安全回执,失败时也不会留下可通过 manifest 消费的半成品。用户旅程保持原命令和原错误通道,普通站点、真实媒体和 receipt/rollback 无需迁移;视觉检查不适用,因为本 PR 不改变渲染界面。

机制规模与问题匹配:一个现有 scanner 的 deny-list、一个站点媒体白名单和一次字节复用足以完成目标,测试也覆盖了此前两轮由 AVIF/APNG 暴露的兼容性回归。剩余风险是二进制内部文本未扫描和未列出的媒体容器仍可能走文本失败关闭,但不阻断当前 issue 的文本覆盖与明确媒体边界。

English verdict: APPROVE at a603af1. Scan every copied non-binary static-site asset with the existing boundary patterns, decode BOM-declared text strictly, fail closed on unreviewable content, and preserve byte-identical browser media.

@huangruiteng
huangruiteng merged commit c82e961 into loopx-project:main Nov 26, 2026
9 of 12 checks passed
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]: static presentation packaging certifies text assets outside its eight-suffix allow-list without scanning them

3 participants