fix: services uncontrolled data used in path expression #11605
+7
−0
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.
fix the problem, we should ensure that the resolved path is strictly contained within the intended root directory of the file server. This can be done by resolving the user-supplied path against the root, normalizing it, and then checking that the resulting absolute path is still within the root directory. In the context of Go's
http.FileSystem
, this means we should check that the cleaned path does not escape the root of the embedded filesystem. Since we may not have access to the actual filesystem path (e.g., withembed.FS
), we can instead reject any path that, after cleaning, contains any parent directory references (..
) or is absolute. We should also ensure that the path is not empty and does not contain any path separators at the start (other than the leading slash).The best way to implement this is to add a check after cleaning the path, before opening the file, to ensure that the path is relative and does not contain any
..
components. This can be done by splitting the path and checking its components. The changes should be made in theServeHTTP
method inservices/web/pkg/assets/server.go
, specifically after line 81 and before line 99.Types of changes
Checklist: