Validate geocoding search query input (#527)#545
Open
maltehuebner wants to merge 1 commit into
Open
Conversation
The public /search/query proxy passed $request->query->get('query')
straight into Geocoder::query(string), so a missing parameter produced
a TypeError -> HTTP 500 instead of a 400. Add server-side validation:
trim the input and require a length between 2 and 128 characters,
returning HTTP 400 with a message otherwise. Non-scalar array input
(?query[]=x) is already rejected by Symfony's InputBag as a 400.
Co-Authored-By: Claude Opus 4.8 (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.
Addresses the input-validation half of #527.
Changes
TypeaheadController::searchActionnow trims thequeryparameter and validates its length (2–128 chars). Missing/empty/over-long input returns HTTP 400 with a JSON error instead of the previous HTTP 500 (GeocodeQuery::create(null)→TypeError, sinceGeocoder::query()is typedstring).?query[]=x) is already rejected as 400 by Symfony'sInputBag::get(), so no extra handling is needed.Deliberately not implemented (deferred)
symfony/rate-limiter). This requires adding the dependency plus aframework.rate_limiterconfig block and a boot-critical cache pool, and its behaviour can only be meaningfully verified against a running app with Redis. The container could not be booted in the review environment (the localvendor/is missingsymfony/runtime, sobin/consoleandWebTestCasecannot start), so I could not verify that the wiring compiles or that limiting actually triggers. Rather than commit unverifiable boot-critical config, this is left for a follow-up. Suggested config for the follow-up:RateLimiterFactoryInterface $searchLimiterand consume by client IP insearchAction, returning 429 when the limit is exceeded.requirements.queryis a query-string parameter, not a path segment, so route requirements do not apply.Verification
vendor/bin/phpunit --testsuite="Project Test Suite"— OK (121 tests)vendor/bin/phpstan analyse --no-progress— No errorsCloses #527
🤖 Generated with Claude Code