-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve Flask-WTF CSRF rule (#3264) * Improve Flask-WTF CSRF rules * Add fixtest * Add pattern-not for flask csrf tokens to django csrf rule (#3263) --------- Co-authored-by: Pieter De Cremer (Semgrep) <[email protected]>
- Loading branch information
1 parent
15a47b7
commit a40e5fa
Showing
5 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import flask | ||
from flask import response as r | ||
|
||
app = flask.Flask(__name__) | ||
# ruleid:flask-wtf-csrf-disabled | ||
app.config['WTF_CSRF_ENABLED'] = True | ||
|
||
# ruleid:flask-wtf-csrf-disabled | ||
app.config["WTF_CSRF_ENABLED"] = True | ||
|
||
# ok: flask-wtf-csrf-disabled | ||
app.config["WTF_CSRF_ENABLED"] = True | ||
# ok: flask-wtf-csrf-disabled | ||
app.config["SESSION_COOKIE_SECURE"] = False | ||
|
||
# ruleid: flask-wtf-csrf-disabled | ||
app.config.WTF_CSRF_ENABLED = True | ||
# ok: flask-wtf-csrf-disabled | ||
app.config.WTF_CSRF_ENABLED = True | ||
|
||
# DICT UPDATE | ||
################ | ||
|
||
app.config.update( | ||
SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf', | ||
# ruleid: flask-wtf-csrf-disabled | ||
WTF_CSRF_ENABLED = True, | ||
TESTING=False | ||
) | ||
|
||
# It's okay to do this during testing | ||
app.config.update( | ||
SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf', | ||
# ok: flask-wtf-csrf-disabled | ||
WTF_CSRF_ENABLED = False, | ||
TESTING=True | ||
) | ||
|
||
# FROM OBJECT | ||
################ | ||
|
||
# custom class | ||
appconfig = MyAppConfig() | ||
# ruleid: flask-wtf-csrf-disabled | ||
appconfig.WTF_CSRF_ENABLED = True | ||
|
||
app.config.from_object(appconfig) | ||
|
||
# this file itself | ||
SECRET_KEY = 'development key' | ||
# ruleid: flask-wtf-csrf-disabled | ||
WTF_CSRF_ENABLED = True | ||
|
||
app.config.from_object(__name__) | ||
|
||
# FROM MAPPING | ||
################ | ||
|
||
app.config.from_mapping( | ||
SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf', | ||
# ruleid: flask-wtf-csrf-disabled | ||
WTF_CSRF_ENABLED = True, | ||
) | ||
|
||
# It's okay to do this during testing | ||
app.config.from_mapping( | ||
SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf', | ||
# ok: flask-wtf-csrf-disabled | ||
WTF_CSRF_ENABLED = False, | ||
TESTING=True | ||
) | ||
|
||
@app.route("/index") | ||
def index(): | ||
return 'hello world' |
This file contains 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
This file contains 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