diff --git a/TouYube/apps/TouYube/templates/TouYube/callback.html b/TouYube/apps/TouYube/templates/TouYube/callback.html
new file mode 100644
index 0000000..ce2081e
--- /dev/null
+++ b/TouYube/apps/TouYube/templates/TouYube/callback.html
@@ -0,0 +1,14 @@
+{% extends "TouYube/base/base.html" %}
+{% load static %}
+
+{% block head %}
+ {{ block.super }}
+
+{% endblock %}
+
+{% block body %}
+
+{% endblock %}
diff --git a/TouYube/apps/TouYube/views.py b/TouYube/apps/TouYube/views.py
index 3666c35..bf9d596 100644
--- a/TouYube/apps/TouYube/views.py
+++ b/TouYube/apps/TouYube/views.py
@@ -135,3 +135,22 @@ def view_video_embed(request: WSGIRequest, video_id: UUID) -> HttpResponse:
"TouYube/video_embed.html",
dict(video=video)
)
+
+
+def view_attack_some(request: WSGIRequest) -> HttpResponse:
+ """
+ Allow for a some attack by allowing JavaScript as an argument that will later be executed in the website context
+ """
+
+ # check the method
+ if request.method != "GET":
+ return HttpResponseBadRequest()
+
+ # get the callback code
+ callback_js = request.GET["callback"]
+
+ return render(
+ request,
+ "TouYube/callback.html",
+ dict(callback_js=callback_js)
+ )
diff --git a/TouYube/configuration/settings.py b/TouYube/configuration/settings.py
index 83836d4..3a208e4 100644
--- a/TouYube/configuration/settings.py
+++ b/TouYube/configuration/settings.py
@@ -12,8 +12,6 @@ https://docs.djangoproject.com/en/5.0/ref/settings/
from pathlib import Path
-from django.views.decorators.csrf import csrf_exempt
-
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -144,7 +142,8 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# CORS_ALLOW_ALL_ORIGINS: bool = True
if not ENABLE_CROSS_ORIGIN_SECURITY:
- X_FRAME_OPTIONS = 'ALLOWALL'
+ X_FRAME_OPTIONS = 'ALLOWALL' # Allow to integrate the website anywhere
+ SESSION_COOKIE_HTTPONLY = False # Allow to access cookie in the JavaScript
# Login Settings
-LOGIN_URL: str = "login/"
+LOGIN_URL: str = "/login/"
diff --git a/TouYube/configuration/urls.py b/TouYube/configuration/urls.py
index af06fcf..4108432 100644
--- a/TouYube/configuration/urls.py
+++ b/TouYube/configuration/urls.py
@@ -30,6 +30,9 @@ urlpatterns = [
path('video/view//', apps.TouYube.views.view_video_full, name="video_full"),
path('video/embed//', apps.TouYube.views.view_video_embed, name="video_embed"),
+ # TODO(Faraphel): find a better path and names for an example
+ path('callback/', apps.TouYube.views.view_attack_some, name="callback_attack_some"),
+
path('admin/', admin.site.urls),
]
diff --git a/Witter/.gitignore b/Witter/.gitignore
index 7282326..4ec7116 100644
--- a/Witter/.gitignore
+++ b/Witter/.gitignore
@@ -1,3 +1,5 @@
# Django
db.sqlite3
+# Application
+.logs/
diff --git a/Witter/apps/Witter/templates/Witter/homepage.html b/Witter/apps/Witter/templates/Witter/csrf.html
similarity index 98%
rename from Witter/apps/Witter/templates/Witter/homepage.html
rename to Witter/apps/Witter/templates/Witter/csrf.html
index 4d21d25..3b6928e 100644
--- a/Witter/apps/Witter/templates/Witter/homepage.html
+++ b/Witter/apps/Witter/templates/Witter/csrf.html
@@ -2,7 +2,7 @@
{% block title %}{{ block.super }} - Homepage{% endblock %}
{% block body %}
- Homepage
+ CRSF
diff --git a/Witter/apps/Witter/templates/Witter/some.html b/Witter/apps/Witter/templates/Witter/some.html
new file mode 100644
index 0000000..3ab3c7f
--- /dev/null
+++ b/Witter/apps/Witter/templates/Witter/some.html
@@ -0,0 +1,26 @@
+{% extends "Witter/base/base.html" %}
+
+{% block title %}{{ block.super }} - Homepage{% endblock %}
+{% block body %}
+ SOME
+
+
+
+
+{% endblock %}
diff --git a/Witter/apps/Witter/views.py b/Witter/apps/Witter/views.py
index 8d26fc8..6db42ca 100644
--- a/Witter/apps/Witter/views.py
+++ b/Witter/apps/Witter/views.py
@@ -1,12 +1,55 @@
+import json
+from datetime import datetime
+
from django.core.handlers.wsgi import WSGIRequest
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponse
from django.shortcuts import render
+from django.views.decorators.csrf import csrf_exempt
-from apps.Witter import forms, models
+from configuration.settings import BASE_DIR
-def view_homepage(request: WSGIRequest) -> HttpResponse:
+# create the logging directory for the attacks
+LOG_DIRECTORY = BASE_DIR / ".logs"
+LOG_DIRECTORY.mkdir(exist_ok=True)
+
+LOG_SOME_DIRECTORY = LOG_DIRECTORY / "some"
+LOG_SOME_DIRECTORY.mkdir(exist_ok=True)
+
+
+def view_csrf(request: WSGIRequest) -> HttpResponse:
+ """
+ CSRF attack page
+ """
+
return render(
request,
- "Witter/homepage.html",
+ "Witter/csrf.html",
)
+
+
+def view_some(request: WSGIRequest) -> HttpResponse:
+ """
+ SOME attack page
+ """
+
+ return render(
+ request,
+ "Witter/some.html",
+ )
+
+
+@csrf_exempt
+def view_logger(request: WSGIRequest) -> HttpResponse:
+ """
+ Log all the information about a POST request
+ """
+
+ # get the path of the file were to log the information
+ log_path = LOG_SOME_DIRECTORY / datetime.now().strftime("%Y-%m-%d %H-%M-%S.req")
+ # log the request
+ with log_path.open("w", encoding="utf-8") as log_file:
+ # dump all the data in the file
+ print(f"Body: {request.body}", file=log_file)
+
+ return HttpResponse()
diff --git a/Witter/configuration/settings.py b/Witter/configuration/settings.py
index b239835..62bcef5 100644
--- a/Witter/configuration/settings.py
+++ b/Witter/configuration/settings.py
@@ -127,3 +127,8 @@ STATIC_ROOT = ".static"
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+
+# CORS Settings
+
+CORS_ALLOW_ALL_ORIGINS: bool = True
\ No newline at end of file
diff --git a/Witter/configuration/urls.py b/Witter/configuration/urls.py
index 0e66c44..67c9175 100644
--- a/Witter/configuration/urls.py
+++ b/Witter/configuration/urls.py
@@ -22,7 +22,10 @@ import apps.Witter.views
from configuration import settings
urlpatterns = [
- path('', apps.Witter.views.view_homepage, name="homepage"),
+ path('csrf/', apps.Witter.views.view_csrf, name="attack_csrf"),
+ path('some/', apps.Witter.views.view_some, name="attack_some"),
+
+ path('logs/', apps.Witter.views.view_logger, name="logger"),
path('admin/', admin.site.urls),
]