Skip to content

feat(audit): detect whitespace padding that hides instructions - #755

Merged
runkids merged 2 commits into
runkids:mainfrom
salmonumbrella:feat/audit-whitespace-padding
Nov 5, 2026
Merged

runkids merged 2 commits into
runkids:mainfrom
salmonumbrella:feat/audit-whitespace-padding

Conversation

@salmonumbrella

@salmonumbrella salmonumbrella commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

Feature implementing one item from the #746 list. It has no approved label yet; happy to close it if you'd rather not take it.

Linked Issue

Implements item 17 of proposal PR #746.

What changed

Add whitespace-padding to the static audit analyzer with four forms:

  • 20–39 consecutive eligible blank lines at MEDIUM and 40+ at HIGH when nonblank text follows. Nonblank fenced-code, indented-code and table lines also reveal preceding padding outside their blocks. Trailing blank runs do not trigger this form.
  • 80+ leading horizontal Unicode White_Space characters before text at MEDIUM. Interior column alignment and trailing whitespace do not trigger this form.
  • More than 4096 eligible UTF-8 bytes with at least 95% whitespace bytes at MEDIUM.
  • 100+ identical consecutive eligible nonblank lines immediately followed by different eligible nonblank text at MEDIUM. EOF-only repeated runs do not trigger this form.

In Markdown .md files, exempt parsed fenced/indented code and table rows from padding accounting. Whitespace inside those blocks stays exempt; nonblank code/table text still triggers a preceding external blank run. An unclosed CommonMark fence exempts its contents through EOF. Fences found only by the HTML-stripped security reparse do not grant exemptions. Density/repetition can flag generated data, including JSON and lookup tables.

Keep one finding per qualifying blank, repeated, or adjacent leading-horizontal run. Preserve original LF-based source locations across CRLF, CR, Unicode separators, vertical tab and form feed. Count CRLF once; density uses original eligible UTF-8 byte counts.

Run the detector through supported content, file and skill scans, including the optimized walker. Honor static-analyzer selection and global/project disable, severity and confidence overlays by ID or pattern. Explicit severity overrides every form; leave regex and exclude unset for this file-level detector.

Include the rule in existing JSON/Markdown/SARIF reporting and obfuscation risk scoring. The new HIGH-capable finding can change blocking and exit behavior at a HIGH threshold, including strict-profile gates. Update English guidance, all four translated catalogs/guides and the built-in skill reference; include a CLI E2E runbook. No behavior outside item 17 is retained.

Accepted padding findings now include the finding form and detector evidence in their acceptance key. A changed padded payload or a new padded run in the same file requires fresh approval; unchanged blank-run findings remain accepted across line shifts. Identical occurrences have separate acceptance keys, so previously accepted padding findings require fresh approval. Density keys use all eligible file content.

Why

Padding can move instructions out of view during human review. Structural checks identify these runs without executing content. Leading-only horizontal accounting and parsed Markdown exemptions keep the reproduced alignment and code-example cases clean. Exempt text must still reveal padding before the block, or a Markdown wrapper can suppress the warning. Findings indicate hidden-content risk, not proof of malicious intent.

Checks

The audit and CLI package suites passed on isolated Linux, including regressions for grouped horizontal padding, colliding same-line findings, and duplicate acceptance. Website typecheck and the all-locale build passed. CI verifies other platforms.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it (AI-assisted: built with Codex; the full diff and two fix rounds were reviewed independently, with each finding reproduced against a built binary, before opening)
  • Tests included and passing — focused audit and CLI packages passed
  • No unrelated changes in the diff — all retained behavior changes are listed above
  • Scope is focused — one concern per PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T04:23:13.515401Z 10ca389 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a66ad636d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/audit/whitespace_padding.go Outdated
}
findings = append(findings, Finding{Severity: severity, Pattern: ruleWhitespacePadding,
Message: fmt.Sprintf("%s: %s", configured.Message, detail), File: filename,
Line: lines[index].sourceLine, Snippet: strings.TrimSpace(lines[index].text),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve payload identity in padding acceptance keys

After a user accepts a benign 40-blank-line finding with --force at a HIGH threshold, a later update can introduce a different padded instruction elsewhere in the same SKILL.md without blocking again. Blank-run findings—and density findings anchored on blank lines—always receive an empty snippet here, while AcceptKey (internal/audit/accept.go:13–18) ignores both the line and message. Consequently, ApplyAcceptedFindings acknowledges these new findings and the update gate skips them (internal/install/install_audit.go:363–365), rather than remembering only the “exact findings” described in website/docs/reference/commands/update.md:324–330. Include the padding form and relevant padded content in the acceptance identity so changed payloads require fresh approval.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 10ca389. Whitespace-padding acceptance keys now include the finding form and a digest of relevant evidence; density findings bind to all eligible file content. Added a regression for a newly added padded run in the same SKILL.md and changed-payload coverage across detector forms. Focused audit, install, and update integration tests plus vet passed.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 10ca38957e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@runkids

runkids commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks for this, and for the care around acceptance keys and CRLF line locations. I read through the diff and have a few points.

Correctness

  • internal/audit/whitespace_padding.go:192: the leading-horizontal form emits one finding per line, while the blank and repeated forms emit one per run. A text file with 200 lines indented 80+ spaces produces 200 MEDIUM findings, and the risk score saturates at 100. Grouping consecutive lines into one finding would match the other forms.
  • Two padding findings on the same line can share a fingerprint. ComputeFingerprint (dedupe.go:24) uses rule, pattern, analyzer, file, line and snippet, but not the padding form. For example, 40+ blank lines at the top of a file that is also mostly whitespace give a blank-run finding and a density finding on line 1, both with an empty snippet, and DeduplicateGlobal drops one of them. The PR handles this collision for AcceptKey but not for the fingerprint.
  • Possibly: if an update adds a second run with the same length and the same following paragraph, it gets the same acceptance key and is treated as already accepted. That's narrower than "a new padded run requires fresh approval".

Docs

  • website/docs/understand/audit-engine.md:189 and the four translated copies still use the old wording about re-acceptance ("changed rule, file, or matched text"), although update.md, audit.md and audit-engine.md:47 were updated.
  • The website build didn't complete, so the new {#whitespace-padding} anchors haven't been checked by the build.

Cleanup (judgement call)

  • paddingExemptions parses the Markdown again (markdownCodeBlocks plus a second goldmark pass with tables), on top of the parse scanFileUnifiedMarkdown already did, for any .md file over roughly 25 KB.

If anything here looks wrong to you, please say so. Happy to discuss.

@salmonumbrella
salmonumbrella force-pushed the feat/audit-whitespace-padding branch from 10ca389 to 731c73a Compare November 4, 2026 16:40
@salmonumbrella

salmonumbrella commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated in 731c73a:

  • Adjacent horizontally padded lines now produce one finding per run.
  • Fingerprints include detector evidence, so same-line blank-run and density findings remain distinct. Identical runs get separate occurrence keys, so adding another requires acceptance; existing accepted padding findings need fresh acceptance after this change.
  • Updated the acceptance and grouping guidance in English and all four translations, including the stale accepted-findings references.
  • Reused the existing Markdown code-block scan for ordinary LF input; inputs with other visual separators still use normalized parsing for exemptions.

The reported regressions failed before the fixes. The audit and CLI package suites, website typecheck, and all-locale build pass on isolated Linux. Docker/devcontainer was unavailable locally; CI covers other platforms.

CI passed unit, Linux integration, Windows, security, and offline sandbox checks. The macOS build and integration jobs were cancelled before any steps started while waiting for runners.

@runkids runkids left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks. Detection, line numbering and acceptance keys look right. Existing fingerprints don't change, because acceptanceContext is only appended when it is set. Two small points:

1. The reparse guard is much looser than the comment suggests (internal/audit/whitespace_padding.go:141). whitespace*100 <= paddingDensityBytes*paddingDensityPercent compares the file's total whitespace against a fixed ~3.9 KB, so almost every .md file over about 15–20 KB parses Markdown again. A CRLF file also clears blocks and pays for one more parse. "Most files have too little whitespace" doesn't hold for ordinary docs. A guard based on the whitespace share, or reusing the blocks already parsed, would keep large skills cheap.

2. A custom regex on this ID is silently ignored (patterns.go:135). A full overlay with id: whitespace-padding and a regex replaces the rule, but matchesLine always returns false for this ID. The built-in detector keeps running and the user gets no warning. Rejecting regex/exclude for this ID at load time, or warning about them, would make the documented "leave these unset" enforceable. This is low priority, since only a hand-edited rules file can reach it.

Long blank spans and repeated filler can move meaningful instructions out
of view during skill review. Add four padding signals under the static
analyzer with Markdown exemptions and original-source line mapping.

Reuse rule overlays so global and project toggles and severity/confidence
overrides also govern this file-level detector. Cover threshold boundaries,
benign examples, optimized scans, reports and CLI rule controls.

Implements item 17 of runkids#746.

Co-Authored-By: GPT-6.1 Sol <[email protected]>
@salmonumbrella
salmonumbrella force-pushed the feat/audit-whitespace-padding branch from 731c73a to c402ae1 Compare November 5, 2026 02:59
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

Updated in c402ae1:

  • Added a conservative syntax guard: ordinary prose and inline markup skip the exemption parse, while possible fenced or indented code, lists, block quotes and tables still go through it. This also avoids the extra CRLF parse when there are no possible exemptions.
  • Reject regex and exclude for whitespace-padding when loading rules, including partial overlays, and documented that behavior in all five locales.

The guard and rule-loading regressions failed before the fix. The full audit package and documentation router check pass on isolated Linux. Docker/devcontainer was unavailable; I didn't rerun the website build for these text changes.

@runkids runkids left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the update. Both points are resolved in c402ae1:

  • paddingMayHaveExemptions covers every case paddingExemptions can exempt, so ordinary prose skips the second parse without losing an exemption.
  • regex and exclude on whitespace-padding are now rejected in parseRulesYAML, which covers both the rules file and the dashboard, and the docs say so in all five locales.

internal/audit passes in the devcontainer, and CI is green. Nothing more from me on this round.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

Thanks for checking. Glad both points are resolved.

@runkids runkids left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approving; all review points are resolved and CI is green on the updated branch.

@runkids
runkids merged commit 9b58248 into runkids:main Nov 5, 2026
10 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.

2 participants