Skip to content

Add examples/cases/match_detail: minimal MatchDetail usage demo#9

Open
wuchulonly wants to merge 3 commits into
chainreactors:masterfrom
wuchulonly:feat/examples-match-detail
Open

Add examples/cases/match_detail: minimal MatchDetail usage demo#9
wuchulonly wants to merge 3 commits into
chainreactors:masterfrom
wuchulonly:feat/examples-match-detail

Conversation

@wuchulonly
Copy link
Copy Markdown
Contributor

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 introduces examples/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 EnableMatchDetail and the fact that MatchDetail.SendData is empty for SDK's passive matchers aren't obvious from the existing examples.

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.

Test plan

  • go build ./examples/cases/match_detail passes (verified in a downstream module that pins the same chainreactors/fingers and chainreactors/sdk versions; the SDK repo itself uses local-path replaces so a standalone go build here depends on the maintainer's monorepo checkout).
  • go vet ./examples/cases/match_detail passes.
  • Smoke-tested the matcher-detail flag flip in a downstream test (fEngine.MatchDetailEnabled == true after EnableMatchDetail()).

wuchulonly and others added 3 commits May 11, 2026 01:50
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>
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.

1 participant