Skip to content

Commit

Permalink
⚠️ Major security update. ⚠️
Browse files Browse the repository at this point in the history
⚠️ CSRF Protection added to whole flaskBlog. ⚠️
  • Loading branch information
DogukanUrker authored Jul 30, 2023
2 parents de487b0 + bfa4dae commit 31d501e
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from routes.accountSettings import accountSettingsBlueprint
from routes.adminPanelComments import adminPanelCommentsBlueprint
from dbChecker import dbFolder, usersTable, postsTable, commentsTable
from flask_wtf.csrf import CSRFProtect

dbFolder()
usersTable()
Expand All @@ -38,6 +39,7 @@
app = Flask(__name__)
app.secret_key = secrets.token_urlsafe(32)
app.config["SESSION_PERMANENT"] = True
csrf = CSRFProtect(app)


@app.context_processor
Expand Down
1 change: 1 addition & 0 deletions templates/accountSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2>
</h2>
<h2>
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<button type="submit" name="userDeleteButton" class="toPanel textPrimary">
delete your account
</button>
Expand Down
1 change: 1 addition & 0 deletions templates/adminPanelComments.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3>
<div class="content" tag="content">{{comment[2]}}</div>
<section>
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="commentID" value="{{comment[0]}}" />
<button
type="submit"
Expand Down
1 change: 1 addition & 0 deletions templates/adminPanelUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1 class="textCenter">Users</h1>
</section>
<section class="stats">
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="userName" value="{{user[1]}}" />
<button
type="submit"
Expand Down
1 change: 1 addition & 0 deletions templates/changePassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.oldPassword(class_="input")}} {{form.password(class_="input")}}
{{form.passwordConfirm(class_="input")}}
<button type="submit" class="btn btnPrimary">change my password</button>
Expand Down
1 change: 1 addition & 0 deletions templates/changeUserName.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.newUserName(class_="input")}}
<button type="submit" class="btn btnPrimary">change my username</button>
</form>
Expand Down
2 changes: 2 additions & 0 deletions templates/createPost.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form formPost centeredHorizontally">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.postTitle(class_="input centeredHorizontally" , autocomplete="off")}}
{{form.postTags(class_="input centeredHorizontally" , autocomplete="off")}}
<small>(separete with comma)</small>
Expand Down
1 change: 1 addition & 0 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h1 class="textCenter">Posts</h1>
<section>
<a href="/editpost/{{post[0]}}" class="btn btnLink textPrimary">edit</a>
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="postID" value="{{post[0]}}" />
<button
type="submit"
Expand Down
1 change: 1 addition & 0 deletions templates/editPost.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form formPost centeredHorizontally">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.postTitle(class_="input centeredHorizontally" , autocomplete="off")}}
{{form.postTags(class_="input centeredHorizontally" , autocomplete="off")}}
<small>(separete with comma)</small>
Expand Down
1 change: 1 addition & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.userName(class_="input",autocomplete="off")}}{{form.password(autocomplete="off",class_="input")}}
<button type="submit" class="btn btnPrimary">Login</button>
<a href="/passwordreset/codesent=false" id="passwordReset"
Expand Down
1 change: 1 addition & 0 deletions templates/passwordReset.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{% if mailSent %} {{form.code(autocomplete="off",class_="input")}}
{{form.password(autocomplete="off",class_="input")}}
{{form.passwordConfirm(autocomplete="off",class_="input")}}
Expand Down
3 changes: 3 additions & 0 deletions templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ <h5 class="date">{{date}}</h5>
{% if author == session["userName"] %}
<div class="bottomBar">
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<button
type="submit"
class="btn btnLink textPrimary"
Expand All @@ -53,12 +54,14 @@ <h5 class="date">{{date}}</h5>
<p class="centeredHorizontally">{{comment[2]}}</p>
{% if session["userName"] == comment[3] %}
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="commentID" value="{{comment[0]}}" />
<button type="submit" name="commentDeleteButton">🗑️</button>
</form>
{% endif %} {% endfor %}
</div>
<form method="post" class="commentForm">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{% if session["userName"] %} {{form.comment(class_="comment")}}
<button type="submit" class="btnSubmit">comment</button>
{% else %}
Expand Down
1 change: 1 addition & 0 deletions templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock head %} {%block body%}
<div class="container">
<form method="post" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{{form.userName(class_="input" , autocomplete="off")}}
{{form.email(class_="input",autocomplete="off")}}
{{form.password(class_="input")}} {{form.passwordConfirm(class_="input")}}
Expand Down

0 comments on commit 31d501e

Please sign in to comment.