Skip to content

codeql: model PRKS sanitizer boundaries - #90

Closed
Fooftilly wants to merge 2 commits into
masterfrom
chatgpt/codeql-prks-sanitizer-models
Closed

Fooftilly wants to merge 2 commits into
masterfrom
chatgpt/codeql-prks-sanitizer-models

Conversation

@Fooftilly

@Fooftilly Fooftilly commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Teach CodeQL about PRKS's existing Python sanitization/containment boundaries so the large py/log-injection and py/path-injection families can be evaluated with the same contracts the runtime already enforces.

This is deliberately query-specific modeling, not a global suppression of either rule.

Why

The fresh master analysis reported:

  • 40 py/log-injection results
  • 48 py/path-injection results

Manual inspection showed that many of these flows cross helpers that constrain output before it reaches a log or filesystem sink, but CodeQL does not infer those project-specific contracts automatically.

Changes

Add a repository-local Python CodeQL model pack under:

.github/codeql/extensions/prks-python-models/

It models:

Log-injection barriers

  • safe_log_id
  • safe_log_label
  • safe_error_type
  • safe_bind_scope
  • safe_client_error_kind
  • safe_error_name
  • safe_client_source
  • safe_route

These helpers return fixed/constrained labels or normalized routes rather than raw user/library text.

Path-injection barriers

  • safe_pdf_path_under_dir
  • managed_pdf_filename
  • referenced_managed_pdf_filename
  • safe_processing_path_under_dir

These helpers either return a canonical path proven to remain below the managed root or a validated single managed filename.

Path containment guard

  • backup_restore._path_is_under(child, parent)

The guard resolves both paths via realpath and only accepts a child equal to or beneath the requested parent.

Safety of the approach

The models are limited to the relevant CodeQL query kinds:

  • log-injection
  • path-injection

They do not mark these values universally safe and do not disable either query. Any taint flow that does not cross one of these reviewed boundaries remains visible.

Validation

The PR CodeQL run is the acceptance test for the model pack. The expected outcome is a material reduction in the current 40 log-injection / 48 path-injection findings without changing application runtime behavior.

Any findings that remain after this PR should be reviewed individually rather than expanding the model indiscriminately.


Prepared using ChatGPT.

Summary by CodeRabbit

  • Security
    • Improved static analysis coverage for Python code involving logging and file-path handling.
    • Security scans can now better identify protections against log-injection and path-injection risks.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 6e940b02-a626-4f37-988a-38e86f8f7019

📥 Commits

Reviewing files that changed from the base of the PR and between dc50f9b and 0876454.

📒 Files selected for processing (2)
  • .github/codeql/extensions/prks-python-models/codeql-pack.yml
  • .github/codeql/extensions/prks-python-models/models/prks.yml

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change adds a CodeQL library pack and Python models for log-injection and path-injection barriers, including a guard for _path_is_under.

Changes

CodeQL Python Models

Layer / File(s) Summary
Pack metadata and safety models
.github/codeql/extensions/prks-python-models/codeql-pack.yml, .github/codeql/extensions/prks-python-models/models/prks.yml
The pack targets codeql/python-all and loads YAML models. The models define barriers for eight logging helpers, four managed-path helpers, and the child argument of _path_is_under.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding CodeQL models for PRKS sanitizer boundaries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Model PRKS sanitizer boundaries in CodeQL

⚙️ Configuration changes ✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Adds a repository-local CodeQL Python model pack for PRKS sanitizer contracts.
• Models reviewed logging and filesystem boundaries only for their relevant injection queries.
• Preserves unrelated taint flows while reducing false-positive CodeQL findings.
Diagram

graph TD
  A["CodeQL Scan"] -->|"discovers"| B["Pack Manifest"] -->|"loads"| C["Barrier Models"] -->|"extends"| D["Injection Queries"]
  E["Log Boundaries"] -->|"contracts"| C
  F["Path Boundaries"] -->|"contracts"| C
Loading
High-Level Assessment

The repository-local data-extension pack is the appropriate approach because it models existing runtime contracts without changing application behavior or globally suppressing findings. Global query exclusions and custom query forks were considered but would either hide unrelated taint flows or create unnecessary maintenance overhead.

Files changed (2) +40 / -0

Other (2) +40 / -0
codeql-pack.ymlDeclare the local Python CodeQL model pack +9/-0

Declare the local Python CodeQL model pack

• Defines a library extension pack targeting all compatible 'codeql/python-all' versions and loads model definitions from the pack’s models directory.

.github/codeql/extensions/prks-python-models/codeql-pack.yml

prks.ymlModel PRKS log and path sanitizer boundaries +31/-0

Model PRKS log and path sanitizer boundaries

• Registers eight log-injection return barriers, four path-injection return barriers, and the '_path_is_under' containment guard. Every model is restricted to its relevant query kind, preserving unrelated taint analysis.

.github/codeql/extensions/prks-python-models/models/prks.yml

@greptile-apps

greptile-apps Bot commented Sep 20, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations were identified.

Summary

This PR adds a repository-local Python CodeQL model pack that identifies existing logging and filesystem containment boundaries for the log-injection and path-injection queries.

  • Adds valid model-pack metadata targeting codeql/python-all.
  • Models constrained logging-helper return values as query-specific barriers.
  • Models canonicalized paths and validated filenames as path-injection barriers.
  • Models _path_is_under as a true-branch containment guard.

Reviews (1) · Last reviewed commit: "codeql: model PRKS sanitizer boundaries"

@Fooftilly Fooftilly closed this Sep 20, 2026
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1)

Grey Divider


Remediation recommended

1. Unsafe fallbacks evade log scanning 🐞 Bug ⚙ Maintainability
Description
The safe_log_label return-value barrier treats every result as sanitized, but the function returns
its caller-supplied fallback unchanged on rejected values. When untrusted text is supplied as the
fallback and the primary value is empty or invalid, that text can reach a log while CodeQL
terminates the flow at this helper.
Code

.github/codeql/extensions/prks-python-models/models/prks.yml[10]

+      - ["backend.log_safety", "Member[safe_log_label].ReturnValue", "log-injection"]
Relevance

●●● Strong

Accepted security-boundary findings are consistently fixed; this directly conflicts with the PR's
stated sanitizer-modeling intent.

PR-#25
PR-#65

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The model declares the entire return value a log-injection barrier, while the implementation
directly returns fallback on four rejection paths without validating it. CodeQL documents
barrierModel(type, path, kind) as the mechanism that blocks the selected value for the specified
query kind, so selecting Member[safe_log_label].ReturnValue overstates this helper's actual
contract.

.github/codeql/extensions/prks-python-models/models/prks.yml[9-10]
backend/log_safety.py[194-202]
🌐 The Python modeling guide defines barrierModel entries by type, selected path, and query kind.

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new CodeQL barrier declares every `safe_log_label` return value safe, although invalid primary values cause the function to return its `fallback` argument unchanged.

## Fix Focus Areas
- .github/codeql/extensions/prks-python-models/models/prks.yml[9-10]
- backend/log_safety.py[194-202]

## Recommended Fix
Make `safe_log_label` validate and constrain the fallback with the same log-safe policy, using a fixed safe value such as `unknown` if the fallback itself is invalid. Keep the return-value barrier only after every return path is guaranteed to produce constrained text, and add a test using a fallback containing a newline.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 1 rule
✅ Web pages:
  +2 more
Review mode: ⚖️ Balanced: This adds security-relevant CodeQL taint and path-containment models that can materially alter analysis results, warranting a careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

# arbitrary request/library text. Keep these barriers query-specific so
# they do not suppress unrelated taint flows.
- ["backend.log_safety", "Member[safe_log_id].ReturnValue", "log-injection"]
- ["backend.log_safety", "Member[safe_log_label].ReturnValue", "log-injection"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Unsafe fallbacks evade log scanning 🐞 Bug ⚙ Maintainability

The safe_log_label return-value barrier treats every result as sanitized, but the function returns
its caller-supplied fallback unchanged on rejected values. When untrusted text is supplied as the
fallback and the primary value is empty or invalid, that text can reach a log while CodeQL
terminates the flow at this helper.
Agent Prompt
## Issue description
The new CodeQL barrier declares every `safe_log_label` return value safe, although invalid primary values cause the function to return its `fallback` argument unchanged.

## Fix Focus Areas
- .github/codeql/extensions/prks-python-models/models/prks.yml[9-10]
- backend/log_safety.py[194-202]

## Recommended Fix
Make `safe_log_label` validate and constrain the fallback with the same log-safe policy, using a fixed safe value such as `unknown` if the fallback itself is invalid. Keep the return-value barrier only after every return path is guaranteed to produce constrained text, and add a test using a fallback containing a newline.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@Fooftilly
Fooftilly deleted the chatgpt/codeql-prks-sanitizer-models branch September 20, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant