Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DDD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Opis Zadania:**
- Niniejsze zadania miało na celu przedstawić założenia modelu Domain Driven Design dla fragmentu aplikacji bankowej. Schemat zawarty poniżej obrazuje zależności między agregatami, encjami i obiektami wartości dla dziedziny (bounding context) uwierzytelniania użytkowników. Zilustrowany fragment pokazuje przepływ informacji od utworzenia konta użytkownika, przypisania mu roli, aż po podjęcie się próby zalogowania do serwisu i zarejestrowania daty udanego zalogowania do banku online.
![diagram przedstawiający schemat Domain Driven Design dla zadania 01. Tworzenie bezpiecznego oprogramowania - Jan Konarski](DDD_Diagram.png "Diagram")

**Przyjęte założenia / Integracje:**
- W przypadku Bounding Contextu dla Uwierzytelniania, zakładamy, że każdy klient w banku przy rejestracji uzyskuje swoje konto użytkownika.
- Z racji na to, w przypadku pojawienia się kontekstu Klientów, istniałaby relacja Klienci Banku -> Uwierzytelnianie (Klient-Użytkownik)
- Każdy zarejestrowany użytkownik otrzymuje swoją rolę składającą się z: Typu (np. Klient / Pracownik), uprawnień oraz encji opisującej ID Roli w bazie.
- Agregat Logowania rejestruje wszystkie podjęte przez użytkowników (udane) zalogowania. Innymi słowy, sprawdzamy kto się zalogował i kiedy.
- Autoryzacja jest agregatem, który w sposób logiczny łączy ze sobą: Dane logującego się użytkownika, jego uprawnienia oraz timestamp zalogowania się do serwisu.
- Autoryzacja posiada również licznik podjętych prób logowania, po którego przekroczeniu (np. 3) system podejmuje kolejnych prób zalogowania użytkownika do chwili odblokowania konta.
- Autoryzacja integrowałaby się z Bounding Contextem dla Stanu Konta użytkownika, bądź Transakcji. Po udanym uwierzytelnieniu, użytkownik uzyskiwałby dostęp do wyświetlania swoich funduszy i wykonywania transakcji.
Binary file added DDD_Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions Python/Flask_Book_Library/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ ENV FLASK_RUN_HOST=0.0.0.0
# Expose the port the app runs on
EXPOSE 5000

# Uruchamiamy aplikację
CMD ["flask", "run"]
# Uruchamiamy aplikację
# Edit: This solves an issue when you can't install flask via docker (happens sometimes)
CMD ["python", "-m", "flask", "run", "--host=0.0.0.0"]
20 changes: 17 additions & 3 deletions Python/Flask_Book_Library/project/books/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import render_template, Blueprint, request, redirect, url_for, jsonify
from flask import render_template, Blueprint, request, redirect, url_for, jsonify, flash
from project import db
from project.books.models import Book
from project.books.forms import CreateBook

import re

# Blueprint for books
books = Blueprint('books', __name__, template_folder='templates', url_prefix='/books')
Expand Down Expand Up @@ -32,8 +32,22 @@ def list_books_json():
def create_book():
data = request.get_json()

new_book = Book(name=data['name'], author=data['author'], year_published=data['year_published'], book_type=data['book_type'])
sanitized_name = data.get('name', '').strip()
sanitized_author = data.get('author', '').strip()
allowed_pattern = r"^[A-Za-z0-9\s\-\':,\.!]+$"

# DB Allows max 64 characters for these fields, let's limit that. We also get rid of |safe to prevent rendering malicious HTML.
# We don't trust the data from user input fields, thus we sanitize it first nevertheless.
if not re.match(allowed_pattern, sanitized_name) or len(sanitized_name) > 64:
print('Invalid book name')
return jsonify({'error': f'Invalid book name'}), 400 # Additional verification for the length and data sanitization, but removing |safe from HTML is enough in this case.

if not re.match(allowed_pattern, sanitized_author) or len(sanitized_author) > 64:
print('Invalid author name')
return jsonify({'error': f'Invalid author name'}), 400

new_book = Book(name=sanitized_name, author=sanitized_author, year_published=data['year_published'], book_type=data['book_type'])

try:
# Add the new book to the session and commit to save to the database
db.session.add(new_book)
Expand Down
4 changes: 2 additions & 2 deletions Python/Flask_Book_Library/project/templates/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h1 class="my-4">Books</h1>
<!-- Loop through books and display each book -->
{% for book in books %}
<tr>
<td>{{ book.name | safe }}</td>
<td>{{ book.author | safe }}</td>
<td>{{ book.name}}</td> <!-- Source of all evil... | safe, NEVER use it, unless input is sanitized. -->
<td>{{ book.author}}</td>
<td>{{ book.year_published }}</td> <!-- Display Year Published -->
<td>{{ book.book_type }}</td> <!-- Display Book Type -->
<td>
Expand Down
4 changes: 2 additions & 2 deletions Python/Flask_Book_Library/project/templates/customers.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h1 class="my-4">Customers</h1>
<!-- Loop through customers and display each customer -->
{% for customer in customers %}
<tr>
<td>{{ customer.name | safe }}</td>
<td>{{ customer.city | safe }}</td> <!-- Display 'city' instead of 'author' -->
<td>{{ customer.name }}</td> <!-- We don't want | safe here as well. -->
<td>{{ customer.city }}</td> <!-- Display 'city' instead of 'author' -->
<td>{{ customer.age }}</td> <!-- Display 'age' -->
<td>
<a href="#" class="btn btn-warning btn-sm" onclick="editCustomer({{ customer.id }})">Edit</a>
Expand Down
4 changes: 2 additions & 2 deletions Python/Flask_Book_Library/project/templates/loans.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ <h1 class="my-4">Loans</h1>
<!-- Loop through loans and display each loan -->
{% for loan in loans %}
<tr>
<td>{{ loan.customer_name | safe }}</td>
<td>{{ loan.book_name | safe }}</td>
<td>{{ loan.customer_name }}</td>
<td>{{ loan.book_name }}</td>
<td>{{ loan.loan_date }}</td>
<td>{{ loan.return_date }}</td>
<td>
Expand Down
16 changes: 16 additions & 0 deletions XSS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**Przykłady wystąpień podatności XSS:**
![Udokumentowany wynik podatności XSS, przykład 1 - Jan Konarski](XSS_1.png "XSS_Vulnerability_1")
![Udokumentowany wynik podatności XSS, przykład 2 - Jan Konarski](XSS_2.png "XSS_Vulnerability_2")
**Przykłady wstrzyknięć:**
```
- <BODY ONLOAD=alert(’XSS’)>
- <script>alert(1)</script>
- <div style="font-family:'foo&#10;;color:red;';">LOL
- <svg><script ?>alert(1)
- I kilka innych, niektóre tworzą iframe'y, których trudno się pozbyć, w tym wypadku administrator musi usunąć rekord z bazy danych aplikacji.
```

Sposób rozwiązania podatności dla aplikacji do wypożyczania książek:
- Sprawdzenie długości ciągu znakowego dla pól formularza.
- Wykorzystanie zapytania Regex, w celu eliminacji znaków specjalnych pozwalających na wykonanie kodu HTML'owego.
- Wykorzystanie funkcji, które potraktują kod jako tekst.
Binary file added XSS_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added XSS_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.