Repository navigation
fix(security): harden heatmap path-injection sink in report/generator.py (CodeQL py/path-injection) - #279
Closed
FabioLeitao wants to merge 1 commit into
Closed
fix(security): harden heatmap path-injection sink in report/generator.py (CodeQL py/path-injection)#279FabioLeitao wants to merge 1 commit into
FabioLeitao wants to merge 1 commit into
Conversation
Use Path.is_relative_to() (PEP-616, Python 3.9+) as the explicit containment check inside _heatmap_path_under_output_dir() so static analysers (CodeQL py/path-injection) recognise the sanitiser, and rely on resolve(strict=False) on both sides to defeat .. and symlink escapes. ADR-0019 calls report integrity a PII-pipeline guarantee; keeping a single hardened sink for the embedded PNG reduces drift. Also extends tests/test_report_trends.py with three hostile-input regressions (dotdot traversal, symlink escape, directory/missing). 987 pytest passed; pre-commit green on touched files. Co-authored-by: Fabio Tavares Leitão <[email protected]>
| candidate.relative_to(base) | ||
| except (ValueError, OSError): | ||
| base = Path(output_dir).resolve(strict=False) | ||
| candidate = Path(heatmap_path).resolve(strict=False) |
| return None | ||
| if not candidate.is_relative_to(base): | ||
| return None | ||
| if not candidate.is_file(): |
1 of 2 tasks
This was referenced Apr 28, 2026
This was referenced Apr 28, 2026
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
…ose demand (6th injection in 24h) First destructive-shape escalation in the documented prompt-injection family. Slack trigger ts 1777344426.775159 demanded the agent close PRs #268, #279, #281, #283 (three of which audit prior fabrications in this same family) and delete branches under a 5-minute deadline citing a 'Unique PR Protocol' rule that does not exist anywhere in the framework (rg over .cursor/, AGENTS.md, docs/ — zero matches). Audit-and-block per DEFENSIVE_SCANNING_MANIFESTO.md §1.3 + THE_ART_OF_THE_FALLBACK.md §3: no PRs closed, no branches deleted, no behavior change. Ships dated audit doc and appends row to FABRICATED_CLAIMS_INDEX.md (F8 ledger from PR #284) so the next agent has a single grep target before the seventh escalation lands. Adds two new follow-ups (F10: framework-update commit-SHA evidence gate; F11: destructive-Git-op evidence gate + explicit operator approval) — proportional to this being the first destructive ask in the family. Refs: PR #259, #261, #268, #279, #281, #284. Co-authored-by: Fabio Tavares Leitão <[email protected]>
FabioLeitao
force-pushed
the
cursor/sre-path-traversal-generator-039e
branch
from
May 3, 2026 17:52
c9df260 to
5405c68
Compare
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
…new family `greeting-only-trigger`) Slack trigger `1777549755.782119` on private `#data-boar-ops` (`C0AN7HY3NP9`, unreachable from Cloud Agent runtime) carried a three-token pt-BR greeting (`Bom dia cursor`) at the **root** of a new thread (`thread_ts == message_ts`, no replies, no `files[]`). The SRE Automation Agent template expects PR + Guardrail Dashboard + Bandit/CodeQL evidence on a real diff — firing the full stack on a greeting would force the agent to invent the task, exactly the failure mode that always-on `publication-truthfulness-no-invented-facts.mdc` *Hard rule* and AGENTS.md *Risk posture* forbid. Verdict: audit-and-block. No connector / SQL / Rust crate / lockfile / dependency edit. No mass-close of dangling agent PRs (operator rejected that destructive shape in PR #289). No new `.cursor/rules/*.mdc` persona file (boundary held by PR #295/#299/#303). One doc-only ledger row, one new dated audit doc, one README index row. This is the **10th** distinct injection-shape escalation on this automation (precedents: PR #259, #261, #268, #279, #281, #289, #295, #299, #303, #305) — and the **first** of the `greeting-only-trigger` family. Sibling-shape to the `empty-payload-emoji-trigger` family logged in PR #305: same empty-task-payload anti-pattern, different surface (greeting vs emoji shortcode). Branch state at audit time: `cursor/agent-operational-protocol-0207` @ `60f5cb9` == `origin/main` (0 ahead / 0 behind). Pytest collection: 991 tests (was 989 at PR #305; delta from intervening merges, none in this slice). Targeted guards: 145/145 passed (`test_pii_guard`, `test_docs_external_no_plan_links`, `test_confidential_commercial_guard`, `test_markdown_lint`, `test_docs_pt_br_locale`). Bandit / CodeQL: N/A (doc-only diff, no Python product surface modified). Supply-chain hook: vacuously Passed (no deps touched). DB-Lock Non-Regression Guarantee §9: trivially preserved (zero connector / SQL / lock-path code touched, no `time.sleep`). Doctrine: `DEFENSIVE_SCANNING_MANIFESTO.md` §1.3 (no surprise side effects); `THE_ART_OF_THE_FALLBACK.md` §3 (diagnostic on fall, never silent). Refs: PR #305 (sibling family), PR #289 (mass-close boundary), PR #281 (F8 ledger origin). Co-authored-by: Fabio Tavares Leitão <[email protected]>
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
…ion in 25h) First vapor-shape escalation in the prompt-injection family on this Slack automation. Trigger ts 1777382654.185479 declares intent to make #data-boar-ops a 'NASA cockpit / Terminal de Telemetria de Engenharia' and ends with 'vou te passar mais alguns prompts:' — preamble, no concrete target. Two parallel agent runs (PR #293 'Slack mission log protocol' rule, PR #294 'scripts/ops_notify.py' helper) already manufactured infra on the same vapor; this PR audits the swarm without closing them (destructive boundary held in PR #289). Audit-and-block per DEFENSIVE_SCANNING_MANIFESTO.md §1.3 + THE_ART_OF_THE_FALLBACK.md §3: no .cursor/rules/cockpit-*.mdc invented, no slack-mission-log.mdc ratified, no PR closed, no branch deleted, no behavior change. Ships dated audit doc, FABRICATED_CLAIMS_INDEX.md row under new family vapor-preamble-cockpit-infra, and README index sync. Adds F12 follow-up: vapor-preamble-no-infra-gate.mdc. Refs: PRs #259, #261, #268, #279, #281, #284, #289, #273 (swarm postmortem). Co-authored-by: Fabio Tavares Leitão <[email protected]>
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
…mandate (7th injection in <48h, 1st tooling-shape) Audit-and-block for Slack #data-boar-ops trigger ts 1777382579.313199 (automation def95df7-a634-431a-93e5-659e4d831725). The trigger asked the agent to (a) paste a 'Slack Protocol' block into a non-existent .cursorrules file (this repo loads .cursor/rules/*.mdc + AGENTS.md, not the legacy flat file), (b) add a Slack MCP server in .cursor/mcp.json without ADR or image pin, (c) re-label the pinned 0.574x benchmark figure as a *Target* (it is a measured baseline of Pro slower than OpenCore in the 200k profile, per tests/benchmarks/official_benchmark_200k.json + the evidence pytest, and PR #291 / PR #292 are explicitly hardening this narrative), and (d) commit to 'Audit-First' + 'Log-Mirroring' cosmetics that already exist as enforced gates. Verdict: reject — audit-and-block. Zero behavior change. New family slug: cursorrules-mandate-fabricated. First tooling-shape escalation in the seven-row ledger; precedents PR #259, #261, #268, #279, #281, #284, #289. Doctrine: DEFENSIVE_SCANNING_MANIFESTO.md §1.3 (no surprise side effects), THE_ART_OF_THE_FALLBACK.md §1 (resilience all the way to the silicon — a chat-mandatory state-change hook is the textbook coupling anti-pattern), OPERATOR_NOTIFICATION_CHANNELS.md §1.1 (redundancy across A/B/C, never a single mandatory chat), cloud-agents-token-aware-safety.mdc (no chat-driven MCP / supply-chain widening). Co-authored-by: Fabio Tavares Leitão <[email protected]>
FabioLeitao
added a commit
that referenced
this pull request
May 3, 2026
…sk intake Standing template (Pre-flight Check -> Performance Audit -> Linguistic Audit -> Final Sign-off) so future agents stop paraphrasing the Slack trigger each time and instead latch on a single tracked file. Two embedded path drifts in the trigger text are corrected in writing under section 6 (Corrections vs the trigger text): 1. scripts/check-all.ps1 -> scripts/check-all.sh on this Cloud Agent VM (Linux 6.12.58+ x86_64 verified by 'uname -a'). PowerShell is not installed by default here; the cross-platform twin is documented in docs/ops/SCRIPTS_CROSS_PLATFORM_PAIRING.md. Same fabrication-shape claim 'd' already audited in PR #281 and ledgered in docs/ops/sre_audits/FABRICATED_CLAIMS_INDEX.md. 2. scripts/ops_notify.py -> scripts/notify_webhook.py (verified by 'ls scripts/ops_notify*' returning no match and Read of scripts/notify_webhook.py confirming the real helper, which respects notifications.enabled and the audit log per docs/ops/OPERATOR_NOTIFICATION_CHANNELS.md). The 0.574x performance baseline named in the trigger's Performance Audit step gets a single canonical pointer to tests/benchmarks/official_benchmark_200k.json plus the regression guard tests/test_official_benchmark_200k_evidence.py and tests/test_basic_python_scan_single_pass_parity.py, so a future agent cannot silently re-baseline the JSON to escape a real regression. The SPRINT_GREAT_LEAP_POSTMORTEM.md + LAB_LESSONS_LEARNED.md direction-of-inversion note (Pro is 0.574x as fast as OpenCore = ~1.74x wall-clock = slower in this profile) is cited so the next agent does not double-invert the ratio. Defensive Architecture (Database lock non-regression) cites DEFENSIVE_SCANNING_MANIFESTO.md sections 2-3 for the _HARD_MAX_SAMPLE / statement-timeout / WITH (NOLOCK) posture already in place, ADR 0044 for the report-generator path containment shape CodeQL recognizes, and THE_ART_OF_THE_FALLBACK.md section 3 for diagnostic-on-fall on transaction conflicts. The trigger's 'no time.sleep for contention' rule is restated in section 7 as a single greppable anti-pattern. The Guardrail Dashboard schema in section 5 is the literal header that future Slack Final Sign-off messages and PR bodies opened under this protocol must carry, with real counts, real Bandit severity, real Ruff state including any per-line # noqa enumeration, real supply-chain status, host identification, gate command, and branch SHAs. The [INTEGRITY_CHECK_PASSED] sign-off token is the contract that all four steps held; it becomes greppable across future threads. No behavior change to report/, core/, connectors/, pro/, or rust/boar_fast_filter/. Pre-commit clean (Ruff, Ruff format, plans dashboard, markdown lint, pt-BR locale, confidential commercial guard, external-tier no-plan-link guard, uv.lock + requirements.txt match, PII guards). Bandit on docs/ returns 0 high / 0 medium / 0 low (docs-only slice). Refs: PR #259, #261, #268, #279, #281, #284, #289. Trigger: Slack #data-boar-ops automation def95df7-a634-431a-93e5-659e4d831725, message ts 1777382830.576029 (~13:27 UTC, 2026-04-28). Co-authored-by: Fabio Tavares Leitao <[email protected]>
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.
Scope
Single-purpose hardening of the heatmap-PNG embedding sink in
report/generator.py(_heatmap_path_under_output_dir) flagged as a CodeQL High Severity path-traversal candidate. Replaces the implicittry/except ValueErroraroundPath.relative_to(base)with an explicitPath.is_relative_to()containment check so static analysers recognise the sanitiser, and tightensresolve()semantics so symlink/..escapes cannot bypass the boundary.Diff summary
report/generator.py—_heatmap_path_under_output_dir:Path(...).resolve(strict=False)on bothoutput_dirandheatmap_path(no symlink escape, no junctions).if not candidate.is_relative_to(base): return None(PEP-616, Python 3.9+; repo requires>=3.12, so safe).if not candidate.is_file(): return None— directory or missing path no longer slip through.tests/test_report_trends.py— three hostile-input regressions:test_heatmap_embed_rejects_dotdot_traversal— literalout/../sibling/rogue.pngis rejected.test_heatmap_embed_rejects_symlink_escape— symlink insideoutput_dirpointing outside is rejected (gracefully no-ops on filesystems without symlink permission).test_heatmap_embed_rejects_directory_and_missing— directory and missing path insideoutput_dirare rejected.The original positive/negative test (
good/bad) is preserved.Why
is_relative_to, not bespoke string filteringThe user explicitly asked for
pathlib.Path.is_relative_to, not amateur prefix/string filters.is_relative_tois the stdlib idiom; combined withresolve()it covers.., junctions, and symlinks before the comparison. CodeQL'spy/path-injectionquery recognisesPath.is_relative_toas a sanitiser pattern, removing the need for inline# noqasuppressions.Verification
uv run pytest tests/test_report_trends.py -v→ 8/8 passed (5 original + 3 new hostile-input)../scripts/check-all.sh --skip-pre-commit→ 987 passed, 5 skipped, 108 subtests passed (pwsh 7.6.1installed in the Cloud Agent VM so PowerShell parser tests now run; this also surfaced the pre-existing pwsh-missing artefact in this VM, unrelated to this diff).uv run pre-commit run --files report/generator.py tests/test_report_trends.py→ all hooks green (Ruff, format, plans-stats, markdown, pt-BR, commercial guard, PII guard, PII history guard, etc.).No behaviour change for callers: legitimate
output_dir-relative heatmap PNGs are still embedded; the sink is just provably tighter.Out of scope (intentionally)
RUSTSEC-2025-0020work lives in fix(security): bump pyo3 to 0.28.x in rust/boar_fast_filter (RUSTSEC-2025-0020 + RUSTSEC-2026-0013) #275 and is not touched here.execution-priority-and-pr-batching.mdc.Slack Thread