Repository navigation
Conversation
Add a `text` parser (one paragraph per line, 1-based line numbers, comment-syntax family in metadata) so the gateway can read the files a Code LLM actually completes: source, config and agent rule files. The format registry gains `FormatHandler.basenames` because `.cursorrules` has no extension to key on, and extension keys are normalised on registration: a handler registered with ".py" used to land in an unreachable slot next to the dotless "py" keys the other parsers use.
Closes the inference-time context-injection channel of arXiv:2610.05139: an unsafe objective written as an ordinary comment (`# TODO:` / `# INSTRUCTION:` / `# TASK:`) inside untrusted context is indistinguishable from the developer's own instruction. A hit needs a directive frame (marker / addressed / imperative / authority / safety-negation) AND an insecure objective from the paper's ten weakness classes, plus prompt injection aimed at the assistant itself. Descriptive prose that merely names a sink, prohibitions and fix-notes are not reported: measured on the bundled corpus 32/32 attack payloads, 0/46 benign comments, 0 findings over 4,643 comment lines of third-party source.
A directive in a comment is not concealment -- a human reads it too -- but the model complies with it, so it earns a content-dimension weight and a cap below the dangerous threshold when it is HIGH or CRITICAL.
Stripping invisible characters does not touch a visible comment payload, so "quarantine" would have been a no-op for code files: the model would read the directive verbatim out of the substitute. `defuse_comment_line()` replaces the instruction with an inert comment that keeps the language's syntax and the line's indentation, and records the removal in `SanitizeResult.removed`.
Source/config extensions and agent rule files (AGENTS.md, CLAUDE.md, GEMINI.md, .cursorrules, .windsurfrules, copilot-instructions.md) are now enforced by the same gate that guards documents; `hook doctor` reports the enforced set. Also corrects the block message: a comment directive is visible to a human reader, so "the file's hidden content never reached the model" was the wrong claim for this finding type -- it now says the file was not sent to the model.
…aviour Attack corpus: the paper's ten weakness classes x three framings plus agent-directed injection (two payloads verbatim from the paper), a 46-comment benign corpus across five comment syntax families, false-positive controls (prose, prohibition, fix-note, marker-only weak class), parser/registry dispatch, defusing, hook enforcement and CLI e2e. Test count 183 -> 320.
Design notes, the measured table and the honest boundaries (the paper's 700-item corpus was not released; a pattern detector is incomplete by construction; DET-008 reads instructions, not vulnerable code). README/README.ja document the new surface and the badge moves to 320 tests.
Sync with GitHub main (PR #1, fix/dev-review-findings) so dev can be pushed without losing upstream's hardening. Conflict resolutions: - hook gate: upstream's sniff guard for unenforced extensions is combined with this branch's rule-file name bypass, so `payload.txt` holding a docx is enforced again while AGENTS.md/.cursorrules stay enforced by name. The sniffed-kind set is now the named constant DOCUMENT_KINDS. - text parser: `.md`/`.txt`/`.rst`/`.adoc` are no longer registered as extensions. Registering them shadowed the registry's content sniffing and would have reopened the misleading-extension hole; prose stays in the sniff path, rule files are matched by name. New tests pin both the registry behaviour (a docx named payload.txt sniffs to docx) and the hook verdict (deny). - README/README.ja: merged test count (330 collected after the merge). Verified on the merged tree: 330 tests pass, ruff and mypy clean, and evil.txt -> sniffed docx -> deny (upstream's regression test, now green again).
… fix The branch now builds on main's PR #1, so the changelog states what came in with it (fail-closed on incomplete scans, hook/cache hardening, visible-content preservation) and the 0.3.0 entry notes the extension/sniff precedence fix that the merge forced: registering prose extensions shadowed sniffing, and the coverage doc no longer claims a plain .md is parseable on demand.
sscodeai
added a commit
that referenced
this pull request
Oct 11, 2026
…nts and threat model Follow-up to #2. README/README.ja: 7 -> 8 detectors (the pipeline diagram and the list-detectors example), M0 row clarified as "6 document formats". docs/plan: the enforced-Read cost line names both paths. SECURITY.md: directive bypass (code comment or rule file) is in scope. Docs-only, no behaviour change.
sscodeai
added a commit
that referenced
this pull request
Oct 12, 2026
… covers code and rule files Second follow-up to #2. README headlines, pyproject/CLI/module descriptions and the GitHub repository description now name the real input surface (documents, source files, agent rule files); README.ja detector count fixed; list-detectors e2e pins DET-008. Docs/metadata plus one test assertion — no behaviour change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the inference-time context-injection channel from arXiv:2610.05139 — Hidden in the Comments: A Context-Injection Attack Surface in Code LLMs (Munir, Quinzan & Roberts, Oxford).
An unsafe objective written as an ordinary comment (
# TODO:/# INSTRUCTION:/# TASK:) inside untrusted context is indistinguishable from the developer's own instruction — the marker space is shared. The paper measures 77.4–92.3% of completions containing a medium-or-higher weakness (benign condition: 1.7–5.1%), with the strongest post-generation screen still missing ~⅓. aiitg now answers upstream of generation: the directive never reaches the model intact.What changed
textparser — source/config files plus agent rule files (AGENTS.md,CLAUDE.md,GEMINI.md,.cursorrules,.windsurfrules,copilot-instructions.md) read as one paragraph per line with a 1-based line number. The format registry gained basename dispatch (FormatHandler.basenames) and extension-key normalisation (a dotted registration can no longer create an unreachable handler).comment_directive— a hit needs a directive frame (marker / addressed-to-the-model / imperative opener / authority claim / safety negation) and an insecure objective from the paper's ten weakness classes, plus prompt injection aimed at the assistant itself. Descriptive prose that merely names a sink, prohibitions ("must never callchild_process") and fix-notes are not reported.SanitizeResult.removed.deny (POL-001), MEDIUM →quarantinewith a defused substitute.aiitg hook doctorreports the enforced set.dangerousthreshold: an instruction the model would follow may never read assafe.Verification
make test),ruffandmypyclean.aiitg scan oracle.py→ exit 1DET-008 CRITICAL @ line 10; hook →deny (POL-001); quarantine → the substitute no longer contains the directive;aiitg hook doctor→63 extensions + 6 rule-file names.mainkeeps PR Fix/dev review findings #1's hardening:evil.txtholding a docx is sniffed todocxand denied again (DOCUMENT_KINDS), pinned bytests/unit/test_text_parser.pyand the existing regression test.Honest boundaries
docs/comment-directive-coverage.md.Notes
a53c1ba(frommain) resolved: the hook gate combines the sniff guard with the rule-file bypass, and prose extensions (.md/.txt) are no longer registered so a document wearing a misleading extension stays in the sniff path.0.3.0, plus a0.2.1section recording the fixes this branch now builds on.feat(parsers)→feat(detectors)→feat(trust)→feat(sanitize)→feat(hooks)→test→docs).