0% found this document useful (0 votes)
29 views76 pages

05 - Form, Authentication, Session, and Cookie

Uploaded by

Fransisca Ellya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views76 pages

05 - Form, Authentication, Session, and Cookie

Uploaded by

Fransisca Ellya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Form, Authentication,

Session, and Cookie


Tim Pengajar PBP
Review
Django Models
• Models are a set of data stored to be processed in our apps. We store them in form of tables that connect
to one another. We can create, read, update, and delete (CRUD) data from the tables using several
specific command instructions called SQL.
Post
• Do you know or remember what is object?
Person author

display_name content

phone_number published_date

• A model class == a database table Person


• A model instance == a database table row display_name phone_number

Kak PeBePe +628123456

Budi +6281676732

3
Django Admin
• By default, the admin site url is http://localhost:8000/admin/

4
HTTP Requests
• The most commonly used HTTP request methods are GET, POST, PUT,
PATCH, and DELETE. These are equivalent to the CRUD operations (create,
read, update, and delete).
▪ GET: GET request is used to read/retrieve data from a web server. GET returns an HTTP
status code of 200 (OK) if the data is successfully retrieved from the server.
▪ POST: POST request is used to send data (file, form data, etc.) to the server. On successful
creation, it returns an HTTP status code of 201.
▪ PUT: A PUT request is used to modify the data on the server. It replaces the entire content
at a particular location with data that is passed in the body payload. If there are no resources
that match the request, it will generate one.
▪ PATCH: PATCH is similar to PUT request, but the only difference is, it modifies a part of the
data. It will only replace the content that you want to update.
▪ DELETE: A DELETE request is used to delete the data on the server at a specified location.

https://www.geeksforgeeks.org/different-kinds-of-http-requests/
5
Passing Argument
Passing Arguments
Request with
Your Webserver Environment ARGUMENTS

Run
# manage.py Internet
Web
Merged of html Page

ARGUMENTS
Request with
template and
Value from Extracted

Page
Web
process arguments
from Request

index.html views.py
style.css It’s your python
script.js code

Value from process views.py Access to URL (on Browser):


https://[appname].pbp.cs.ui.ac.id/ 7
Passing Argument Methods
POST:
● Appends form-data inside the body of the HTTP request (data is not
shown is in URL)
● Form submissions with POST cannot be bookmarked

GET:
• Never use GET to send sensitive data! (will be visible in the URL)
• Useful for form submissions where a user want to bookmark the
result
• GET is better for non-secure data, like query strings in Google

PUT : untuk request

8
Form
About Form
<form action=[URL DESTINATION] method=[METHOD]>
<input type=[INPUT TYPE] other attributes> <form action="http://www.sesuatu.com/proses"
method="POST">
....
Name: <input type="text">
.... <input type="submit" value="Submit">
</form>
<input type=[INPUT TYPE] other attributes>
</form>

URL DESTINATION :
Posting data to URL endpoint

METHOD :
Method on passing variables to URL DESTINATION (GET or POST)

INPUT & INPUT TYPE:


Data attributes from Browser to Server

10
Submission Flows
Browser Server
User
Generate HTTP Request Receive HTTP Request
Type Address: to http://host/path
http://host/path Display HTML Layout to Which views.py to handle path?
User Generate HTML page FORM
Generate HTTP Request, Receive HTTP Request
Insert Form Which views.py to handle path?
Method, and arguments
to URL Destination Do Whatever you want to do in this
based on HTML page step
FORM
Generate HTML page
Display HTML Layout to
User

11
Django HTML Form
(Example Form definition in forms.py)
class Input_Form(forms.ModelForm):

class Meta:

model = Person

fields = ['display_name']

error_messages = {

'required' : 'Please Type'

input_attrs = {

'type' : 'text',

'placeholder' : 'Nama Kamu'

display_name = forms.CharField(label='', required=False, max_length=27,


widget=forms.TextInput(attrs=input_attrs))

12
Django HTML Form
(Import from forms.py in views.py)
from .forms import Input_Form

def formulir(request):

response = {'input_form' : Input_Form}

return render(request, 'index.html', response)

13
Django HTML Form
(Merge HTML parts from forms.py in HTML
template)

Full html to render


penting untuk security
Cross-Site Request Forgery

14
Django HTML Form
(Generated HTML parts from forms.py)
forms.py HTML template
class Input_Form(forms.ModelForm):
class Meta:
model = Person
fields = ['display_name’]
error_messages = {
'required' : 'Please Type’
}
input_attrs = {
'type' : 'text',
'placeholder' : 'Nama Kamu’
}
display_name = forms.CharField(label='', required=False,
max_length=27, widget=forms.TextInput(attrs=input_attrs))

Generated HTML parts

Note that each form field


has an ID attribute set to
id_<field-name>

15
Django HTML Form
(Validate POST arguments based on forms.py)

views.py

16
Authentication and Authorization
Authentication and Authorization
● Authentication is the process of verifying who
you are: login
● Authorization is the process of verifying that you
have access to something

18
Question
Do we need both authentication and authorization?
Butuh agar tidak sembarang orang bisa masuk, klo authorization, misalkan ada siswa dan dosen yang memiliki hak akses yang berbeda.
Authorization untuk mengatur role para pengunjung.
Authentication is hard
Trying to write your own login system is difficult:
● How are you doing to save your password securely?
● How do you help with forgotten password?
● How do you make sure users set a good password?

Solution: Reuse Django User/Login module.

20
Django Framework With Authentication
Session
Your Webserver Environment Authentication/ Request
Authorization
Run
# manage.py Internet
Web
Merged of html Page
template and
Value from Extracted

Request
Page
Web
process arguments
from Request

index.html views.py
style.css It’s your python
script.js code

Value from process views.py Access to URL (on Browser):


https://[appname].pbp.cs.ui.ac.id/ 21
Reuse Django Framework Users Object
● Core of the authentication system
● Primary attributes of the default users are:
username, password, email, first_name, last_name
● Creating users
from django.contrib.auth.models import User
user = User.objects.create_user(‘pebepe', ‘[email protected]', ‘pbppassword’)
user.save()

● Creating superusers
$ python manage.py createsuperuser --username=kakpebepe [email protected]

22
Changing Password

• Django does not store raw (clear text) passwords on the user model,
but only a hash
• Do not attempt to manipulate the password attribute of the
user directly.
• A helper function is used when creating a user.
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username=‘pewe')
>>> u.set_password('new password')
>>> u.save()

Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that
represents the original string. Eg: hash(‘ini password saya’) == ‘AF3627731ABE63FF’
23
How to log a user in?
from django.contrib.auth import authenticate, login

def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
# Register in Session
# Redirect to a success page.
...
else:
# Return an 'invalid login' error message.
# Sometimes return HTTP 403

...

24
Alternative login mechanism
● By using available libraries ?
● Open Authentication (OAuth) ?

25
OAuth (Open Authentication)
● OAuth is a standard for user authentication
● For users:
○ It allows a user to log into a website like AirBnB via some other
service, like Gmail or Facebook
● For developers:
○ It lets you authenticate a user without having to implement log in
○ Examples: "Log in with Facebook"

26
OAuth2
● Companies like Google, Facebook, Twitter, and GitHub have OAuth2 APIs:
○ Google Sign-in API
○ Facebook Login API
○ Twitter Login API
○ GitHub Apps/Integrations

● OAuth2 is standardized, but the libraries that these companies provide are
all different.
● You must read the documentation to understand how to connect via their
API.

27
Session and Cookie
Komunikasi antar website pake HTTP dengan sifat stateless sehingga agar user berada di satu jalur menggunakan sessions dan cookie.
Session

● Session: an abstract concept to represent a series of HTTP request


and responses between a specific Web browser and server
○ HTTP doesn’t support the notion of a session
● How to implement Session concept?
○ Implement some code in ServerSide and ClientSide programming
■ ServerSide programming using Server Session Database
■ ClientSide programming using Cookie or LocalStorage
○ Server Session and Cookies need to work together to keep the session alive

29
Why a webserver need to handle sessions?
Why a web user needs to keep their session?
Browser 1 WebServer Browser 2

REQ: Hi I’m Unyil

RESP: Hallo Unyil

REQ: Hi I’m Pak Ogah

RESP: Hallo Pak Ogah


REQ: Who am I ?
RESP: Pak Ogah

A World WITHOUT Session


30
Why a webserver need to handle sessions?
Why a web user needs to keep their session?
Browser 1 WebServer Browser 2 empty

empty

REQ: Hi I’m Unyil


1. ABC = Unyil
RESP: Hallo Unyil
(SESS ID: ABC)
Store
REQ: Hi I’m Pak Ogah
Local ID:
ABC 1. ABC = Unyil
2. XYZ = Pak Ogah RESP: Hallo Pak Ogah
Fetch (SESS ID: XYZ) Local ID:
Local ID REQ: Who am I ? (SESS: ABC) XYZ

RESP: Pak Unyil


Who is ABC ?
1. ABC = Unyil
2. XYZ = Pak Ogah

A World WITH Session


31
Why a webserver need to handle sessions?
Why a web user needs to keep their session?
Browser 1 WebServer Browser 2 empty

empty

REQ: Hi I’m Unyil


1. ABC = Unyil
RESP: Hallo Unyil
(SESS ID: ABC)
Store
REQ: Hi I’m Pak Ogah
Local ID:
ABC 1. ABC = Unyil
2. XYZ = Pak Ogah RESP: Hallo Pak Ogah
Use Fake
(SESS ID: XYZ) Local ID:
Session REQ: Who am I ? (SESS: XYZ) XYZ
ID: XYZ
RESP: Pak Ogah
Who is XYZ ?
1. ABC = Unyil
2. XYZ = Pak Ogah

Using Fake Session ID (Session forgery)


NB: Do not try this at anywhere 32
Cookie
● Small amount of information sent by a web server to a browser and then sent
back by the browser on future page requests
● Cookies are used to:
○ Authentication
○ User tracking
○ Maintaining user preferences
● A cookie’s data consists of a single name/value pair (like dictionary), sent in the
header of the client’s HTTP GET or POST request

33
Myths and Facts about Cookies

Myths Facts
● Like worms or viruses that can erase data from ● Only data, not program code
user harddisk

● A form of spyware that can steal personal ● Cannot erase or read information from the user’s
information computer

● Generate popups and spam ● Usually anonymous (don’t contain personal


information)

34
Storing a Cookie
• Session cookie (default): temporary cookie
• Stored in the browser memory
• When the browser is closed, it will be erased
• Can’t be used for tracking long-term information
• Safer, only browser can access
• Persistent cookie:
• Stored in a file on the browser’s computer
• Can track long term information
• Less secure: users or programs can open cookie files
Please try:
Open multiple tab for the same website
Open multiple browser for the same website, 35
Server Session
• Server Session in Django, consists of
• Database (a model to keep session data)
• Webserver automatic handling
■ Read cookie parameter passed by Browser
■ Fetch / store data in session model
■ Modify information in the session
■ Send corresponding cookie back to Browser
• Implementation in Django:
• https://developer.mozilla.org/en-US/docs/Learn/Server-
side/Django/Sessions#Enabling_sessions
• https://developer.mozilla.org/en-US/docs/Learn/Server-
side/Django/Sessions#Using_sessions

36
Security Risks
OWASP Top 10 Web Application Security Risks
The OWASP (Open Source Foundation for Application Security) Top
10 is a standard awareness document for developers and web
application security. It represents a broad consensus about the most
critical security risks to web applications. (https://owasp.org/www-
project-top-ten/)
A01:2021-Broken Access Control - CSRF
CSRF (Cross Site Request
Forgery) adalah sebuah
tipe vulnerability di mana
seseorang bisa
melakukan request dari
origin yang tidak
seharusnya.
A01:2021-Broken Access Control - CSRF
Salah satu mitigasi untuk menghindari CSRF adalah dengan melakukan
implementasi token CSRF. Dengan token CSRF yang disertakan pada
request, sebuah web bisa memastikan bahwa request yang diterima
merupakan request yang dapat dipercaya. Token CSRF dibuat
menggunakan algoritma kriptografi yang aman sehingga tidak bisa di-
generate secara sembarang.
A01:2021-Broken Access Control - CSRF
● Django has built-in protection against most types of Cross
Site Request Forgery (CSRF) attacks
● Activated by default on MIDDLEWARE parameter in
settings.py. The 'django.middleware.csrf.CsrfViewMiddleware'
will be executed before any view

41
A01:2021-Broken Access Control - CSRF
● CSRF in HTML Template Form field:
<form action="." method="post">
{% csrf_token %}
</form>

● CSRF in views.py:
With CSRF check:
def my_view(request):
# my implementation goes here
return render(request, "a_template.html")

Without CSRF check:


@csrf_exempt
def my_view(request):
# my implementation goes here
return render(request, "a_template.html")

42
A01:2021-Broken Access Control - IDOR
IDOR (Insecure Direct Object Reference) adalah sebuah vulnerability di
mana seseorang bisa melakukan enumerasi terhadap ID sebuah object
yang ada. IDOR juga bisa terjadi jika sebuah object tidak memiliki
authorization yang baik.
A01:2021-Broken Access Control - IDOR
Solusi untuk menghindari IDOR adalah untuk mengimplementasikan
authorization yang baik dan benar terhadap sebuah object dalam API. ID
dari sebuah object juga bisa diubah menggunakan tipe data yang tidak
mudah dienumerasi, misalnya UUIDv4, UUIDv7, dan GUID.
A01:2021-Broken Access Control - CORS
Misconfig
CORS (Cross Origin Resource Sharing) adalah sebuah mekanisme browser
supaya bisa memperbolehkan origin lain melakukan request ke sebuah
website/API. Jika konfigurasi tidak dilakukan dengan benar, seorang
attacker bisa saja melakukan request ke endpoint internal yang tidak
seharusnya bisa diakses oleh jaringan luar.
A01:2021-Broken Access Control - CORS
Misconfig
Salah satu prinsip yang bisa digunakan untuk memperbaiki konfigurasi
CORS adalah Principle of Least Privileges, di mana konfigurasi yang
ditentukan hanya membuka akses untuk origin dan method yang
diperlukan saja. Hindari penggunaan konfigurasi dengan sifat
“enable/allow all” dan “wildcard”.
A02:2021-Cryptographic Failures
Salah satu vulnerability yang masuk di kategori ini adalah Use of Hard-
coded Password. Salah satu contoh konkret pada PBP adalah secret key
Django yang belum diubah dari default dan turut di-push pada GitHub
sehingga ter-expose ke publik.
A02:2021-Cryptographic Failures - Practical
Examples
Mengutip dokumentasi Django
(https://docs.djangoproject.com/en/5.1/topics/signing/):
“When you create a new Django project using startproject, the
settings.py file is generated automatically and gets a random
SECRET_KEY value. This value is the key to securing signed data – it is
vital you keep this secure, or attackers could use it to generate their
own signed values.”
A03:2021-Injection - XSS
XSS (Cross Site Scripting) adalah sebuah vulnerability di mana seseorang
bisa melakukan injeksi kode Javascript yang akan dieksekusi oleh client.
Masalah yang bisa terjadi dari vulnerability ini adalah oknum attacker
bisa saja mencuri cookies dari pengguna yang sudah melakukan login ke
sebuah website.

Description Input: <img src=x onerror=alert(1)>


A03:2021-Injection - XSS
Salah satu mitigasi paling mudah untuk menghindari XSS adalah untuk
selalu melakukan sanitization terhadap semua user input. Content
Security Policy (CSP) juga dapat digunakan untuk menghindari XSS, di
mana atribut dan tag yang biasa digunakan untuk melakukan XSS dapat
dibatasi penggunaannya.
A03:2021-Injection - XSS
● Django’s Built in Security Features Cross Site Scripting (XSS) Protection
● XSS attacks allow a user to inject client side scripts into the browsers of other users
● Using Django templates protects you against the majority of XSS attacks
● Using is_valid() in Django templates, forms.py and views.py
>>> data = {“subject”: “hello”,
... “message”: “<script>alert(‘Hacked’);</script>“,
... “sender”: “[email protected]”,
... “cc_myself”: True}
>>> f = ContactForm(data)
>>> f.is_valid()

51
A03:2021-Injection - XSS
● Django templates escape specific characters which are particularly dangerous to HTML
● While this protects users from most malicious input, it is not entirely foolproof, eg:

<div class={{ var }} >Halo</div>

● What happened if “var” was set to

“class1 onmouseover=alert(‘Hacked’)”

<div class=class1 onmouseover=alert(‘Hacked’)> Halo </div>

Note: be very careful when storing HTML in the database, especially when that HTML is
retrieved and displayed.

52
A03:2021-Injection - SQL Injection
SQL Injection bisa terjadi jika user input tidak divalidasi dan di-sanitize
dengan baik yang mengakibatkan terjadinya operasi SQL yang tidak
seharusnya. Oknum attacker bisa saja melakukan operasi INSERT,
UPDATE, DELETE, dan lain-lain untuk mengubah data yang ada di
database.

query: SELECT * FROM users WHERE


email = '[email protected]' OR 1 = 1 --
' AND password = '******';
komen = --
A03:2021-Injection - SQL Injection
Mitigasi terhadap SQL Injection:

● Prepared Statements
SELECT * FROM users WHERE email = ? AND password = ?;
(MySQL)
● Database Specific Defenses
Oracle DB: ESAPI.encoder().encodeForSQL(new
OracleCodec(), str);
MySQL: SELECT QUOTE('test''case');
A03:2021-Injection - SSTI
SSTI (Server Side Template Injection) adalah sebuah vulnerability di mana
seseorang bisa memanfaatkan library templating untuk melakukan injeksi
kode yang akan dieksekusi di server. Attacker bisa saja memanfaatkan
vulnerability ini untuk mengakses file di server atau bahkan mendapatkan
akses server tersebut.
A03:2021-Injection - SSTI
Mitigasi untuk SSTI adalah dengan tidak memperbolehkan user untuk
membuat atau melakukan modifikasi template. Jika memang
dibutuhkan, user input harus selalu melewati sanitization sebelum
dimasukkan ke template.
A04:2021-Insecure Design - Error Message
Kegagalan pada autentikasi bisa memberikan informasi yang berpeluang
membantu seorang attacker. Pada contoh berikut, seorang attacker
menjadi tahu bahwa username yang dicoba sudah benar. Hal ini dapat
menjadi masalah jika tidak ada sistem blokir untuk percobaan login
sehingga memungkinkan dilakukan brute-force terhadap password.
A04:2021-Insecure Design - Error Message
Mitigasi dari vulnerability ini adalah dengan tidak memberikan informasi
sensitif dalam error message yang ditampilkan di client. Hal ini bisa
dicapai dengan memberikan error message yang ambigu.
Dari contoh sebelumnya, error message tersebut bisa diubah menjadi
“Sorry, incorrect username or password”.
A04:2021-Insecure Design - Plaintext Storage of
a Password
Credentials yang disimpan pada basis data dalam bentuk plaintext juga
merupakan salah satu bentuk insecure design. Dalam kasus terburuk,
apabila basis data yang digunakan untuk menyimpan data terbobol
maka credentials pengguna juga ikut bocor dan dapat disalahgunakan.
A04:2021-Insecure Design - Plaintext Storage of
a Password
Bentuk mitigasi yang bisa dilakukan adalah dengan menyimpan
credentials pengguna dalam bentuk hash, umumnya menggunakan
algoritma Bcrypt. By default, hal ini sudah diimplementasikan
menggunakan User model di Django.
A04:2021-Insecure Design - Clear Text Storage
of Sensitive Information
Contoh lain dari insecure design adalah penyimpanan informasi sensitif
tanpa adanya usaha enkripsi (atau usaha enkripsi yang sangat
minimum) pada tempat penyimpanan data yang kurang aman, misalnya
cookies.
base64.decode(“ZmFsc2U=”) = “false”
base64.encode(“true”) = “dHJ1ZQ==”
A04:2021-Insecure Design - Clear Text Storage
of Sensitive Information
Solusi untuk menghindari vulnerability ini adalah dengan menyimpan
informasi sensitif di server. Namun, jika informasi sensitif tersebut
harus disimpan di client, informasi tersebut harus melalui medium yang
aman dan terenkripsi, seperti token JWT, di mana pengguna bisa
melihat, tetapi tidak bisa mengubah informasi tersebut.
A05:2021-Security Misconfiguration
Salah satu contoh misconfiguration keamanan di Django adalah dengan
membiarkan variabel “DEBUG” bernilai “True” pada produk yang dirilis.
Hal ini membuka banyak sekali celah untuk aktor pengancam melihat
seluk-beluk dari produk yang dirilis.
A05:2021-Security Misconfiguration
Selain melihat endpoint, attacker juga bisa melihat file structure dan
stacktrace dari error yang diberikan.
A06:2021-Vulnerable and Outdated Components
Vulnerability ini terjadi karena library dan komponen lain yang
digunakan oleh aplikasi tidak di-update secara berkala dan bisa saja
versi library yang belum di-update itu memiliki vulnerability yang bisa
disalahgunakan.
A07:2021-Identification and Authentication
Failures
Vulnerability yang masuk ke dalam kategori ini adalah Improper
Authentication. Salah satu contoh dari vulnerability ini adalah
memperbolehkan pengguna untuk menggunakan password yang lemah
(contoh: admin dan password123). Attacker bisa memanfaatkan
vulnerability ini untuk melakukan percobaan login secara brute-force
dengan password-password yang umum digunakan.
A07:2021-Identification and Authentication
Failures
Untuk memaksa pengguna membuat password yang lebih kuat, dibutuhkan
rules yang ketat dalam pembuatan password. Contohnya, password harus 8
karakter atau lebih, password harus memiliki setidaknya 1 karakter angka
dan 1 karakter simbol, password tidak boleh mirip dengan username,
password tidak boleh menggunakan common password, dan lain-lain.
A08:2021-Software and Data Integrity Failures
Salah satu vulnerability di kategori ini adalah Insecure Deserialization. Contohnya
adalah jika sebuah JSON tidak di-deserialize secara baik dan benar, ada
kemungkinan seseorang bisa melakukan prototype pollution (untuk Javascript) dan
class pollution (untuk Python). Seseorang bisa saja melakukan perubahan atribut
pada superclass dari sebuah class yang jika ada pembuatan instance baru dari class
tersebut maka akan terpolusi dengan atribut yang telah dibuat.
A08:2021-Software and Data Integrity Failures
Mitigasi paling ampuh untuk menghindari vulnerability ini adalah
dengan tidak menerima input yang tidak dipercaya untuk dilakukan
deserialization. Jika memang diperlukan, perlu ada proteksi tambahan
seperti integrity checking, memberlakukan restriction yang ketat,
melakukan deserialization dalam environment yang memiliki low privilege,
dan lain-lain.
A09:2021-Security Logging and Monitoring Failures

Vulnerability yang masuk ke dalam kategori ini berhubungan dengan


logging. Contohnya adalah event-event yang menyangkut authentication,
authorization, dan akses ke resources sensitif tidak dimasukkan ke dalam
log secara lengkap. Warning dan errors yang kurang jelas juga bisa
menjadi vulnerability karena bisa mengurangi kemampuan monitoring
aktivitas yang mencurigakan.
A09:2021-Security Logging and Monitoring Failures

Vulnerability ini dapat dimitigasi dengan cara melakukan logging


terhadap authorization, authentication, dan aksi sensitif lain dengan
konteks yang cukup agar mudah dilacak jika dibutuhkan untuk analisis
dan investigasi.
A10:2021-Server-Side Request Forgery
SSRF adalah sebuah vulnerability di mana seseorang bisa mengubah
sebuah request yang dilakukan sebuah server. Contohnya adalah jika
sebuah aplikasi memperbolehkan menggunakan gambar dari sebuah
link. Jika link yang diberikan pengguna tidak divalidasi dengan baik,
seseorang bisa saja memasukkan link yang hanya bisa diakses oleh
internal yang memungkinkan terjadinya kebocoran informasi sensitif.
A10:2021-Server-Side Request Forgery
Mitigasi SSRF dapat dilakukan dengan menggunakan Principle of Least
Privileges di mana sebuah whitelist dapat dibuat untuk mengatur
domain/origin mana saja yang dapat diakses oleh sebuah aplikasi.
Additional Materials
Model Relationship
Pelajari contoh model relationship yang ada di Django Documentation

• Many-to-many relationships
- To define a many-to-many relationship, use ManyToManyField.
- In this example, an Article can be published in multiple Publication objects,
and a Publication has multiple Article objects.
• Many-to-one relationships
- To define a many-to-one relationship, use ForeignKey.
- In this example, a Reporter can be associated with many Article objects, but
an Article can only have one Reporter object.
• One-to-one relationships
- To define a one-to-one relationship, use OneToOneField.
- In this example, a Place optionally can be a Restaurant.
75
References
● Django Documentation: https://docs.djangoproject.com/en/5.0/
● https://courses.cs.washington.edu/courses/cse190m/10su/lectures/slides/lecture22-
cookies.shtml
● https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Forms
● https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Sessions
● https://www.w3schools.com/tags/ref_httpmethods.asp
● Andrew Hoffman. Web Application Security (1st Edition), O’Reilly, 2020

76

You might also like