fix(feat): Prevent Insecure path traversal in Archive extraction and escape Injection in string construction #2
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.
Summary of Fixes
This pull request addresses multiple security-related issues in the
cilium-cli
andpkg/policy
components that could potentially expose the system to path traversal and string injection vulnerabilities. The changes improve input validation, ensure safe path handling, and replace unsafe string concatenation with proper encoding and marshaling.1. Path Traversal Prevention in Archive Extraction
File:
cilium-cli/sysdump/sysdump.go
(around line 2346)When extracting files from an archive, unvalidated filenames can lead to directory traversal attacks (e.g., entries like
../evil-file
). Such attacks may allow files to be written outside the intended extraction directory, potentially overwriting sensitive files.Fix implemented:
The extraction path is now cleaned using
filepath.Clean
and verified to ensure:..
path components.dst
).Suspicious entries are skipped, and a warning can be logged to indicate skipped entries.
This ensures all files extracted from a zip or tar archive remain confined to the intended directory, preventing arbitrary file write vulnerabilities.
2. Safe JSON Construction in Deployment Annotations
File:
cilium-cli/connectivity/check/deployment.go
(lines 1903–1906)The original implementation manually constructed a JSON string using string concatenation that included user-provided values. This approach is unsafe because unescaped quotes or special characters could break the JSON structure or lead to injection vulnerabilities.
Fix implemented:
json.Marshal
.map[string]annotations
and serialized to JSON before being passed toSet
.json.Marshal
andSet
.This change ensures the generated JSON is syntactically valid and eliminates the risk of injection via crafted annotation names or values.
3. Escaping Dangerous Characters in Error Messages
File:
pkg/policy/l4.go
(around line 1210)A similar issue was found where an error message was manually embedded in a quoted string without escaping. If the error message contained quotes or control characters, it could break the JSON structure.
Fix implemented:
Replaced:
with:
This ensures that all dangerous characters are escaped correctly, and the resulting string is a valid JSON string literal.
CWE-22: Improper Limitation of a Pathname to a Restricted Directory (‘Path Traversal’)
CWE-116: Improper Encoding or Escaping of Output
CWE-79 / CWE-20 (related): Improper Input Validation or Injection via Unescaped Strings
Please ensure your pull request adheres to the following guidelines:
description and a
Fixes: #XXX
line if the commit addresses a particularGitHub issue.
Fixes: <commit-id>
tag, thenplease add the commit author[s] as reviewer[s] to this issue.
Fixes: #issue-number