Fix/env variable underscore mapping - #50
Merged
Merged
Conversation
The ConfigLoader mapped every underscore in an env var name to a dot, so fields that contain underscores (command_injection, max_attempts, requests_per_second, etc.) could never be overridden via environment variables and were silently ignored. Map env vars by walking the Pydantic schema (longest field match first), keep the legacy underscore-to-dot fallback for compatibility, and support the double-underscore convention (CIBERWEBSCAN_HTTP__RATE_LIMIT__ADAPTIVE) to disambiguate section boundaries. Unmappable variables are ignored with a debug log instead of risking a config-wide fallback. Also update the CLI integration test helper to disable command injection and subdomain attacks and cap retries, keeping scans within the 30s subprocess timeout (SQLi tests went from ~50s to ~9s).
get_origin returns types.UnionType (not typing.Union) on Python 3.11+, so Optional nested models like ProxyConfig were never recognized as nested and whole-section env keys (e.g. CIBERWEBSCAN_HTTP_PROXY) leaked into the config and could trigger a silent full fallback to defaults. Also validate legacy fallback paths against the schema and log env vars that cannot be mapped, and log validation errors before the fallback.
Cover the schema-guided resolution, the double-underscore convention, whole-section rejection (e.g. CIBERWEBSCAN_HTTP_PROXY), the debug log for unmappable variables and the error log + defaults fallback for invalid values.
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.
Summary
Fix
ConfigLoaderenvironment variable mapping so that config fields containing underscores can be overridden viaCIBERWEBSCAN_env vars, and unmappable/invalid variables are logged instead of being silently ignored.Problem
ConfigLoader._load_envreplaced every underscore in the env var name with a dot (_→.), which caused:CIBERWEBSCAN_ATTACK_COMMAND_INJECTION,CIBERWEBSCAN_HTTP_RETRY_MAX_ATTEMPTS,CIBERWEBSCAN_HTTP_RATE_LIMIT_ADAPTIVE, etc. mapped to non-existent paths (attack.command.injection) and were silently ignored.command_injection/subdomainvia env vars, so--sqlialso ran the command injection attack; combined with the test server returning 500s for SQLi payloads, the retry logic (exponential backoff) plus the adaptive AIMD rate limiter pushed each scan to ~50s →subprocess.TimeoutExpiredafter 30s.CIBERWEBSCAN_HTTP_PROXYproduced aValidationErrorand the loader fell back to defaults with no log.Changes
src/ciberwebscan/config/loader.pyCIBERWEBSCAN_ATTACK_COMMAND_INJECTION→attack.command_injection.__) to explicitly mark section boundaries:CIBERWEBSCAN_HTTP__RATE_LIMIT__REQUESTS_PER_SECOND→http.rate_limit.requests_per_second(previously agreed solution, seedocs/CONFIGURATION.md)._→.) is now validated against the schema; unmappable vars — including whole sections — are ignored and logged at debug level:Ignoring env var ... does not map to a config key.ProxyConfig | None) across Python 3.10–3.12 (types.UnionTypevstyping.Union).tests/unit/config/test_loader.py(new, 27 tests): legacy mapping, underscore-containing fields,__convention, unmappable vars (ignored + logged), invalid values, case-insensitivity.tests/integration/cli/test_attack_cli.py: the helper now also disablessubdomainandcommand_injectionand caps retries to keep scans within the 30s subprocess timeout.docs/CONFIGURATION.md,.env.example, andAGENTS.md.Verification