fix(parsers/go): classify entry points by signature, not return type or bare next(#129
Open
gadievron wants to merge 1 commit into
Open
fix(parsers/go): classify entry points by signature, not return type or bare next(#129gadievron wants to merge 1 commit into
gadievron wants to merge 1 commit into
Conversation
…or bare next( Two over-broad heuristics in classifyUnitType seeded false remote-web entry points: isHTTPHandler matched HTTP type patterns (incl. HandlerFunc) against the RETURN type, tagging factories like func Logger() gin.HandlerFunc as http_handler (F10); isMiddleware tagged any body containing the substring next( as middleware, catching Go 1.23 iterators / lexers / cursors (F7). Match handler patterns only against parameters, and gate the next( heuristic on an HTTP request signature. Genuine handlers and middleware remain classified (covered by new tests). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Findings F7 + F10 (MED). Coordinates with #126 ( |
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.
fix(parsers/go): classify entry points by signature, not return type or bare next(
Base:
master· Type: bug fix · Findings: F10 + F7 (MED)What
parsers/go/go_parser/extractor.go:isHTTPHandlerno longer matcheshttpHandlerPatternsagainst thereturn type (dropped
|| pattern.MatchString(returnsStr)); it matchesparameters only.
isMiddlewareno longer treats a barenext(substring as middleware;the
next(heuristic is now gated on the function having an HTTP requestsignature (
hasHTTPSignature && strings.Contains(code, "next(")). Thehttp.Handler/http.HandlerFuncreturn andnext.ServeHTTPsignals are kept.Why
Both heuristics over-matched, seeding false remote-web entry points:
func Logger() gin.HandlerFunchas no request param but matched thebare
HandlerFuncpattern against its return type → taggedhttp_handler. Ahandler is defined by what it receives, not what it returns.
next(— Go 1.23 range-over-func iterators(
iter.Pull→next()), lexers, cursors — was taggedmiddleware.Tests
parsers/go/go_parser/extractor_classify_test.go(new): factory returninghttp.HandlerFuncis nothttp_handler; iterator usingnext()is notmiddleware; a genuine(w, r)handler and genuinenext.ServeHTTPmiddlewareare still detected.
go test ./...passes.Reachability impact (verified empirically, base vs patched binary)
Function-id sets identical (no extraction loss). Reclassified units sampled and
confirmed all fake:
middleware1 → 0 (CutPrefix, a pull-iterator).http_handler108 → 89; all 19 removed are factoriesreturning
HandlerFunc(Logger,Recovery,BasicAuth, …) with no requestparam. All 89 retained handlers carry a genuine request/context param.
Zero genuine handlers or middleware lost.
Scope / siblings (deferred, documented)
Same defect class but out of scope here (tightening risks false negatives,
needs its own corpus):
isHTTPHandlerbody heuristicsw.Write(/Handler =(
:289-290) over-match any localwwith.Write(;isCLIHandleros.Argsbody match (
:318). Tracked for a follow-up.Upstream coordination
Only PR #126 also edits
extractor.go(different functions:typeToStringgenerics +
duplicateIDWarning). No hunk overlap withisHTTPHandler/isMiddleware; rebase trivially if #126 lands first. Binarygo_parsernotincluded — reviewers/CI rebuild from source.
Author notes
isHTTPHandlerparam-only loop;isMiddlewarehasHTTPSignaturegate on
next(.next()-using iterators thatpreviously became false entry points.
gin/echo/fiber handlers always take the request/context as a param; a return-only
match is a factory. Body heuristics still catch param-less real handlers.