Skip to content

Commit

Permalink
added flask-seasurf for csrf protection
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-peters committed Mar 18, 2021
1 parent 906a913 commit 922dd30
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ brotli==1.0.9
# via strong-but-simple-passwords (setup.py)
click==7.1.2
# via flask
flask-seasurf==0.3.0
# via strong-but-simple-passwords (setup.py)
flask-talisman==0.7.0
# via strong-but-simple-passwords (setup.py)
flask==1.1.2
# via strong-but-simple-passwords (setup.py)
# via
# flask-seasurf
# strong-but-simple-passwords (setup.py)
gunicorn==20.0.4
# via strong-but-simple-passwords (setup.py)
itsdangerous==1.1.0
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
version="0.1.0",
packages=find_packages(),
include_package_data=True,
install_requires=["flask", "flask-talisman", "whitenoise", "brotli", "gunicorn"],
install_requires=[
"flask",
"flask-talisman",
"flask-seasurf",
"whitenoise",
"brotli",
"gunicorn",
],
)
4 changes: 4 additions & 0 deletions strong_but_simple_passwords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask
from flask_talisman import Talisman
from flask_seasurf import SeaSurf
from whitenoise import WhiteNoise
from pathlib import Path
from .config import get_config_from_env_vars
Expand All @@ -17,6 +18,9 @@ def create_app(config=None):

app.add_url_rule("/", "index", view_func=views.index, methods=("GET", "POST"))

# add CSRF protection
SeaSurf(app)

# use whitenoise to serve static files
static_root = Path(__file__).parent / "static/"
app.wsgi_app = WhiteNoise(app.wsgi_app, root=static_root, prefix="static/")
Expand Down
1 change: 1 addition & 0 deletions strong_but_simple_passwords/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ <h3>2. Only keep the first 3 letters of each word</h3>
<h3>3. Put a random symbol somewhere in between</h3>
</li>
</ol>
<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
<button type="submit">Generate password!</button>
</form>
</main>
Expand Down

0 comments on commit 922dd30

Please sign in to comment.