Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-PYRAMID-SEC-001 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects calls to Configurator.set_default_csrf_options() in Pyramid applications. This method controls CSRF protection globally. When called with require_csrf=False, it disables CSRF token validation across every view in the application, leaving all state-changing endpoints vulnerable to cross-site request forgery attacks.
Pyramid's CSRF protection works by requiring a valid token on POST, PUT, DELETE, and PATCH requests. Disabling it means any website can craft a form that submits to your application using the victim's browser cookies, performing actions on their behalf without their knowledge.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Cross-Site Request Forgery on All Endpoints
With CSRF protection disabled, an attacker can create a malicious page that submits forms to your Pyramid application. When an authenticated user visits the attacker's page, their browser sends cookies automatically, and the forged request executes with the victim's session.
Account Takeover via Password Change
A common CSRF attack target is the password change form. The attacker's page submits a hidden form to /change-password with a new password. Without CSRF protection, the request succeeds and the attacker owns the account.
Compliance Violations
PCI DSS, SOC 2, and OWASP all require CSRF protection for web applications handling sensitive data. Globally disabling it will fail any security audit.
How to Fix
Recommended remediation steps
- 1Never call set_default_csrf_options(require_csrf=False) in production. Pyramid enables CSRF protection by default.
- 2If specific views need CSRF exemption (webhooks, API endpoints with token auth), exempt them individually with require_csrf=False in the @view_config decorator
- 3Use Pyramid's built-in CSRF token mechanism with session.get_csrf_token() in templates
- 4For API endpoints using Bearer token authentication, exempt per-view rather than disabling globally
- 5Review all calls to set_default_csrf_options() in code review to confirm the configuration is intentional
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule matches all calls to set_default_csrf_options() via the pattern calls("*.set_default_csrf_options"). It fires on any invocation regardless of the arguments passed, since the presence of this call warrants review.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Frequently Asked Questions
Common questions about Pyramid CSRF Check Disabled Globally
New feature
Get these findings posted directly on your GitHub pull requests
The Pyramid CSRF Check Disabled Globally rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.