feat(server): unify scan target param on target, keep url as REST alias#1152
Merged
Conversation
… alias
The scan target was named inconsistently across surfaces: the MCP
`scan_with_dalfox` tool and every response payload (`ResultPayload.target`,
the submit `{scan_id, target}`) used `target`, but the REST request body and
query string used `url`. Anyone wiring up both surfaces hit the mismatch.
Standardize on `target` and keep `url` working for existing REST clients:
- `ScanRequest.url` → `target` with `#[serde(alias = "url")]`, so POST `/scan`
and POST `/preflight` accept `{"target": ...}` (canonical) or `{"url": ...}`.
- GET `/scan` reads the `target` query param, falling back to `url`.
- MCP already used `target` — unchanged.
Backwards compatible: every existing client sending `url` (JSON body or query
string) keeps working; responses are unchanged.
Verified end-to-end against a live server: POST/GET with `target` and with the
`url` alias all return a scan_id, `/preflight` with `target` works, and a body
with neither field is a 400. Docs (integrations/server.md) updated to show
`target` with the alias noted; added serde-alias + GET-`target` unit tests.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Address the one behavior-change the review surfaced: a present-but-empty `target` query param (e.g. a templated `?target=&url=...`) shadowed a real `url` and 400'd. Filter empty target before the alias fallback so any caller still sending `url` keeps working. Covered with a test.
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.
Summary
Follow-up to the dogfooding finding that REST and MCP named the scan target differently. The MCP
scan_with_dalfoxtool and every response payload (ResultPayload.target, the submit{scan_id, target}) usedtarget, but the REST request body and query string usedurl. Anyone wiring up both surfaces hit the mismatch.Per the decision: standardize on
target, keepurlworking for existing REST clients.Changes
ScanRequest.url→targetwith#[serde(alias = "url")]— POST/scanand POST/preflightaccept{"target": ...}(canonical) or{"url": ...}(alias)./scanreads thetargetquery param, falling back tourl.target— unchanged.integrations/server.md) showtarget, with theurlalias noted.Backwards compatible: every existing client sending
url(JSON body or query string) keeps working; response shapes are unchanged.Verification (live server)
POST /scan {"target":...}POST /scan {"url":...}(alias)GET /scan?target=...GET /scan?url=...(alias)POST /scan {"options":{}}(no target)POST /preflight {"target":...}Testing
cargo build/cargo clippy --all-targetscleancargo test --lib— 1765 pass (addedtest_scan_request_accepts_target_canonical_and_url_alias,test_get_scan_handler_accepts_target_query_param)