fix(backend): tighten service-creation input validation#612
Merged
Conversation
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
validate_user_endpoint_url(url, hosted_mode, field)that always rejects query / fragment / userinfo / non-http(s) / over-2048-char URLs, and additionally rejects loopback / private / link-local / CGNAT / cloud-metadata targets via DNS resolution when running in production. Wired intoPOST /keys(catalog override + custom HTTP),PUT /keys/{id}, andPUT /endpoints/{id}. Skipped when the route is node-managed (the URL goes to the node agent, never to NyxID's outbound HTTP client).auth_key_name): Extend the existingbody-only check to coverheader,query, andpathmethods as well (the proxy needs a non-empty key name for all four to inject the credential into a named field). Centralized the rule inauth_method_requires_key_name/auth_key_name_required_messagehelpers and applied it increate_user_service,update_user_service,validate_update_inputs, adminPOST /services, andunified_key_service::create_key(the last one rejects before any partial endpoint / api-key rows are written, avoiding orphans).closes #597
closes #598
Notes for reviewers
validate_public_http_urlhelper, which already does the DNS-resolution / IP-class checks and is tested.create_keygained a newhosted_mode: boolparameter populated fromstate.config.is_production(). In-tree tests passfalse(so they continue exercising the lax dev path).auth_key_namecheck now uses.trim().is_empty(), so a whitespace-onlyauth_key_name: " "is rejected too.Test plan
cargo test(passes: 1790 backend + 277 CLI + 1 freshness)nyxid service add --custom --slug qa-cliw-local --label "QA local" --endpoint-url http://localhost:9999 --auth-method none --base-url <hosted> --output jsonreturns400 ValidationErrorinstead of silently creating the service.--endpoint-url 'https://httpbin.org/anything?x=1'returns400 endpoint_url must not contain a query string.--endpoint-url http://localhost:9999against a non-production backend still succeeds (dev workflow preserved).nyxid service add --custom ... --auth-method header --auth-key-name '' --credential-env QA_TOKEN ...returns400 ValidationErrorat create time instead of HTTP 500 on first proxy call.auth-method query/pathwith empty key name also rejected.bearer/basic/noneservices with emptyauth_key_namestill create successfully (the methods that don't need a key name).