-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add csrf_protection app with someviews with protection
- Loading branch information
leonardo.leano
committed
Nov 11, 2020
1 parent
0a74526
commit ee9caf9
Showing
12 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CsrfProtectionConfig(AppConfig): | ||
name = 'csrf_protection' |
Empty file.
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,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
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,27 @@ | ||
<header> | ||
CSRF INITIAL PAGE | ||
</header> | ||
<p>The project is configured with the Middleware:</p> | ||
<p>django.middleware.csrf.CsrfViewMiddleware</p> | ||
<div> | ||
Submit Without CSRFTOKEN - to view without protection | ||
<form action="{% url 'csrf_protection:without_protection' %}" method="post" > | ||
<input type="submit" value="Submit"> | ||
</form> | ||
<div> | ||
|
||
<div> | ||
Submit Without CSRFTOKEN - to view with standard protection (should popup a 403) | ||
<form action="{% url 'csrf_protection:with_standard_protection' %}" method="post" > | ||
<input type="submit" value="Submit"> | ||
</form> | ||
<div> | ||
|
||
|
||
<div> | ||
Submit With CSRFTOKEN - to view with standard protection | ||
<form action="{% url 'csrf_protection:with_standard_protection' %}" method="post" > | ||
{% csrf_token %} | ||
<input type="submit" value="Submit"> | ||
</form> | ||
<div> |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,10 @@ | ||
from django.urls import path | ||
from csrf_protection import views | ||
|
||
app_name = 'csrf_protection' | ||
|
||
urlpatterns = [ | ||
path("", views.csrf_index, name='csrf_index'), | ||
path("without_protection/", views.without_protection, name='without_protection'), | ||
path("with_standard_protection/", views.with_standard_protection, name='with_standard_protection'), | ||
] |
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,47 @@ | ||
from django.shortcuts import render | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
def csrf_index(request): | ||
html_data={} | ||
return render(request, "csrf_protection/index.html",html_data) | ||
|
||
@csrf_exempt | ||
def without_protection(request): | ||
""" | ||
without_protection | ||
url: csrf/without_protection/ | ||
url-shortcut: "csrf_protection:without_protection" | ||
Parameters | ||
---------- | ||
request : [type] | ||
[description] | ||
Returns | ||
------- | ||
[type] | ||
[description] | ||
""" | ||
html_data={} | ||
return render(request, "csrf_protection/index.html", html_data) | ||
|
||
def with_standard_protection(request): | ||
""" | ||
without_protection | ||
url: csrf/without_protection/ | ||
url-shortcut: "csrf_protection:with_standard_protection" | ||
Parameters | ||
---------- | ||
request : [type] | ||
[description] | ||
Returns | ||
------- | ||
[type] | ||
[description] | ||
""" | ||
html_data={} | ||
return render(request, "csrf_protection/index.html", html_data) |
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