Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llama_cpp/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def create_app(
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_origins=server_settings.cors_allow_origins,
allow_credentials=True if server_settings.cors_allow_origins != ["*"] else False,
Comment thread
vip0hc33-eng marked this conversation as resolved.
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.

allow_methods=["*"],
allow_headers=["*"],
)
Expand Down
7 changes: 4 additions & 3 deletions llama_cpp/server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama:
assert (
settings.hf_tokenizer_config_path is not None
), "hf_tokenizer_config_path must be set for hf-tokenizer-config"
chat_handler = llama_cpp.llama_chat_format.hf_tokenizer_config_to_chat_completion_handler(
json.load(open(settings.hf_tokenizer_config_path))
)
with open(settings.hf_tokenizer_config_path) as f:
chat_handler = llama_cpp.llama_chat_format.hf_tokenizer_config_to_chat_completion_handler(
json.load(f)
)

tokenizer: Optional[llama_cpp.BaseLlamaTokenizer] = None
if settings.hf_pretrained_model_name_or_path is not None:
Expand Down
4 changes: 4 additions & 0 deletions llama_cpp/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ class ServerSettings(BaseSettings):
default=None,
description="API key for authentication. If set all requests need to be authenticated.",
)
cors_allow_origins: List[str] = Field(
default=["*"],
description="Allowed CORS origins. Use ['*'] to allow all origins (not recommended for production).",
)
interrupt_requests: bool = Field(
default=True,
description="Whether to interrupt requests when a new request is received.",
Expand Down
Loading