Skip to content

PIPE-10443 vulnerable fix coverage-report-server#12

Draft
SB-PawanN wants to merge 1 commit into
masterfrom
PIPE-10443-vulnerable-coverage-report-server
Draft

PIPE-10443 vulnerable fix coverage-report-server#12
SB-PawanN wants to merge 1 commit into
masterfrom
PIPE-10443-vulnerable-coverage-report-server

Conversation

@SB-PawanN

Copy link
Copy Markdown
Contributor

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.

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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants