Skip to content

NO-JIRA: Fix path traversal vulnerability in certificate file handling - #124

Open
tpantelis wants to merge 1 commit into
openshift:mainfrom
tpantelis:path-traversal-vuln
Open

NO-JIRA: Fix path traversal vulnerability in certificate file handling#124
tpantelis wants to merge 1 commit into
openshift:mainfrom
tpantelis:path-traversal-vuln

Conversation

@tpantelis

@tpantelis tpantelis commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Added validation to sanitize certificate and key file paths from CLI arguments to prevent path traversal attacks. This addresses the Snyk security scan finding that was failing CI checks.

Changes:

  • Add validateFilePath() function to clean and validate file paths
  • Validate cert/key paths at startup before use
  • Use validated paths in certificate watching loop
  • Add comprehensive test coverage for path validation

The validation ensures:

  • Empty paths are rejected
  • Paths are cleaned to remove . and .. elements
  • Paths are converted to absolute paths
  • Symlinks are resolved to real paths
  • No .. patterns remain after processing

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation and normalization of TLS certificate and key file paths.
    • Prevented invalid or empty paths from being accepted.
    • Improved certificate monitoring by consistently using the validated certificate path.
    • Added support for resolving relative paths and symlinks while rejecting unsafe path traversal segments.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tpantelis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9aed41de-45c0-40fb-bdeb-96b0930b830a

📥 Commits

Reviewing files that changed from the base of the PR and between fb891d3 and 3197d32.

📒 Files selected for processing (2)
  • cmd/webhook/main.go
  • cmd/webhook/main_test.go

Walkthrough

The webhook now validates and normalizes certificate and key paths before TLS setup. Certificate monitoring reuses the validated certificate path. New tests cover path normalization and empty-path rejection.

Changes

Webhook TLS path handling

Layer / File(s) Summary
TLS path validation and tests
cmd/webhook/main.go, cmd/webhook/main_test.go
validateFilePath normalizes paths, resolves symlinks, permits nonexistent files, and rejects empty or unsafe paths. Tests cover supported inputs and empty-path errors.
Startup and certificate monitoring integration
cmd/webhook/main.go
main validates certificate and key paths before TLS keypair creation. Certificate monitoring reuses the validated certificate path.

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

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning The added Ginkgo Its contain bare assertions such as Expect(err).NotTo(HaveOccurred()) without meaningful failure messages, which violates requirement 4. Add diagnostic messages to every new Expect assertion, including the path under test and the expected validation behavior.
✅ Passed checks (14 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Stable And Deterministic Test Names ✅ Passed The added Ginkgo titles are static and descriptive: they name path categories and validation behavior, with no generated values, timestamps, IPs, or runtime interpolation.
Microshift Test Compatibility ✅ Passed The added Ginkgo tests exercise only local validateFilePath behavior and use no Kubernetes, OpenShift, unavailable API, namespace, or multi-node feature.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The new Ginkgo tests validate local file paths only. They use no cluster APIs, nodes, replicas, scheduling, topology, or HA behavior, so they make no multi-node assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed The commit changes only certificate/key path validation in cmd/webhook and tests; it adds no manifests, controllers, replicas, affinity, topology spread, node selectors, tolerations, or PDBs.
Ote Binary Stdout Contract ✅ Passed The diff adds no stdout writes. New main() calls use glog.Fatalf, which routes to files or stderr, and new output-producing tests run inside It blocks.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added Ginkgo tests only validate local file paths and empty input. They add no network calls, IPv4 literals, IPv4 parsing, or external connectivity; existing IPv4 HTTP tests are unchanged.
No-Weak-Crypto ✅ Passed The changed code uses SHA-512 for certificate monitoring and TLS 1.2 AEAD cipher suites; no flagged weak crypto or custom secret comparison is introduced.
Container-Privileges ✅ Passed The PR changes only cmd/webhook Go files. The diff adds no privilege fields, and deployment/Dockerfile scans found no privileged, host namespace, SYS_ADMIN, or allowPrivilegeEscalation settings.
No-Sensitive-Data-In-Logs ✅ Passed Changed logs emit certificate/key file paths and generic errors only; the diff does not log file contents, passwords, tokens, API keys, PII, session IDs, hostnames, or customer data.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing path traversal in certificate file handling.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@openshift-ci
openshift-ci Bot requested review from dougbtv and jeremyeder August 12, 2026 18:41
@openshift-ci

openshift-ci Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tpantelis
Once this PR has been reviewed and has the lgtm label, please assign jeremyeder for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tpantelis tpantelis changed the title Fix path traversal vulnerability in certificate file handling NO-JIRA: Fix path traversal vulnerability in certificate file handling Aug 12, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 12, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@tpantelis: This pull request explicitly references no jira issue.

Details

In response to this:

Added validation to sanitize certificate and key file paths from CLI arguments to prevent path traversal attacks. This addresses the Snyk security scan finding that was failing CI checks.

Changes:

  • Add validateFilePath() function to clean and validate file paths
  • Validate cert/key paths at startup before use
  • Use validated paths in certificate watching loop
  • Add comprehensive test coverage for path validation

The validation ensures:

  • Empty paths are rejected
  • Paths are cleaned to remove . and .. elements
  • Paths are converted to absolute paths
  • Symlinks are resolved to real paths
  • No .. patterns remain after processing

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@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: 3

🤖 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 `@cmd/webhook/main.go`:
- Around line 295-318: Reject raw parent-directory path elements before
normalization in the path-validation flow around filepath.Clean, then remove the
final realPath substring check so safe names containing ".." remain valid.
Update cmd/webhook/main.go lines 295-318 accordingly. Change
cmd/webhook/main_test.go lines 410-415 to expect parent-directory input to fail
validation.
- Around line 304-320: The symlink-resolving logic in the path validation
function must not replace the configured path used for TLS reads and reloads.
Use filepath.EvalSymlinks only to validate the resolved target, avoid rejecting
Kubernetes AtomicWriter paths containing "..", and return the cleaned absolute
configured path (absPath) so certificate rotation continues to follow the
symlink. Add coverage for a tls.crt symlink targeting ..data/tls.crt that
verifies both startup and subsequent rotation.
- Around line 102-109: Update the fatal error handling around validateFilePath
for both the certificate and key paths to log only stable validation-failure
messages. Remove the supplied flag values and validation error details from the
glog.Fatalf calls while preserving termination and distinguishing certificate
versus key validation failures.
🪄 Autofix

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: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 03919ff2-050e-4f25-a6e8-0c6c2bfc7c54

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9df61 and fb891d3.

📒 Files selected for processing (2)
  • cmd/webhook/main.go
  • cmd/webhook/main_test.go

Comment thread cmd/webhook/main.go Outdated
Comment thread cmd/webhook/main.go
Comment thread cmd/webhook/main.go Outdated
Added validation to sanitize certificate and key file paths from
CLI arguments to prevent path traversal attacks. This addresses the
Snyk security scan finding that was failing CI checks.

Changes:
- Add validateFilePath() function to clean and validate file paths
- Validate cert/key paths at startup before use
- Use validated paths in certificate watching loop
- Add comprehensive test coverage for path validation

The validation ensures:
- Empty paths are rejected
- Paths are cleaned to remove . and .. elements
- Paths are converted to absolute paths
- Symlinks are resolved to real paths
- No .. patterns remain after processing

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
@tpantelis
tpantelis force-pushed the path-traversal-vuln branch from fb891d3 to 3197d32 Compare August 12, 2026 18:59
@openshift-ci

openshift-ci Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@tpantelis: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/security 3197d32 link false /test security

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants