You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(builtin): escape directory and profiler names - #3743
Problem Summary:
Builtin /dir and hotspots pages render filesystem-derived names into HTML.
A malicious directory entry or historical profiler filename could inject HTML
into the builtin management UI.
What is changed and the side effects?
Changed:
Escape HTML link text and href values emitted by Path.
Escape profiler filenames in HTML option values and visible text.
Encode profiler view and base paths in generated URLs, then decode and
validate them in both profiler handlers.
Add regression tests for hostile names and encoded profile paths.
Side effects:
Performance effects: Negligible; escaping/encoding only occurs while
rendering builtin management pages.
Breaking backward compatibility: No. Existing raw view and base query
parameters remain supported.
Check List:
Please make sure your changes are compilable.
When providing us with a new feature, it is best to add related tests.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An active moderate issue remains: non-responsive diff/base profile requests encode the base path but DisplayResult does not decode it, causing those requests to fail with an invalid base query.
This PR hardens built-in directory and profiler management pages against HTML injection from filesystem-derived names and safely encodes profiler paths in generated URLs.
Changes:
Escape directory links, profiler option values, and visible profiler names.
Add prefixed percent encoding and validation for profiler view and base query paths.
Add regression tests for hostile names, encoded paths, and rendered links.
File
Description
test/brpc_builtin_service_unittest.cpp
Adds regression tests covering hostile directory and profiler names, encoded profiler paths, and HTML link rendering.
src/brpc/builtin/hotspots_service.cpp
Encodes and validates profiler paths in generated URLs and escapes profiler filenames in HTML output.
src/brpc/builtin/common.cpp
Escapes directory link URLs and displayed text when rendering HTML.
The reason will be displayed to describe this comment to others. Learn more.
[replied by brpc-oncall robot] The added HTML escaping is the right direction, but the new prefixed path encoding is applied asymmetrically (Copilot already flagged that base is encoded into the non-responsive URL yet never decoded before validation in DisplayResult, so every diff/base view fails), and the encoding layer duplicates a hard-coded prefix in the inline JS while adding no protection beyond what ValidProfilePath already enforces.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two moderate active issues remain: generated URLs do not percent-encode reserved filename and query characters, so valid paths cannot be selected reliably and may be misinterpreted by browsers.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Approval is blocked by unresolved path round-trip and query-encoding issues, a critical profiling-directory traversal risk, and a regression test that does not exercise the escaping behavior.
Path-prefix validation allows access outside the profiling directory
src/brpc/builtin/hotspots_service.cpp:1069
ValidProfilePath only checks starts_with(FLAGS_rpc_profiling_dir), so a sibling such as ./rpc_data/profiling_evil/... also passes when the configured directory is ./rpc_data/profiling. The view/base values are later passed to pprof, allowing an HTTP caller to select files outside the profiling directory; checking the enumerated names here does not fix that handler path. Require a directory boundary (or canonicalize and verify the parent) before accepting the path.
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
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
Builtin
/dirand hotspots pages render filesystem-derived names into HTML.A malicious directory entry or historical profiler filename could inject HTML
into the builtin management UI.
What is changed and the side effects?
Changed:
Path.viewandbasepaths in generated URLs, then decode andvalidate them in both profiler handlers.
Side effects:
Performance effects: Negligible; escaping/encoding only occurs while
rendering builtin management pages.
Breaking backward compatibility: No. Existing raw
viewandbasequeryparameters remain supported.
Check List: