Add examples/cases/match_detail: minimal MatchDetail usage demo#9
Open
wuchulonly wants to merge 3 commits into
Open
Add examples/cases/match_detail: minimal MatchDetail usage demo#9wuchulonly wants to merge 3 commits into
wuchulonly wants to merge 3 commits into
Conversation
A minimal, copy-pasteable case showing how to obtain matcher details (matcher type/value, rule index, send_data) and the matched resource URL from a fingerprint hit. Key points the case illustrates: * EnableMatchDetail() must be called AFTER NewEngine(), because engine.Compile() resets each finger's EnableMatchDetail to the engine field's default value (false). * common.Framework.MatchDetail is read directly — no extra wrapper type is introduced. * match_url uses MatchDetail.SendData's "url=" segment when present (only populated by upstream consumers that do active probing), and falls back to resp.Request.URL for passive matches via DetectContent / MatchHTTP. Also introduces examples/cases/ as the home for cookbook-style minimal snippets, separate from the four top-level CLI tools. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds two complementary case variants alongside the existing cmd-style example so users can pick the form that best fits their integration: * examples/cases/match_detail/match_detail_test.go Test-based minimal demo using an inline Finger + httptest.Server. Verifies EnableMatchDetail() propagation end-to-end and serves as a reverse-control test (without EnableMatchDetail, MatchDetail is nil). Run with: go test ./examples/cases/match_detail -v * examples/cases/match_detail_helper/ Wrapper-style variant exposing a flat FingerMatch struct plus helpers (EnableMatchDetail, FlattenMatches, ExtractURL) and two cookbook functions (DetectFingersDetail, SprayWithCrawlAndFingerDetail). Comes with unit + e2e tests. Run with: go test ./examples/cases/match_detail_helper -v README updated to describe both styles and clarify that match_url must fall back to the request URL (or SprayResult.UrlString) for passive matchers, since MatchDetail.SendData is only populated by upstream active-probe flows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Adds
examples/cases/match_detail, a minimal copy-pasteable case showing how to obtain matcher details (matcher type/value, rule index, send_data) and the matched resource URL from a fingerprint hit. Also introducesexamples/cases/as a home for cookbook-style minimal snippets, separate from the four top-level CLI tools.Why
Downstream consumers (e.g. CyberHub) want to surface "which fingerprint matched on which path" to end users. The pieces are already in the SDK, but the timing of
EnableMatchDetailand the fact thatMatchDetail.SendDatais empty for SDK's passive matchers aren't obvious from the existing examples.Key points the case illustrates
EnableMatchDetail()must be called afterNewEngine(), becauseengine.Compile()resets each finger'sEnableMatchDetailto the engine field's default value (false).common.Framework.MatchDetailis read directly — no extra wrapper type is introduced.match_urlusesMatchDetail.SendData'surl=segment when present (only populated by upstream consumers that do active probing), and falls back toresp.Request.URLfor passive matches viaDetectContent/MatchHTTP.Test plan
go build ./examples/cases/match_detailpasses (verified in a downstream module that pins the samechainreactors/fingersandchainreactors/sdkversions; the SDK repo itself uses local-path replaces so a standalonego buildhere depends on the maintainer's monorepo checkout).go vet ./examples/cases/match_detailpasses.fEngine.MatchDetailEnabled == trueafterEnableMatchDetail()).