Skip to content

fix: security hardening — file upload, JWT, CORS, headers#3975

Open
devrel-ditto wants to merge 1 commit intoava-labs:masterfrom
devrel-ditto:fix/security-batch
Open

fix: security hardening — file upload, JWT, CORS, headers#3975
devrel-ditto wants to merge 1 commit intoava-labs:masterfrom
devrel-ditto:fix/security-batch

Conversation

@devrel-ditto
Copy link
Contributor

Summary

Batch security fix addressing 4 issues. All changes are minimal and low-risk.

Changes

1. File upload MIME type validation (#3972)

Adds an allowlist of accepted file types to POST /api/file:

  • Images: png, jpeg, gif, webp, svg+xml
  • Documents: pdf
  • Video: mp4, quicktime

Rejects uploads with unrecognized MIME types to prevent storage of executable content (HTML, JS, etc.) on public blob storage.

2. JWT validation response trimming (#3974)

POST /api/validate-jwt-token no longer returns the full decoded token payload. Response now contains only valid and sub fields.

3. CORS scoping on API routes (#3973)

Restricts Access-Control-Allow-Origin on /api/* routes to https://build.avax.network (was *). Adds Vary: Origin header to prevent cache poisoning.

4. Security headers (#3967)

Adds standard security headers for all routes:

  • Strict-Transport-Security: 2-year max-age with preload
  • X-Content-Type-Options: nosniff
  • X-Frame-Options: DENY
  • Referrer-Policy: strict-origin-when-cross-origin
  • Permissions-Policy: deny camera, microphone, geolocation

Testing

  • File upload: existing uploads with valid types unaffected; test with a .html file to verify rejection
  • JWT endpoint: callers that relied on payload field will need updating (check if any exist)
  • CORS: verify Builders Hub frontend still works (same-origin requests unaffected). External consumers of public API routes (stats, validators) will be blocked — if any exist, those routes may need exemption
  • Headers: no functional impact, purely additive

Risk

Low. The CORS change is the most impactful — if external sites legitimately consume /api/*, they will break. Worth auditing before merge.

Resolves #3967, #3972, #3973, #3974
Supersedes #3968

…+ headers

- Add MIME type allowlist to file upload endpoint (images, PDFs, videos only)
- Remove full token payload from JWT validation response (return sub only)
- Add security headers: HSTS, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy
- Scope CORS on /api/* to build.avax.network origin with Vary: Origin

Resolves ava-labs#3972, ava-labs#3974, ava-labs#3973, ava-labs#3967
@vercel
Copy link

vercel bot commented Mar 17, 2026

@devrel-ditto is attempting to deploy a commit to the Ava Labs Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
builder-hub Ready Ready Preview, Comment Mar 18, 2026 0:10am

Request Review

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.

Missing security headers on build.avax.network

1 participant