PIPE-10443 vulnerable fix coverage-report-server#12
Draft
SB-PawanN wants to merge 1 commit into
Draft
Conversation
| filepath = os.path.join(self.src_path, filename) | ||
| if not os.path.exists(filepath): | ||
| filepath = self.resolve_source_path(filename) | ||
| if filepath is None or not os.path.exists(filepath): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Remediate CWE-22 path traversal findings on lines 152 and 163 of tools/sancov/coverage-report-server.py.
Problem
ServerHandler.do_GET built a file path directly from the request URL and passed it to os.path.exists() and open() without validating that it stayed under the intended source directory. An attacker could request a path like GET [passwd] to read files outside the source root.
Fix
Added ServerHandler.resolve_source_path(filename), which resolves the requested path with os.path.realpath() and validates it against the configured --srcpath root using os.path.commonpath(). If the resolved path escapes the source root, the request is rejected with 404.
The handler now uses the validated path returned by resolve_source_path() for both the existence check and the open() call. args.srcpath is normalized once at startup so both sides of the comparison are canonical absolute paths.
Change
Added resolve_source_path(); updated do_GET to use the validated path; normalized src_path at startup.
Testing
python3 -m py_compile [coverage-report-server.py] passes.
Valid source file requests resolve correctly.
Traversal attempts are rejected.