Security & Authentication
CSCI 344: Advanced Web Technologies
Fall 2024
Announcements
Outline
Outline
Securing Data that You’re Collecting Over the Web
When you create a web application that gathers and stores user-generated data, what are your obligations?
Your Thoughts Here…
Some Privacy, Security, and Ethical Considerations
1. Hashing DB Passwords
2. Protecting Data Against Unauthorized Use
How do you safeguard this?
3. Protection from SQL Injection
If you don’t “sanitize” your query parameters, malicious hackers can append malicious SQL at the end of a request.
Note that using SQLAlchemy models / helper functions will protect against SQL Injection attacks “for free.”
4. Using HTTPS
Read More
5. CSRF (Cross-Site Request Forgery): What is it?
A way for a script or action to take advantage of a privileged session of another browser application.
As stated in this video, “CSRF hackers craft malicious ways to induced privileged users to perform unwanted actions by taking advantage of browser-target trust.”
5. CSRF Attack (GET): Example
5. CSRF: POST Attack
5. To Protect against CSRF attacks
Read More
6. XSS (Cross-Site Scripting): What is it?
When a user injects a malicious script or HTML element on YOUR website that targets other users that use your platform (see video).
6. XSS (Cross-Site Scripting): Example
Here’s how it happens:
6. XSS (Cross-Site Scripting): Preventing It
Once a script is embedded in the codebase, that script is also able to access a user’s cookies and steal their tokens.
Protections
6. XSS (Cross-Site Scripting): More Reading
7. Terms of Service
What needs to go into a terms of service agreement?
Your thoughts here…
Outline
General Authentication Workflow
Most authentication workflows consist of the following steps:
Two Common Authentication Workflows
Approach 1: Session Cookies
Approach 1: Session Cookies
Cookies
Session Cookies
Approach 2: Other machines accessing your API
For third-party clients, your REST API needs to provide a different way to authenticate, for instance by requesting an authentication token from an authentication endpoint:�� /api/token
In this model, the client will manage this token and use it to access privileged resources. Furthermore, the client also needs to track / manage expiring tokens and use the refresh token to generate a new access token.
Approach 2: JWT (JSON Web Token Approach)
2. JWT Workflow
Demo (Postman)
Similarities & Differences
JWTs (JSON Web Tokens) Workflow
JSON web tokens offer ONE (of many) ways to securely transmit authentication credentials between parties. Workflow:
JWTs: How Encoding Works
In its compact form, JSON Web Tokens consist of three parts separated by dots (.), which are:
IMPORTANT: JWTs are encoded but not encrypted
Source: https://jwt.io/introduction
Diagram of a JWT
Pros: Useful for “Microservices”
It is often the case that the authentication server is on a completely different machine than the REST API that is serving your data:
One key advantage of using JWTs is that the same token can be used on both servers – so long as both servers share the same access and refresh token secrets!
Cons: Revoking the Token