← CSC 314 Web Application Technologies
Web Application Security, Authentication, and Authorization
Notes
Core Web Vulnerabilities
Web applications exposed to public networks are vulnerable to numerous security threats documented by bodies such as the Open Web Application Security Project (OWASP). Two of the most destructive attack vectors are SQL Injection (SQLi) and Cross-Site Scripting (XSS). SQL Injection occurs when untrusted user input is directly concatenated into dynamic database queries, allowing attackers to bypass authentication or extract sensitive records. Cross-Site Scripting occurs when an application injects malicious client-side scripts into web pages viewed by other users. Another common risk is Cross-Site Request Forgery (CSRF), where malicious sites trick authenticated user browsers into transmitting unauthorized commands to a vulnerable target application.
Authentication Mechanisms
Authentication verifies the identity of an entity accessing a system, whereas authorization dictates what resources that entity is permitted to access. Traditional stateful authentication relies on server-managed sessions. Upon successful login, the server generates a unique session identifier, stores it in memory or a cache like Redis, and transmits it to the client inside an HTTP-only cookie. In contrast, stateless authentication frequently leverages JSON Web Tokens (JWT). A JWT consists of a header, payload, and cryptographic signature separated by dots. Because the signature is signed using a secret key or asymmetric private key on the authentication server, API microservices can independently verify token validity without querying a centralized session database.
Securing Data in Transit and at Rest
Production web systems must mandate Transport Layer Security (TLS/HTTPS) to encrypt data in transit, thwarting man-in-the-middle sniffing attacks. Furthermore, authentication credentials stored at rest in databases must never exist in plaintext. Developers must hash passwords using computationally expensive, salted one-way key derivation functions such as bcrypt or Argon2.
Practical example
Consider developing a web management dashboard for a credit cooperative such as Stima Sacco in Kenya. Members access financial records, apply for instant development loans, and view savings balances. To prevent SQL Injection, the backend engineering team disallows string concatenation and writes database queries using parameterized prepared statements in Object Relational Mapping frameworks. For authentication, when a Sacco member submits their national identity number and password over an HTTPS connection, the server retrieves the salted bcrypt hash from the database and verifies the password. Upon successful validation, the server signs a short-lived JSON Web Token containing claims for memberId, saccoBranch, and userRole. The token is sent to the client inside a secure, HttpOnly, SameSite strict cookie to mitigate both XSS access and CSRF exploits. When the member attempts to disburse a loan by calling /api/loans/disburse, an authorization middleware intercepts the request, verifies the cryptographic signature of the token, and confirms that the userRole claim has clearance for loan transactions before routing the execution to core banking services.
Quiz
1. What is the purpose of setting the HttpOnly flag on a session cookie?
2. Why are passwords hashed with algorithms like bcrypt rather than algorithms like MD5 or SHA-256?
3. Which technique is the most effective defense against SQL Injection vulnerabilities?
Sign in to submit and securely grade your quiz.