Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion .github/workflows/qwen-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3325,6 +3325,79 @@ jobs:
printf '%s%s\n' "$esc" "$truncated"
printf '</code></pre>\n\n</details>\n\n'
}
# Render report.md as MARKDOWN instead of an escaped <pre> dump.
# The report is a curated bilingual document (tables, nested
# <details>, headings); the pre/code embedding displayed it as a
# wall of raw source (#8140's comment was the exhibit). Rendering
# keeps the same security floor via four line-independent
# guarantees:
# 1. every & < > is escaped, then ONLY the structural tags the
# report legitimately uses are un-escaped back to live tags
# (details/summary/pre/code/br) — no other tag can form, so
# <img>/<script>/onerror never render;
# 2. the comment-open token is broken (<!-- becomes an escaped
# no-op, the autofix-proven neutralizer), so no forged
# qwen-triage:* marker can form anywhere in the body;
# 3. @ becomes &#64; — renders identically, never fires a
# mention;
# 4. unbalanced <details> opens are counted and closed at the
# end, so a malformed report cannot swallow the footer.
# An OVERSIZED report falls back to emit_block wholesale (cut
# markdown dangles fences/folds), as does any sanitizer failure.
emit_report() {
local file="$1" max="$2"
[ -n "$file" ] && [ -f "$file" ] || return 0
if [ "$(wc -c < "$file")" -gt "$max" ]; then
emit_block 'Verification report (report.md, truncated)' "$file" "$max"
return 0
fi
local san_file="${TMPDIR:-/tmp}/verify-report-$$"
if ! (
set -o pipefail
tr -d '\000' < "$file" |
sed -E -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' \
-e 's/&lt;(\/{0,1})(details|summary|pre|code|br)&gt;/<\1\2>/g' \
-e 's/&lt;!--/\&lt;!\\-\\-/g' \
-e 's/@/\&#64;/g' > "$san_file"
); then
rm -f "$san_file"
emit_block 'Verification report (report.md)' "$file" "$max"
return 0
fi
if [ "$(wc -c < "$san_file")" -gt "$max" ]; then
rm -f "$san_file"
emit_block 'Verification report (report.md, truncated)' "$file" "$max"
return 0
fi
local opens closes
# `|| true` inside the substitution: grep exits 1 on zero
# matches, and under the step's pipefail that would kill the
# whole composer for a report with no folds at all.
opens="$(grep -o '<details>' "$san_file" | wc -l || true)"
closes="$(grep -o '</details>' "$san_file" | wc -l || true)"
# The balancing loop below appends `opens - closes` closers
# (11 bytes each) AFTER this size gate has already passed, so a
# report dense in unbalanced <details> opens could be pushed past
# the cap — and past GitHub's 65,536-char comment limit — by the
# closers alone. Budget for that overhead before committing to
# the markdown path; otherwise fall back to the capped pre dump.
local deficit=$(( opens - closes ))
if [ "$deficit" -gt 0 ] && \
[ $(( $(wc -c < "$san_file") + deficit * 11 + 30 )) -gt "$max" ]; then
rm -f "$san_file"
emit_block 'Verification report (report.md, truncated)' "$file" "$max"
return 0
fi
printf '### Verification report\n\n'
cat "$san_file"
rm -f "$san_file"
printf '\n'
while [ "$opens" -gt "$closes" ]; do
printf '</details>\n'
opens=$(( opens - 1 ))
done
printf '\n'
}

# Host the agent's evidence images (if any) on a per-PR branch
# (pr-assets/<N>-verify, matching hand-run convention) and build
Expand Down Expand Up @@ -3695,7 +3768,7 @@ jobs:
if [ -n "${MISSING_REPORT_NOTE:-}" ]; then
printf '%s\n\n' "$MISSING_REPORT_NOTE"
fi
emit_block 'Verification report (report.md)' "$REPORT" 45000
emit_report "$REPORT" 45000
if [ -n "$EVIDENCE_SECTION" ]; then
printf '%s' "$EVIDENCE_SECTION"
fi
Expand Down
142 changes: 140 additions & 2 deletions scripts/tests/qwen-triage-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,142 @@ describe('qwen-triage verify hardening', () => {
// tests do not cover it. Execute it: hostile content must stay literal,
// and the escaped body must land under GitHub's 65,536-char comment cap
// (the cap is applied AFTER escaping for exactly this reason).
it('renders report.md as sanitized markdown with an escaped-pre fallback', () => {

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.

Declined — the premise does not hold. This test is reachable in CI: ci.yml's "Run tests and generate reports" step runs the root npm run test:ci, which chains && npm run test:scripts (package.json), and that runs vitest run --config ./scripts/tests/vitest.config.ts whose include glob covers scripts/tests/**/*.test.{js,ts}. So this file gates every full PR. Verified by running it through that exact config — 108/108 passed. Adding a separate CI job would duplicate an existing gate, so no change was made.

中文说明

拒绝——前提不成立。该测试在 CI 中可达:ci.yml 的 "Run tests and generate reports" 步骤运行根级 npm run test:ci,其后链式调用 && npm run test:scripts(package.json),该脚本运行 vitest run --config ./scripts/tests/vitest.config.ts,其 include glob 覆盖 scripts/tests/**/*.test.{js,ts}。因此本文件对每个 full PR 构成闸门。已通过该配置实际运行验证——108/108 通过。新增独立 CI 作业会重复已有闸门,故不做更改。

// #8140's verify comment displayed the whole curated bilingual report
// as a wall of raw markdown source inside <pre><code> — tables, bold
// markers, and literal <details> tags all rendered as text. report.md
// now renders as MARKDOWN, holding the same security floor: only
// structural tags un-escape, the comment-open token is broken so no
// forged qwen-triage:* marker can form in the RAW body the upsert
// greps, @ cannot fire mentions, and unbalanced folds are closed so a
// malformed report cannot swallow the footer. Oversized reports fall
// back to the escaped <pre> wholesale (cut markdown dangles fences).
const publishStep = step('Post verification report comment');
const body = publishStep.match(/run: \|-\n([\s\S]*)$/)?.[1];
const script = body.replace(/^ {10}/gm, '');
const helpers = script.slice(
script.indexOf('html_escape()'),
script.indexOf('EVIDENCE_SECTION='),
);
expect(helpers).toContain('emit_report()');
// The report call site uses the rendering path; the tmux lane keeps
// its escaped embedding.
expect(script).toContain('emit_report "$REPORT" 45000');
expect(step('Post tmux result comment')).not.toContain('emit_report');

const dir = mkdtempSync(join(tmpdir(), 'verify-render-'));
try {
const report = join(dir, 'report.md');
writeFileSync(
report,
[
'# Deep Verification — `merge-ready`',
'',
'**Verdict:** pass && <T<U>> ok',
'',
'| scenario | match |',
'| --- | --- |',
'| success | ✅ |',
'',
'<details>',
'<summary>中文摘要</summary>',
'',
'- 结论:通过 @everyone <img src=x onerror=alert(1)>',
'- marker: <!-- qwen-triage:verify -->',
'',
'</details>',
'',
'<details>',
'<summary>unclosed fold</summary>',
'tail',
'',
].join('\n'),
);
const emit = (file, max) => {
const proc = spawnSync(
'bash',
['-c', `${helpers}\nemit_report "$1" ${max}`, '_', file],
{ encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 },
);
expect(proc.status).toBe(0);
return proc.stdout;
};

const out = emit(report, 45000);
// Markdown structure survives (renders), instead of an escaped dump.
expect(out).toContain('### Verification report');
expect(out).toContain('| scenario | match |');
expect(out).toContain('**Verdict:**');
expect(out).toContain('<details>');
expect(out).toContain('<summary>中文摘要</summary>');
expect(out).not.toContain('<pre><code>');
// Security floor: no live marker in the RAW body, no mention, no
// non-allowlisted tag, entities escaped.
expect(out).not.toContain('<!-- qwen-triage');
expect(out).not.toContain('@everyone');
expect(out).not.toContain('<img');
expect(out).toContain('&#64;everyone');
expect(out).toContain('&amp;&amp;');
expect(out).toContain('&lt;T&lt;U&gt;&gt;');
expect(out.match(/<(?!\/?(details|summary|pre|code|br)\b)[a-z]/g)).toBe(
null,
);
// The unclosed fold is balanced so the footer cannot be swallowed.
const opens = out.split('<details>').length - 1;
const closes = out.split('</details>').length - 1;
expect(opens).toBe(closes);

// Oversize → wholesale fallback to the escaped pre embedding.
const big = join(dir, 'big.md');
writeFileSync(big, `x${'y'.repeat(46000)}`);
const fb = emit(big, 45000);
expect(fb).toContain('<pre><code>');
expect(fb).toContain('Verification report (report.md, truncated)');

// Inflation: raw under the cap but sanitized over it (& -> &amp;).
const dense = join(dir, 'dense.md');
writeFileSync(dense, '&'.repeat(44000));
const inflated = emit(dense, 45000);
expect(inflated).toContain('<pre><code>');
expect(inflated).toContain('Verification report (report.md, truncated)');

// The fold-counting greps carry `|| true` because grep exits 1 on zero
// matches, which under the step's real `set -euo pipefail` would abort
// the whole composer for a fold-free report. `emit` spawns without
// pipefail, so exercise that path explicitly: a zero-fold report under
// pipefail must still exit 0 and render.
const nofolds = join(dir, 'nofolds.md');
writeFileSync(nofolds, '## heading\nbody text\n');
const pf = spawnSync(
'bash',
[
'-c',
`set -o pipefail\n${helpers}\nemit_report "$1" 45000`,
'_',
nofolds,
],
{ encoding: 'utf8' },
);
expect(pf.status).toBe(0);
expect(pf.stdout).toContain('### Verification report');
expect(pf.stdout).toContain('## heading');

// The balancing loop appends `opens - closes` closers AFTER the size
// gate passes, so a report dense in unbalanced <details> opens must
// fall back to the capped pre dump once the closer overhead would
// exceed the budget — rather than shipping a section over the cap.
// 100 opens: raw ~1000 B and sanitized ~1000 B both clear max=2000,
// but 1000 + 100*11 + 30 > 2000 forces the fallback.
const folds = join(dir, 'folds.md');
writeFileSync(folds, '<details>\n'.repeat(100));
const over = emit(folds, 2000);
expect(over).toContain('<pre><code>');
expect(over).toContain('Verification report (report.md, truncated)');
} finally {
rmSync(dir, { recursive: true, force: true });
}
});

it('escapes and size-caps the verify report body', () => {
const publishStep = step('Post verification report comment');
const body = publishStep.match(/run: \|-\n([\s\S]*)$/)?.[1];
Expand Down Expand Up @@ -2663,10 +2799,12 @@ describe('qwen-triage verify publish fidelity', () => {
expect(assertZh).toBeGreaterThan(details);
expect(assertZh).toBeLessThan(detailsEnd);
}
// The report block stays outside the Chinese fold.
expect(body.indexOf('Verification report (report.md)')).toBeGreaterThan(
// The report section stays outside the Chinese fold — now rendered
// as markdown under its own heading, not an escaped <pre> dump.
expect(body.indexOf('### Verification report')).toBeGreaterThan(
detailsEnd,
);
expect(body).toContain('## real report');
} finally {
rmSync(dir, { recursive: true, force: true });
}
Expand Down
Loading