mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #116] [MERGED] server: opt-in CORS for /v1/* (config "cors_origins") - a page on another origin can call the API from a browser #348
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#348
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/116
Author: @sociolog
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @mw00
Base:
main← Head:pr-cors-v1📝 Commits (1)
ba93d3dserver: opt-in CORS for /v1/* (config "cors_origins") - a page on another origin (a local chat client) can call the API from a browser📊 Changes
3 files changed (+165 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+5 -0)📝
serve/server.py(+52 -1)📝
serve/test_server.py(+108 -1)📄 Description
What
Opt-in CORS for
/v1/*, so a browser page served from another origin (a local chat client, for examplehttp://127.0.0.1:8090) can use the API. New config key"cors_origins": exact origins, or["*"]. Missing or empty:no CORS header at all, byte for byte as before.
It has the shape of the opt-in trusted-origin list Strata took in its #321 (without that PR's X-Forwarded-For / CF-*
origin bypass).
Why
A browser stops a page on another origin from calling
/v1/*unless the server answers the preflight and sendsAccess-Control-Allow-Origin. A chat page that is a single file served beside Maya (so not by Maya's own server) needseither a reverse proxy or this.
What it does
/v1/*: 204 withAllow-MethodsandAllow-Headers(it echoesAccess-Control-Request-Headers). Anything else stays 403, as before./v1/*answer to a listed origin (JSON, a stream, an error) carriesAccess-Control-Allow-Origin, andVary: Originfor an exact origin._own_pagestill refuses a foreign Origin, so alisted page may chat but may not change settings or run tools. Its docstring said the server never grants a
preflight; it now says it grants one to
cors_originson/v1/*only.["*"]is allowed. The docs say to set anapi_keywith it: otherwise any page you open can use your model.Checked
python -m unittest discover -s serve -p "test_*.py" -t .: 152 tests OK (3 skipped), 7 of them new(
CorsOptIn): unset = nothing changes; a listed page gets its preflight and the header on JSON and on a stream;another page gets nothing;
"*"; a trailing slash in the config; settings and the page stay closed; the config value.passes with it: it only touches
serve/server.py).serve/server.pyelsewhere and do not conflict with this (their conflicts with main are README.md andglm_model.cu, with or without this PR).Files: docs/DETAILS.md (+5 -0), serve/server.py (+52 -1), serve/test_server.py (+108 -1).
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.