Fix/cors configurable secure - #61
Merged
Merged
Conversation
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.
fix: configurable and secure CORS defaults
Description
Replaces hardcoded CORS configuration (allow_credentials=True, allow_methods=[""], allow_headers=[""]) with configurable fields via config.yaml and environment variables. Defaults are now secure by default.
Changes
Security:
cors_origins: default changed from [""] to [] (no cross-origin = secure)
cors_allow_credentials: default False (was hardcoded True)
cors_allow_methods: default ["GET","POST","PUT","DELETE","PATCH"] (was [""])
cors_allow_headers: default ["Authorization","Content-Type","X-API-Key"] (was ["*"])
Files modified:
src/ciberwebscan/config/models.py 4 new CORS fields in APIConfig + 4 validators
src/ciberwebscan/api/app.py:78-89 Middleware reads from config instead of hardcoded
docs/CONFIGURATION.md API section rewritten with CORS fields
docs/API.md CORS section, env vars, auth examples
examples/profiles/bugbounty.yaml CORS example with explicit domain
examples/profiles/pentest.yaml CORS example with explicit domain
Testing
ruff check + ruff format pass
Config loads CORS fields correctly from YAML
Env vars CIBERWEBSCAN_API_CORS_* work as expected
curl tests: allowed origin → 200 + CORS headers, disallowed origin → 400 "Disallowed CORS origin"
Notes
Backward-compatible: users with existing cors_origins: ["*"] in their config keep working
Default change only affects users without a config.yaml (the most insecure case currently)
No existing tests broken