Skip to content

fix: the build-digest in build-digest.py - #1173

Open
anupamme wants to merge 2 commits into
layer5io:masterfrom
anupamme:fix-repo-docs-v-001-sanitize-cli-args-build-digest
Open

fix: the build-digest in build-digest.py#1173
anupamme wants to merge 2 commits into
layer5io:masterfrom
anupamme:fix-repo-docs-v-001-sanitize-cli-args-build-digest

Conversation

@anupamme

@anupamme anupamme commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Fix high severity security issue in build-digest.py.

Vulnerability

Field Value
ID V-001
Severity HIGH
Scanner multi_agent_ai
Rule V-001
File build-digest.py:105
Assessment Likely exploitable

Description: The build-digest.py script accepts command-line arguments directly from sys.argv without sanitization. If these arguments are passed to shell commands without proper escaping, an attacker controlling the arguments could inject shell metacharacters to execute arbitrary commands on the build host.

Evidence

Exploitation scenario: Attacker with control over build script arguments (e.g., through CI/CD pipeline manipulation) supplies malicious arguments containing shell metacharacters: python build-digest.py 'content/; rm -rf.

Scanner confirmation: multi_agent_ai rule V-001 flagged this pattern.

Production code: This file is in the production codebase, not test-only code.

Threat Model Context

This is a Node.js library - vulnerabilities affect downstream consumers who use this package.

Changes

  • build-digest.py

Behavior Preservation

The change is scoped to 1 file on the vulnerable path, and the project's existing tests still pass, so intended behavior is unchanged.

Verification

  • Build passes
  • Scanner re-scan confirms fix
  • LLM code review passed

Automated security fix by OrbisAI Security

Summary by CodeRabbit

  • Bug Fixes
    • Improved command-line path handling by resolving input/output paths consistently before use.
    • Added validation to produce a clear stderr error and exit with code 1 when the specified content directory is missing or not a directory.
    • Refined the digest “Source” header and completion messaging to match the original CLI argument text.

Automated security fix generated by OrbisAI Security

Signed-off-by: orbisai0security <mediratta@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 966c7d11-f800-4ea1-888c-4980c50b85ac

📥 Commits

Reviewing files that changed from the base of the PR and between b0261a1 and 523c55b.

📒 Files selected for processing (1)
  • build-digest.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • build-digest.py

📝 Walkthrough

Walkthrough

build-digest.py resolves content and output paths absolutely, validates the content directory, and preserves the original CLI strings in the digest source header and completion message.

Changes

Digest path validation

Layer / File(s) Summary
Normalize and validate digest paths
build-digest.py
main() resolves both paths, reports invalid content directories to stderr with exit status 1, and uses the original CLI arguments for displayed source and output paths.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title identifies the affected script and indicates a fix, which matches the main change in this PR.
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 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build-digest.py`:
- Around line 109-110: Update the path handling around content_dir and
output_file so canonical absolute paths remain available for filesystem
operations but are not emitted in the generated digest source line or completion
message. Preserve the original arguments as display values, or convert them to
repository-relative/generic paths, and use those sanitized values at the output
sites near the digest generation and completion logging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 865178be-645a-4625-b826-f41334aee8a4

📥 Commits

Reviewing files that changed from the base of the PR and between 15c4721 and e49e629.

📒 Files selected for processing (1)
  • build-digest.py

Comment thread build-digest.py Outdated

@Maanvi212006 Maanvi212006 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.

The code change itself is fine and mildly useful — .resolve() and the new directory-existence check are harmless improvements. Just address CodeRabbit's comment: since paths are now absolute, they leak into the generated digest header and completion log.

@anupamme

Copy link
Copy Markdown
Author

Addressed review comments. Pls review.

@Maanvi212006 Maanvi212006 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.

Image

Follow the steps given on this link to fix this issue:
https://github.com/layer5io/docs/pull/1173/checks?check_run_id=89745033442

Preserve the original CLI arguments as display values so that resolved
absolute paths are not emitted in the generated digest header, error
messages, or the completion log. Also add a docstring to main() to
satisfy the 80% docstring coverage threshold.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Anupam Mediratta <mediratta@gmail.com>
@anupamme
anupamme force-pushed the fix-repo-docs-v-001-sanitize-cli-args-build-digest branch from b0261a1 to 523c55b Compare July 29, 2026 01:29
@anupamme

Copy link
Copy Markdown
Author

signed off. pls review.

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.

2 participants