Escape HTML output in builtin /flags service - #3529
Open
wwbmmm wants to merge 1 commit into
Open
Conversation
The ?setvalue= confirmation message and the ?setvalue&withform page wrote the gflag name/value into the html page without escaping, unlike the flag list page which already escapes values with HtmlReplace. Escape them with WebEscape like rpcz_service does. Plain text output is unchanged.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new test mutates a global gflag and should use RAII (e.g., GFLAGS_NAMESPACE::FlagSaver) to guarantee flag restoration even on early ASSERT_* exits, preventing cross-test contamination.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens the builtin /flags HTML pages against HTML injection by escaping user-controlled gflag names/values at two previously unescaped sinks, and adds a regression test to validate both reflected and stored rendering behavior.
Changes:
- Escape gflag name/value in the
?setvalue&withformHTML form page (set_value_page) usingWebEscape. - Escape gflag name/value in the HTML confirmation message for
?setvalue=...updates. - Add
BuiltinServiceTest.flags_escapingto cover reflected/stored HTML escaping and unchanged plain-text output.
File summaries
| File | Description |
|---|---|
src/brpc/builtin/flags_service.cpp |
Escapes gflag name/value when rendering the HTML set-value form and HTML confirmation output. |
test/brpc_builtin_service_unittest.cpp |
Adds a reloadable string flag + a new test that exercises both HTML sinks and verifies plain-text output remains unescaped. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+704
to
+708
| const std::string payload = "<svg onload=alert(1)>&\"'"; | ||
| const std::string escaped = brpc::WebEscape(payload); | ||
| std::string saved_value; | ||
| ASSERT_TRUE(GFLAGS_NAMESPACE::GetCommandLineOption( | ||
| "reloadable_string_flag_for_ut", &saved_value)); |
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.
What problem does this PR solve?
Problem Summary:
The builtin
/flagsservice wrote the gflag name and value into the HTML page without escaping in two places: the?setvalue=confirmation message and the?setvalue&withformform page (set_value_page). Unlike the flag list page, which already escapes values withHtmlReplace, these two sinks rendered the raw value, so a value containing HTML metacharacters was injected into the page markup.What is changed and the side effects?
Changed:
current_valueinset_value_pagewithWebEscape.?setvalue=confirmation message withWebEscape.Side effects:
Performance effects: none, only affects HTML rendering of the
/flagspages.Breaking backward compatibility: none. Plain-text output (non-browser requests) is unchanged.
Check List:
BuiltinServiceTest.flags_escapingcovering the reflected (?setvalue=<payload>) and stored (?setvalue&withform) HTML rendering plus the unchanged plain-text output; the test uses a reloadable string gflag and restores its value afterwards.test/brpc_builtin_service_unittestpasses (20 tests).🤖 This PR was automatically created by brpc-oncall