Improve GraphQL fingerprinting with specificity scoring#5
Improve GraphQL fingerprinting with specificity scoring#5
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the GraphQL add-on’s engine fingerprinting to use a tiered strategy that prefers high-confidence header indicators (with optional quick verification) and otherwise falls back to pattern-based detection using specificity scoring to reduce false positives.
Changes:
- Refactored
fingerprint()to perform an initial probe, header-based detection/verification, then scored pattern matching. - Added new unit tests covering definitive header detection, header-hint verification, and fallback behavior.
- Added
*.hprofto.gitignore.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
addOns/graphql/src/main/java/org/zaproxy/addon/graphql/GraphQlFingerprinter.java |
Adds tiered header detection, quick verification, and specificity-scored pattern detection. |
addOns/graphql/src/test/java/org/zaproxy/addon/graphql/GraphQlFingerprinterUnitTest.java |
Updates an existing test expectation and adds new tests for header-based detection/verification. |
.gitignore |
Ignores Java heap dump files (*.hprof). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot review again |
All previous review feedback has been addressed and resolved:
The code compiles successfully and is ready for re-review. |
c4a3142 to
3a0d709
Compare
f0affeb to
c8eed25
Compare
|
@copilot update the PR description based on the current state of the branch |
Updated PR description to reflect current implementation after the "Second opinion" commit (c8eed25). The tiered header-based detection has been simplified to focus on pattern-based detection with specificity scoring and descending order iteration only. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot are there literal strings used multiple times which should be converted to constants? It’s okay if no change is warranted simply reply with a comment if that’s the case. |
No changes warranted. The literal strings in the code are either:
Extracting these wouldn't improve maintainability since they serve different purposes in different contexts. |
|
@copilot what about repeated literal occurrences of framework/engine names? |
No changes warranted for framework/engine names. Analysis shows: Framework names: Each of the 36 framework names (like "tartiflette", "hasura", "apollo") is used only once as a map key in the fingerprinters registration. One instance ("inigo") appears 3 times total, but extracting constants for single-use identifiers would add boilerplate without improving maintainability. JSON field names: Standard GraphQL response fields like "data" (6 uses), "extensions" (3 uses), and "errors" (2 uses) are used in different contexts throughout detection methods. These are well-known GraphQL standard field names, and their literal form aids readability in fingerprinting logic. The current approach keeps the code clear and maintainable without unnecessary abstraction. |
1ca02f1 to
2a39087
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
69803d7 to
3d103a6
Compare
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
3d103a6 to
b9803bb
Compare
Overview
Current GraphQL fingerprinting uses sequential pattern matching with first-match-wins approach, which can cause generic patterns to shadow specific ones, leading to false positives.
This PR implements specificity-based scoring and descending order iteration for GraphQL framework detection to improve accuracy and reduce false positives.
Key Changes
1. Specificity Scoring System
Each framework fingerprint is assigned a specificity score (0-100) based on pattern uniqueness:
2. Descending Order Iteration
Fingerprint checks are executed in descending specificity order:
3. Record-Based Type Safety
Introduced
FingerprintCheckrecord to encapsulate:BooleanSupplier)Architecture
Benefits
Backward Compatibility
check*Engine()methods remain unchangedTesting
Related Issues
N/A
Original prompt
Improve GraphQL Fingerprinting with Header-Based Detection and Specificity Scoring
Overview
Enhance the GraphQL add-on's fingerprinting mechanism to use a tiered detection strategy that leverages HTTP response headers and implements specificity scoring for pattern-based detection. This improves both speed and accuracy of framework identification.
Current Issues
Changes Required
1. Add Detection Result Records
Create two new record types in
GraphQlFingerprinter.java:2. Refactor
fingerprint()MethodReplace the current implementation with a tiered detection strategy: