Skip to content

fix: preserve one-character directories in SARIF paths - #84

Merged
matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:fix/github-action-sarif-relative-paths
Oct 23, 2026
Merged

matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:fix/github-action-sarif-relative-paths

Conversation

@ANAMASGARD

@ANAMASGARD ANAMASGARD commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

PR description

Fixes #83

The SARIF normalizer uses sub("^./"; ""), where the unescaped dot matches any character. This incorrectly changes legitimate paths such as k/pod.yaml to pod.yaml, causing findings to reference the wrong file.

This change:

  • Escapes the dot so only a literal leading ./ is removed.
  • Adds regression coverage through the complete entrypoint.
  • Covers relative paths, workspace-absolute paths, file:// URIs, longer-directory negative controls, and existing empty-URI filtering.

No action inputs, dependencies, or SARIF schema changes are introduced.

Validation

  • Regression fails on unchanged code and passes with the correction.
  • Entrypoint tests: 19 passed.
  • Action command-construction tests: 22 passed.
  • Bash syntax and git diff --check: passed.
  • Actual container comparison confirms the baseline produces pod.yaml, while the corrected action preserves k/pod.yaml.

Hosted GitHub Actions execution and Code Scanning upload have not been verified.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected SARIF report path handling so a leading ./ is recognized and stripped literally. Relative directories are preserved, supported path prefixes are removed, and empty URIs are omitted. This improves the consistency of file locations shown in SARIF output.

Match only a literal leading ./ when normalizing SARIF artifact URIs. The unescaped dot also matched single-character directory prefixes and changed k/pod.yaml to pod.yaml.

Exercise the full entrypoint with relative, workspace-absolute and file URI fixtures, including longer-directory and empty-location controls.

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 054dd032-6e05-44bd-ae5a-bcc537f40971
📥 Commits

Reviewing files that changed from the base of the PR and between 55308b8 and 32b24fb.

📒 Files selected for processing: 2
  • entrypoint.sh
  • tests/entrypoint_test.sh

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The SARIF URI cleanup now matches a literal leading ./. A regression test covers multiple URI forms, directory retention, prefix removal, and empty URI omission.

Changes: SARIF URI normalization

Layer / File(s) Summary
URI cleanup and regression test
entrypoint.sh, tests/entrypoint_test.sh
The cleanup pattern now matches a literal ./ prefix. The test harness can load a SARIF fixture, passes through INPUT_FORMAT, and checks normalized URI output for several path forms.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: matthyx

Merge Risk: ⚪ Minimal · up to 32b24

SARIF locations now preserve one-character directory prefixes, with no concrete merge-blocking risk identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 clearly and concisely describes the main change: preserving one-character directory prefixes in SARIF paths.
Linked Issues check Passed Issue [#83] requires removal of only a literal leading ./ from SARIF URIs. entrypoint.sh changes sub("^./"; "") to sub("^\\\\./"; ""). The new entrypoint test covers k/pod.yaml, longer directo…
Out of Scope Changes check Passed The pull request changes only the SARIF normalization expression and the entrypoint test harness and regression fixture. The test harness changes support execution of the linked SARIF regression test.…
Full details: Linked Issues check

Explanation

Issue [#83] requires removal of only a literal leading ./ from SARIF URIs. entrypoint.sh changes sub("^./"; "") to sub("^\\./"; ""). The new entrypoint test covers k/pod.yaml, longer directories, ./ paths, workspace-absolute paths, file:// URIs, and empty-URI filtering. The expected output preserves k/pod.yaml and removes only the intended prefixes.

Full details: Out of Scope Changes check

Explanation

The pull request changes only the SARIF normalization expression and the entrypoint test harness and regression fixture. The test harness changes support execution of the linked SARIF regression test. No unrelated product behavior, inputs, dependencies, or schema changes are present in the reviewed diff.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@matthyx matthyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve: the fix is needed and sound. No blocking findings in the two changed files.

Reviewed head 32b24fbbc8339790523474bfca692767291ea596 against main at 55308b8442c97f510a87f81f4b9d11d3e5419014. The unescaped regex dot removes k/ from k/pod.yaml; matching a literal dot repairs the cause while retaining existing prefix removal and empty-location filtering. No inputs, dependencies, schema, or resource handling change.

Validation in a credential-free, network-isolated Bubblewrap environment with read-only source and temporary writable storage:

  • bash tests/entrypoint_test.sh: 19 passed; the same tests with main's entrypoint: 18 passed, with only the new SARIF regression failing.
  • bash tests/action_test.sh: 22 passed (after fixing an isolation-only missing awk symlink).
  • bash -n for entrypoint and both test scripts; git diff --check: passed.

The fixture covers relative paths, longer directory controls, literal ./, workspace-absolute paths, file URIs, and empty URI filtering. Full scanner/container execution and successful hosted Code Scanning upload were not independently validated; ShellCheck was unavailable.

History: #83 describes this exact defect. Merged #18 and #22 establish SARIF output/upload support; neither fixes this regex. #71 and #50 concern empty reports (the latter tracks Helm source attribution), not directory corruption. Closed #7 was explicitly replaced by #9; its input-validation discussion does not reject this normalization. Closed #44 has no explicit maintainer rejection of this approach. Main still contains the defect. No duplicate or superseding fix found.

Search scope: all repository PR/issue listings fit within the 100-item API pages; searched title/body/comment index for sarif, entrypoint.sh, and path, and inspected entrypoint history and related discussions. This is bounded repository-local evidence, not proof of absence across forks or unindexed discussions.

Head CI's entrypoint job passed. Scan/image jobs fail opening SARIF with EACCES and also report deprecated CodeQL v2; autofix artifact upload fails opening results.json with EACCES. These are separate permission/workflow problems: this diff changes neither file modes nor JSON handling. No existing human reviews or inline threads require resolution; CodeRabbit reports no actionable findings. Independent code review recommends approval; architecture assessment is clear.

@matthyx
matthyx merged commit 6a52718 into kubescape:main Oct 23, 2026
5 of 8 checks passed
@matthyx matthyx moved this to To Archive in KS PRs tracking Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

SARIF normalization drops one-character directory prefixes

2 participants