-
Notifications
You must be signed in to change notification settings - Fork 10
fix: harden security — configurable CORS origin, role escalation, unauthenticated seed #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zikunz
wants to merge
1
commit into
alphaonelabs:main
Choose a base branch
from
zikunz:fix/security-hardening
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider avoiding global mutable state for CORS initialization.
The current approach works but has a few considerations worth noting:
globalstatement modifying_CORS_ORIGIN_INITIALISEDis discouraged in Python best practices.env.ALLOWED_ORIGINcould vary (e.g., during hot config updates), this pattern won't pick up changes.A cleaner approach would be to compute the headers at response time or use a helper that returns the complete headers dict:
♻️ Suggested refactor: Compute CORS headers per-request
Then update response helpers (
json_resp,_unauthorized_basic,serve_static) to acceptenvand use_cors_headers(env).That said, if simplicity and minimal code churn are priorities, the current implementation is functional and achieves the security goal. The fallback to
"*"is documented and intentional per the PR objectives.🧰 Tools
🪛 Ruff (0.15.7)
[warning] 1136-1136: Using the global statement to update
_CORS_ORIGIN_INITIALISEDis discouraged(PLW0603)
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I considered the per-request approach but it would require threading
envthroughjson_resp,ok,err,_unauthorized_basic, andserve_static, touching many call sites. For a focused security fix, I preferred minimal churn. I am happy to refactor in a follow-up if the maintainers prefer that pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zikunz— That's a completely reasonable trade-off. Keeping the diff focused on the security fix rather than introducing a broad refactor across multiple helpers is a sound engineering decision. The current implementation is functional and achieves the intended goal.If you'd like, I can open a follow-up issue to track the per-request CORS header refactor so it doesn't get lost. Just let me know!