René's URL Explorer Experiment


Title: server: inject CORS headers on Fastify-internal errors (#376) by melvincarvalho · Pull Request #421 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub

Open Graph Title: server: inject CORS headers on Fastify-internal errors (#376) by melvincarvalho · Pull Request #421 · JavaScriptSolidServer/JavaScriptSolidServer

X Title: server: inject CORS headers on Fastify-internal errors (#376) by melvincarvalho · Pull Request #421 · JavaScriptSolidServer/JavaScriptSolidServer

Description: Closes #376. Before $ curl -i -H 'Origin: https://example.com' 'https://example.test/foo%g1' HTTP/2 400 content-type: application/json content-length: 116 # (no access-control-* headers) {"error":"Bad Request","code":"FST_ERR_BAD_URL", ...} Browser-side: surfaces as a generic CORS / network error instead of the real 400, masking the actual failure mode (malformed percent-encoding). After $ curl -i -H 'Origin: https://example.com' 'https://example.test/foo%g1' HTTP/2 400 access-control-allow-origin: https://example.com access-control-allow-methods: GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS access-control-allow-headers: Accept, Authorization, Content-Type, DPoP, ... access-control-expose-headers: Accept-Patch, Accept-Post, ... access-control-allow-credentials: true access-control-max-age: 86400 content-type: application/json; charset=utf-8 {"error":"Bad Request","code":"FST_ERR_BAD_URL","message":"'/foo%g1' is not a valid url component","statusCode":400} Browser sees the real 400 and the actual FST_ERR_BAD_URL reason. The error field uses the HTTP status text ("Bad Request") via STATUS_CODES[statusCode], matching Fastify's default body shape so any pre-fix client that was parsing error keeps working. For non-browser requests (no Origin header), CORS headers are still set with Access-Control-Allow-Origin: * — consistent with the rest of the server, where the global onRequest hook sets CORS unconditionally. Root cause FST_ERR_BAD_URL is thrown by Fastify's URL parser BEFORE the request enters the normal handler chain. Direct probe confirmed neither setErrorHandler nor onSend hooks fire for this code path. Fastify writes the 400 directly via res.writeHead() / res.end() in onBadUrl() (node_modules/fastify/fastify.js:752–771) — bypassing every JSS CORS-injecting handler. Fix Configure Fastify's frameworkErrors option in createServer. This is the explicit hook Fastify provides for framework-level errors (FST_ERR_BAD_URL, FST_ERR_ASYNC_CONSTRAINT). When set, Fastify routes through this function instead of the direct-write path, giving us a Reply object to attach headers to. The handler: Always calls getCorsHeaders(request.headers.origin) and applies the full JSS CORS set — Allow-Origin mirrors the request Origin if present, falls back to * if absent Sends a JSON body with error: STATUS_CODES[statusCode] (HTTP status text, e.g. "Bad Request"), code (the Fastify error code, e.g. "FST_ERR_BAD_URL"), message, and statusCode — same shape as Fastify's default error body Test plan Three new integration tests in test/error-handler.test.js against a live JSS server: %g1 with Origin → 400, ACAO mirrors Origin, full CORS set, body error: "Bad Request" %g1 without Origin → 400, ACAO=*, full CORS set, body error: "Bad Request" Normal 404 path (no FST_ERR) → CORS still injected by the existing wildcard handler — confirms the new hook didn't displace existing behavior Full suite: 777 → 780 pass Refs #371 — Git-Protocol CORS header #374 — GIT_CORS_HEADERS const + 4xx return paths (the PR that surfaced this issue) Fastify frameworkErrors option

Open Graph Description: Closes #376. Before $ curl -i -H 'Origin: https://example.com' 'https://example.test/foo%g1' HTTP/2 400 content-type: application/json content-length: 116 # (no access-control-* hea...

X Description: Closes #376. Before $ curl -i -H 'Origin: https://example.com' 'https://example.test/foo%g1' HTTP/2 400 content-type: application/json content-length: 116 # (no acce...

Opengraph URL: https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b47ccb68-d2e9-c42a-cd97-840623c0e73d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC584:2CA452:1439093:19B940D:6B039F21
html-safe-nonce9ef7be28bc8ff39a62bd4072e47b86082d71ad487218c500724560c787f4264e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTg0OjJDQTQ1MjoxNDM5MDkzOjE5Qjk0MEQ6NkIwMzlGMjEiLCJ2aXNpdG9yX2lkIjoiMjI2MzM4MTc0NDU1MDEyNTM0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5e34bd18774006b0a22e0c61fae2c382fdd63acbe95b1b90a594fc78c09ec0ff
hovercard-subject-tagpull_request:3664297243
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
twitter:imagehttps://avatars.githubusercontent.com/u/65864?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/65864?s=400&v=4
og:image:altCloses #376. Before $ curl -i -H 'Origin: https://example.com' 'https://example.test/foo%g1' HTTP/2 400 content-type: application/json content-length: 116 # (no access-control-* hea...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/JavaScriptSolidServer/JavaScriptSolidServer git https://github.com/JavaScriptSolidServer/JavaScriptSolidServer.git
octolytics-dimension-user_id205442424
octolytics-dimension-user_loginJavaScriptSolidServer
octolytics-dimension-repository_id958025407
octolytics-dimension-repository_nwoJavaScriptSolidServer/JavaScriptSolidServer
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id958025407
octolytics-dimension-repository_network_root_nwoJavaScriptSolidServer/JavaScriptSolidServer
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FJavaScriptSolidServer%2FJavaScriptSolidServer%2Fpull%2F421%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FJavaScriptSolidServer%2FJavaScriptSolidServer%2Fpull%2F421%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=JavaScriptSolidServer%2FJavaScriptSolidServer
Reloadhttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
Reloadhttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
Reloadhttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
JavaScriptSolidServerhttps://github.com/JavaScriptSolidServer
JavaScriptSolidServerhttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer
Codehttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer
Issues165 (165)https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues
Pull requests14 (14)https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pulls
Actionshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/actions
Projectshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/projects
Security and qualityhttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/security
Insightshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/insights
Sign up for GitHub https://github.com/signup?return_to=%2FJavaScriptSolidServer%2FJavaScriptSolidServer%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FJavaScriptSolidServer%2FJavaScriptSolidServer%2Fissues%2Fnew%2Fchoose
melvincarvalhohttps://github.com/melvincarvalho
gh-pageshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/tree/gh-pages
issue-376-cors-on-fastify-errorshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/tree/issue-376-cors-on-fastify-errors
Conversation 8 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421
Commits 3 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/commits
Checks 0 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/checks
Files changed https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
Please reload this pagehttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
server: inject CORS headers on Fastify-internal errors (#376) https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#top
Show all changes 3 commits https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
8d0454a server: inject CORS headers on Fastify-internal errors (#376) melvincarvalho May 11, 2026 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/commits/8d0454a8accbd6a582e02e0ef662eae62a53ec81
e7d1133 Address copilot pass 1 on #421 melvincarvalho May 11, 2026 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/commits/e7d1133738a67b472a9b4c010ad2bec93c04e085
9220501 Address copilot pass 2 on #421 — doc cleanups melvincarvalho May 12, 2026 https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/commits/922050115d361095b6c8bb975a8f63875fb9d1d1
Clear filters https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
Please reload this pagehttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
Please reload this pagehttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files
server.js https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-79f4c7cdc0b026f6e556196f5911a449157807cffdb3f9d33f0b5404b4ffc2f3
error-handler.test.js https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-cfdf8499cfa8b03c96e953bd4f426f7612910fbbae36f8a109b9f0f329b48abe
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/blob/gh-pages/.github/CODEOWNERS#L12
src/server.jshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-79f4c7cdc0b026f6e556196f5911a449157807cffdb3f9d33f0b5404b4ffc2f3
View file https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/blob/922050115d361095b6c8bb975a8f63875fb9d1d1/src/server.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/{{ revealButtonHref }}
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-79f4c7cdc0b026f6e556196f5911a449157807cffdb3f9d33f0b5404b4ffc2f3
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-79f4c7cdc0b026f6e556196f5911a449157807cffdb3f9d33f0b5404b4ffc2f3
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-79f4c7cdc0b026f6e556196f5911a449157807cffdb3f9d33f0b5404b4ffc2f3
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/blob/gh-pages/.github/CODEOWNERS#L12
test/error-handler.test.jshttps://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-cfdf8499cfa8b03c96e953bd4f426f7612910fbbae36f8a109b9f0f329b48abe
View file https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/blob/922050115d361095b6c8bb975a8f63875fb9d1d1/test/error-handler.test.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/{{ revealButtonHref }}
https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/pull/421/files#diff-cfdf8499cfa8b03c96e953bd4f426f7612910fbbae36f8a109b9f0f329b48abe
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.