Enhance File Sandbox Security and Add Comprehensive Path Handling Tests #2083
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.
feat(security): Harden file sandboxing and path handling
This pull request improves the security and reliability of file sandboxing and path handling in Consul Template. It addresses potential vulnerabilities related to symlink and path confusion attacks by enforcing stricter path validation and adds comprehensive unit tests for edge cases.
Description
This change hardens the file sandbox functionality to prevent potential security vulnerabilities where a malicious template could escape the sandbox or disclose sensitive data. By normalizing, resolving, and using absolute paths for all checks and file operations, we mitigate the risk of symlink and path manipulation attacks.
The primary benefits are:
There are no breaking changes to public APIs.
Key Changes
Sandbox Enforcement:
pathInSandbox
andfileFunc
to use normalized, resolved, and absolute paths for all sandbox checks and file reads.Path Handling:
NewFileQuery
to ensure the exact path checked is the one accessed.Comprehensive Testing:
Notes
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.