Repository navigation
fix(worker): pass worker checks; fix CORS origin validation and module-ID validation - #20
Merged
Merged
Conversation
…e-ID validation - CORS: echo the request origin only when it matches FRONTEND_URL instead of reflecting any origin, and drop Access-Control-Allow-Credentials (the API authenticates via Authorization: Bearer). Closes #4 - CORS: rebuild the response instead of mutating c.res.headers, which throws TypeError: immutable on Hono redirect responses - validation: accept the app's bare kebab-case module IDs (e.g. "linear-regression"); the previous domain/module-only rule would have rejected every real progress sync - database: throw typed ApiError subclasses so Hono forwards DB failures as 500 JSON instead of rejecting app.fetch() - tests: use the real ml_platform_db binding, fix the mockenv typo and bookmark fixtures; correct stale CORS/validation expectations. No test was deleted, skipped or weakened - ci: enable the worker type-check + test job. Closes #18 - chore: replace the real GA measurement ID in .env.example. Closes #16
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
Makes the Cloudflare Worker sub-project's checks pass and fixes two genuine bugs found while doing so — including the CORS vulnerability in #4. This also lets the worker job be enabled in CI (#18).
🐛 Real bugs fixed
worker/src/middleware/cors.ts) — Closes Worker CORS reflects any Origin with credentials enabled #4.getCorsHeaders(origin)echoed whateverOriginthe caller sent and always setAccess-Control-Allow-Credentials: true, so any website could make credentialedcross-origin requests to the auth API. Production
FRONTEND_URLwas never used.Now the origin is echoed only when it matches
FRONTEND_URL, otherwise theconfigured origin is returned (never
*), and the credentials header is gone(the API authenticates with
Authorization: Bearer, not cookies).c.res.headers.set(...)throwsTypeError: immutableon Hono's 302 redirects (the OAuth callback). It nowrebuilds the response from a copied
Headers, preserving status,Location, etc.isValidModuleIdrequired a
domain/modulepair, but the app sends bare IDs(
loadQuiz('decision-trees', …), each module'sconfig.json"id") — so everyprogress sync would have been rejected with a 400. It now accepts one or two
kebab-case segments.
app.fetch().worker/src/services/database.tsthrew plain objects, which Hono does not forward to
onError(onlyinstanceof Erroris). Throws now use the existing typedApiErrorhelpers, soDB failures return
500 { code: 'DATABASE_ERROR' }as intended.🔧 Test fixes (no test deleted, skipped or weakened)
DB:→ml_platform_db:in mock envs (stale binding name;wrangler.tomlandthe
Envinterface useml_platform_db).mockenv→mockEnvtypo.BookmarkWithParams[]type.lists — all origin-validation assertions kept unchanged.
validation.test.tsfixtures corrected to the real (bare) module-ID format, witha bare-ID case added to the
validateProgressDatavalid fixture as regressioncoverage.
🧹 Also
.env.examplewith theG-XXXXXXXXXXplaceholder.workerjob in.github/workflows/ci.yml.✅ Verification
npm run type-checknpm run test