Skip to content

security: fix CORS misconfiguration and unclosed file handle#2

Closed
ghost wants to merge 1 commit into
mainfrom
security/fix-cors-and-resource-leak
Closed

security: fix CORS misconfiguration and unclosed file handle#2
ghost wants to merge 1 commit into
mainfrom
security/fix-cors-and-resource-leak

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 26, 2026

Opened by @roomote-v0 on behalf of J oz

Security Fixes

1. CORS Misconfiguration (HIGH)

The server was configured with allow_origins=["*"] combined with allow_credentials=True. Per the CORS specification, browsers will reject credentialed requests when the origin is a wildcard. More importantly, this configuration signals an intent to allow all origins with credentials, which is a security anti-pattern.

Fix: Added a configurable cors_allow_origins setting to ServerSettings and disabled allow_credentials when wildcard origins are used. Users can now restrict CORS origins in production by setting specific allowed origins.

2. Unclosed File Handle (LOW)

In model.py, json.load(open(...)) was used without a context manager, creating a resource leak where file handles might not be properly closed.

Fix: Wrapped in a proper with statement.


View task on Roo Code Cloud

- Make CORS origins configurable via cors_allow_origins server setting
- Disable allow_credentials when using wildcard origins (per CORS spec)
- Fix unclosed file handle in hf_tokenizer_config_path loading (model.py)
@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 26, 2026

Rooviewer Clock   See task

I've reviewed the PR and found an issue with the CORS validation logic.

  • Fix incomplete wildcard check for allow_credentials in app.py

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment thread llama_cpp/server/app.py
@vip0hc33-eng vip0hc33-eng marked this pull request as ready for review April 26, 2026 22:19
@vip0hc33-eng vip0hc33-eng deleted the security/fix-cors-and-resource-leak branch April 26, 2026 22:20
@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 26, 2026

Rooviewer Clock   See task

I've reviewed the PR and found an issue with the CORS validation logic.

  • Fix incomplete wildcard check for allow_credentials in app.py

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment thread llama_cpp/server/app.py
allow_origins=["*"],
allow_credentials=True,
allow_origins=server_settings.cors_allow_origins,
allow_credentials=True if server_settings.cors_allow_origins != ["*"] else False,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition only checks for an exact match of ["*"]. If cors_allow_origins is configured with multiple origins including a wildcard (e.g., ["*", "https://example.com"]), this evaluates to True and enables credentials, defeating the intended security fix. You should check if "*" is present in the list instead.

Suggested change
allow_credentials=True if server_settings.cors_allow_origins != ["*"] else False,
allow_credentials="*" not in server_settings.cors_allow_origins,

Fix it with Roo Code or mention @roomote and request a fix.

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.

2 participants