Skip to content

fix(pprofhandler): use exact path matching to prevent prefix-based route confusion#2262

Open
toller892 wants to merge 1 commit into
valyala:masterfrom
toller892:fix/pprof-strict-path-matching
Open

fix(pprofhandler): use exact path matching to prevent prefix-based route confusion#2262
toller892 wants to merge 1 commit into
valyala:masterfrom
toller892:fix/pprof-strict-path-matching

Conversation

@toller892

Copy link
Copy Markdown

Problem

PprofHandler uses for matching pprof endpoint paths. This means paths like incorrectly match the handler, matches , etc.

Fixes #2258

Fix

Switch from to for the four named handlers (cmdline, profile, symbol, trace). For runtime profile names in the default case, check that the path either exactly matches or has a trailing slash boundary.

Changes:

  • : Replace with for exact path matching
  • : Add tests verifying that malformed paths with extra suffixes don't match specific handlers

Testing

All existing functionality preserved — exact paths still resolve correctly. Malicious/malformed paths with extra suffixes no longer match specific handlers.

…ute confusion

PprofHandler previously used bytes.HasPrefix for matching pprof endpoint
paths, which meant /debug/pprof/cmdlineEvil would incorrectly match the
cmdline handler. Switch to bytes.Equal for the four named handlers
(cmdline, profile, symbol, trace) and add proper boundary checking for
runtime profile names in the default case.

Fixes valyala#2258
"github.com/valyala/fasthttp/fasthttputil"
)

func TestPprofHandler_PathMatching(t *testing.T) {

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.

Can you please remove the test. This is such a simple change, it doesn't need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: pprofhandler imprecise path matching exposes debug data

2 participants