Skip to content

internal/graph: escape file and title strings written to dot - #1053

Merged
aalexand merged 5 commits into
google:mainfrom
Medios-lgtm:graph-escape-file-title-dot
Nov 4, 2026
Merged

aalexand merged 5 commits into
google:mainfrom
Medios-lgtm:graph-escape-file-title-dot

Conversation

@Medios-lgtm

@Medios-lgtm Medios-lgtm commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Mapping/object file names and the graph title come from the profile, but three sites in internal/graph/dotgraph.go wrote them into the generated dot without escaping: the digraph name in start(), the legend tooltip in addLegend(), and the File/Objfile components of a node label in multilinePrintableName(). A " in any of them closes the quoted attribute, so a crafted profile can inject dot attributes such as URL=, which Graphviz turns into an xlink:href in the SVG the web UI renders inline. The sibling node and edge tooltips already run through escapeForDot; this wraps the three missed sites the same way.

Repro: a profile whose mapping file name is lib" URL="javascript:alert(1) renders, before this change, an <a xlink:href="javascript:alert(1)"> in pprof -svg / -http; after it the quote is escaped and no such link appears. TestComposeWithNamesThatNeedEscaping now checks the escaping directly instead of against compose7.dot (removed); it fails on the three unescaped sites and passes with the fix.

Mapping/object file names and the graph title come from the profile and
are attacker-controlled, but three sites wrote them into the dot output
without escaping: the digraph name in start(), the legend tooltip in
addLegend(), and the File/Objfile components of a node label in
multilinePrintableName(). A double quote in any of them closes the
quoted attribute and lets the profile inject further dot attributes
(for example a URL=), which Graphviz emits as an xlink:href in the SVG
that the web UI renders inline. Wrap each site in escapeForDot, matching
the sibling node and edge tooltips that already escape.
aalexand
aalexand previously approved these changes Oct 21, 2026
@aalexand
aalexand enabled auto-merge (squash) October 21, 2026 22:56
@aalexand
aalexand disabled auto-merge October 21, 2026 22:57
@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.50%. Comparing base (3b76a86) to head (f42e1f8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1053      +/-   ##
==========================================
+ Coverage   73.47%   73.50%   +0.03%     
==========================================
  Files          46       46              
  Lines        7939     7941       +2     
==========================================
+ Hits         5833     5837       +4     
+ Misses       2084     2082       -2     
  Partials       22       22              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread internal/graph/dotgraph_test.go Resolved
…atNeedEscaping

Fold the file, objfile and title cases into the existing escaping test
and have it assert on the escaped and unescaped forms of each string
directly, so the compose7.dot golden is no longer needed.

@aalexand aalexand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this.

Comment thread internal/graph/dotgraph_test.go Resolved
Comment thread internal/graph/dotgraph_test.go Resolved
@aalexand
aalexand enabled auto-merge (squash) November 4, 2026 07:52
@aalexand
aalexand merged commit 393459d into google:main Nov 4, 2026
22 checks passed
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.

3 participants