Skip to content

fix(apigatewayv2): fix route priority, proxy errors, CORS, and dispatch#275

Merged
vieiralucas merged 2 commits intomainfrom
worktree-fix+cubic-batch3-apigw
Apr 12, 2026
Merged

fix(apigatewayv2): fix route priority, proxy errors, CORS, and dispatch#275
vieiralucas merged 2 commits intomainfrom
worktree-fix+cubic-batch3-apigw

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 12, 2026

Summary

  • De-prioritize ANY routes vs exact-method routes for same path
  • Deterministic stage resolution (sort by API ID) when multiple APIs share a stage name
  • Return 502 on malformed Lambda proxy response instead of silently defaulting to 200
  • Return 502 on invalid base64 body instead of silently falling back to raw bytes
  • Reject duplicate stage names in CreateStage with ConflictException
  • Require /v2/apis/* for management API dispatch (not just /v2/*)
  • Replace all .parse().unwrap() in CORS with safe fallbacks
  • Reflect matching Origin header in CORS preflight responses
  • Clamp negative timeout in HTTP proxy

Addresses unresolved Cubic findings from PRs #252, #253, #254, #255, #256.

Test plan

  • cargo clippy -p fakecloud-apigatewayv2 -- -D warnings passes
  • All 17 unit tests pass (1 new: test_exact_method_over_any)

Summary by cubic

Fixes API Gateway v2 routing, CORS, and proxy error handling to prevent silent defaults and panics. Stage resolution is now deterministic and management API dispatch is stricter.

  • Bug Fixes

    • Routing: exact-method routes outrank ANY for the same path.
    • Stage resolution: when multiple APIs share a stage name, pick deterministically by sorting API IDs.
    • Dispatch: require /v2/apis/* for management API (no longer any /v2/*).
    • CreateStage: reject duplicate stage names with ConflictException.
    • Lambda proxy: return 502 for invalid statusCode or invalid base64 body (no fallback to 200/raw bytes).
    • CORS preflight: reflect the matching Origin header; replace unsafe header parsing to avoid panics.
    • HTTP proxy: clamp negative timeout before casting.
  • Refactors

    • Extracted request recording into a helper to ensure requests (including failures) are logged.

Written for commit 69e37d4. Summary will update on new commits.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

…y errors, CORS, dispatch

- Router: de-prioritize ANY routes vs exact-method routes for same path
- Execute API: sort by API ID for deterministic stage resolution across APIs
- Lambda proxy: return 502 on malformed statusCode instead of defaulting to 200
- Lambda proxy: return 502 on invalid base64 body instead of silently falling back
- CreateStage: reject duplicate stage names with ConflictException
- Dispatch: require /v2/apis/* (not just /v2/*) for management API routing
- CORS: replace .parse().unwrap() with .parse().ok() to prevent panics
- CORS preflight: reflect matching request origin instead of always first configured
- HTTP proxy: clamp negative timeout before i64→u64 cast
- Extract record_request helper to enable recording failed requests
@vieiralucas vieiralucas force-pushed the worktree-fix+cubic-batch3-apigw branch from d3b2996 to 69e37d4 Compare April 12, 2026 13:44
@vieiralucas vieiralucas merged commit e69059b into main Apr 12, 2026
21 checks passed
@vieiralucas vieiralucas deleted the worktree-fix+cubic-batch3-apigw branch April 12, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant