Repository navigation
Fix: 4 issues (#1204, #1205, #1206, #1207) - #1283
Merged
fejilaup-cloud merged 2 commits intoOct 21, 2026
Merged
Conversation
Co-authored-by: Simple Agent <agent@simple.dev>
|
@knightqueen-sketch Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #1204
Closes #1205
Closes #1206
Closes #1207
Issues
#1204 Replace the Wildcard CORS Header With an Allowlist
#1205 Add GraphQL Depth and Complexity Limits
#1206 Explicitly Configure GraphQL Introspection
#1207 Protect the /metrics Endpoint
Summary
Keep the new configuration env-driven and default-safe: empty CORS allowlist means no CORS headers are emitted, introspection defaults off outside development, and metrics require a token or are only reachable on the internal port. Reuse the existing AuthError/IntoResponse pattern in auth.rs for the metrics token guard if convenient. Ensure the public router no longer mounts /metrics and that the test router in main.rs mirrors production wiring so the integration tests are meaningful. Verify async-graphql 7 exposes limit_depth/limit_complexity/disable_introspection on SchemaBuilder (they are available via the standard extensions in v7).
Changes
allowed_origins: Vec<String>field to MiddlewareConfig (default empty, populated from an env var such as CORS_ALLOWED_ORIGINS) and a helper that decides whether a request path is a public read route (e.g. GET on /v1/ip/, /v1/swap/, /graphql, /health, /version) versus admin/recovery routes (/v1/admin/, /v1/auth/recovery/). In cors_middleware, read the request Origin header before calling next.run, and only when the path is a public read route AND the origin matches the allowlist, insert Access-Control-Allow-Origin echoing that origin (plus Vary: Origin) along with the Allow-Methods/Allow-Headers/Expose-Headers headers; otherwise emit no CORS headers at all. Handle OPTIONS preflight for allowed origins. Add unit tests in this module asserting an unlisted origin receives no Access-Control-Allow-Origin header and that admin/recovery paths never receive CORS headers. (api-server/src/middleware_pipeline.rs).limit_depth(...),.limit_complexity(...)and.disable_introspection()when configured. Add tests that a query exceeding the depth limit and one exceeding the complexity limit are rejected with errors, and a test that with introspection disabled an introspection query returns an error while with it enabled it succeeds. (api-server/src/graphql.rs)require_metrics_tokenmiddleware reading METRICS_AUTH_TOKEN from env and comparing the Authorization header) and/or support serving metrics on a separate internal listener port (METRICS_PORT). Expose a helper that builds the internal metrics router so main.rs can mount it separately. Add a test that metrics_handler behind the guard returns 401 when no/invalid token is supplied and 200 with the correct token. (api-server/src/metrics.rs)metricscontainerPort (METRICS_PORT), change the prometheus.io/port annotation to the internal metrics port, and add METRICS_AUTH_TOKEN (from the existing secret) plus METRICS_PORT, CORS_ALLOWED_ORIGINS, GRAPHQL_MAX_DEPTH, GRAPHQL_MAX_COMPLEXITY and GRAPHQL_INTROSPECTION env entries so the new configuration is available in-cluster. (deploy/k8s/base/deployment.yaml)metricsport to the api-server Service (targetPort matching the metrics containerPort) so Prometheus can scrape it, and ensure the publichttpport no longer exposes /metrics. (deploy/k8s/base/service.yaml)