Allow CORS for all subdomains under xmoj-script.uk#64
Merged
Conversation
Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-bbs/sessions/29dec5cb-37ff-47bc-8f8d-ed7d9a5947bb Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
PythonSmall-Q
May 2, 2026 07:34
View session
Reviewer's guide (collapsed on small PRs)Reviewer's GuideExtends the CORS origin allowlist to include any HTTPS subdomain of xmoj-script.uk while preserving existing rules for .xmoj-script.pages.dev and other domains. Sequence diagram for CORS validation with new xmoj-script.uk subdomainssequenceDiagram
actor Browser
participant Frontend as Frontend_subdomain_xmoj_script_uk
participant API as API_Server
Browser->>Frontend: Fetch https://sub.xmoj-script.uk/app
Frontend->>API: CORS preflight / API request with Origin: https://sub.xmoj-script.uk
API->>API: getAllowedOrigin(origin)
alt Origin matches xmoj_script_pages_dev
API-->>API: return origin
else Origin matches subdomain_xmoj_script_uk
API-->>API: return origin
else Origin matches xmoj_bbs_me_or_www_xmoj_tech
API-->>API: return origin
else No match
API-->>API: return null
end
alt Allowed origin returned
API-->>Frontend: Response with Access_Control_Allow_Origin: https://sub.xmoj-script.uk
Frontend-->>Browser: Response forwarded
else Origin not allowed
API-->>Frontend: Response without CORS headers / 4xx
Frontend-->>Browser: CORS blocked by browser
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
xmoj-script.ukregex only supports a single subdomain label (no additional dots), so if you truly need to allow 'any subdomain' (e.g.,foo.bar.xmoj-script.uk) you may want to update the pattern to support multiple labels rather than just[a-z0-9-]+. - Since
getAllowedOriginis accumulating multiple very similar regex checks, consider extracting a small helper or shared pattern builder for allowed hostnames to reduce duplication and make future domain additions less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `xmoj-script.uk` regex only supports a single subdomain label (no additional dots), so if you truly need to allow 'any subdomain' (e.g., `foo.bar.xmoj-script.uk`) you may want to update the pattern to support multiple labels rather than just `[a-z0-9-]+`.
- Since `getAllowedOrigin` is accumulating multiple very similar regex checks, consider extracting a small helper or shared pattern builder for allowed hostnames to reduce duplication and make future domain additions less error-prone.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR broadens the worker’s CORS allowlist in Source/index.ts so browser requests can also come from xmoj-script.uk hosts, alongside the existing allowed XMOJ-related origins. It fits into the codebase by extending the origin validation used for preflight handling and response CORS headers.
Changes:
- Add a new
getAllowedOriginrule forhttps://<subdomain>.xmoj-script.uk. - Keep the existing
pages.dev,xmoj-bbs.me, andwww.xmoj.techorigin rules unchanged.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (/^https:\/\/[a-z0-9-]+\.xmoj-script[a-z0-9-]*\.pages\.dev$/.test(origin)) { | ||
| return origin; | ||
| } | ||
| if (/^https:\/\/[a-z0-9-]+\.xmoj-script\.uk$/.test(origin)) { |
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.
Extends the CORS allowlist to permit requests from any subdomain of
xmoj-script.uk, alongside the existing*.xmoj-script*.pages.dev,xmoj-bbs.me, andwww.xmoj.techrules.Changes
Source/index.ts: Added a new regex match ingetAllowedOriginforhttps://<subdomain>.xmoj-script.ukorigins:Summary by Sourcery
New Features:
Summary by cubic
Extends the CORS allowlist to accept HTTPS requests from any subdomain of
xmoj-script.uk. Enforces subdomain-only (apex not allowed) and keeps existing rules for*.xmoj-script*.pages.dev,xmoj-bbs.me, andwww.xmoj.tech.Written for commit eddd19d. Summary will update on new commits.