Workspace: make HeaderCacheService configuration aware#8207
Workspace: make HeaderCacheService configuration aware#8207LeFrosch wants to merge 1 commit intobazelbuild:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request completes the implementation of configuration awareness within the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the HeaderCacheService to be configuration aware, ensuring headers are cached and retrieved based on their specific configuration ID to prevent conflicts and improve efficiency. However, the current implementation introduces several Path Traversal vulnerabilities due to a lack of validation for configurationId and other path-related strings obtained from build metadata. This could allow malicious projects to write, delete, or read arbitrary files on the user's system. It is crucial to sanitize these inputs to prevent traversal characters (e.g., ..) and ensure resolved paths remain within the intended cache directory.
| private fun TargetKey.cacheDirectory(): Path { | ||
| // TODO: use different cache directories depending on the configuration | ||
| return cacheDirectory.resolve("default") | ||
| return cacheDirectory.resolve(configurationId().ifBlank { "default" }) |
There was a problem hiding this comment.
The configurationId() from TargetKey is used to construct a file path without validation, leading to a Path Traversal vulnerability. An untrusted project could use .. in configurationId to write files outside the intended cache directory. While using ifBlank { "default" } is a good approach for empty IDs, it's critical to sanitize configurationId() to prevent path traversal. Additionally, consider adding a DEBUG log when the default is used to help identify missing configurations.
val configId = configurationId().ifBlank { "default" }
if (configId == "default") {
LOG.debug("Using default cache directory for target key: $this")
}
return cacheDirectory.resolve(configId)References
- Path Traversal vulnerability due to unsanitized input in file path construction.
|
|
||
| // check if the header is already present in the cache | ||
| if (!cacheTracker.add(header.relativePath())) continue | ||
| if (!cacheTracker.add(key.configurationId() + "/" + header.relativePath())) continue |
There was a problem hiding this comment.
The use of header.relativePath() and configurationId() to track cached headers, while an in-memory operation here, highlights an insecure handling of untrusted strings. These values are later used to construct file system paths, which could lead to Path Traversal vulnerabilities if configurationId() contains unsafe characters. It is crucial to sanitize or encode configurationId() to ensure it is filesystem-safe before it's used in any path-related operations.
References
- Path Traversal vulnerability due to unsanitized input in file path construction.
The header cache was designed from the beginning to be configuration aware. This PR fills in the gaps using the target's configuration id.