Backend Security
Understand core backend security practices, from authentication and authorization to common vulnerabilities and defenses.
Why Backend Security Matters
Backend systems handle sensitive data and critical operations, making them a primary target for attacks if not properly secured.
- Backends store sensitive data such as credentials, personal, and financial information.
- Security prevents unauthorized access and protects against data breaches.
- Attacks can target both external users and internal system components.
Details
Backend systems are responsible for handling some of the most sensitive parts of an application, including user credentials, personal data, financial records, and internal service communication. If these systems are compromised, the impact can be severe, ranging from data leaks to complete service disruption.
Security exists to enforce strict control over who can access the system and what actions they are allowed to perform. Without these controls, any client could potentially access or modify critical data.
Common threats include unauthorized access attempts, large-scale data breaches, and malicious attacks designed to exploit system vulnerabilities. These threats are constant in production environments and must be actively defended against.
At a high level, backend security introduces a protective layer between the client and the system. Every request must pass through security controls before reaching application logic. These controls ensure that only valid and authorized actions are executed.
Authentication
Authentication verifies the identity of a user or service before allowing access to the system.
- Users prove identity using credentials such as passwords or tokens.
- Systems validate these credentials before granting access.
- Authentication applies to both human users and services.
Details
Authentication is the first step in securing a backend system. It answers a fundamental question: “Who is making this request?” Before any action is allowed, the system must verify the identity of the requester.
This process typically involves credentials. A user might enter a password, present a session token, or use an API key. In more advanced setups, identity providers such as Google or enterprise authentication systems can verify identity on behalf of the application.
Once the credentials are validated, the system considers the identity verified. This does not mean the user can do anything—it only confirms who they are. What they are allowed to do is handled separately by authorization.
Without authentication, systems would have no way to distinguish between legitimate users and malicious actors, making secure access control impossible.
Authorization
Authorization determines what an authenticated user or service is allowed to do within the system.
- Authorization checks permissions after identity has been verified.
- Access is granted or denied based on roles or policies.
- Different users can have different levels of access to resources.
Details
Once a user is authenticated, the system knows who they are, but it still needs to determine what actions they are allowed to perform. This is the role of authorization.
Authorization works by checking permissions. For example, a regular user may only be allowed to view their own data, while an administrator may have the ability to delete accounts or modify system settings. These rules are enforced through roles, access control lists, or policy-based systems.
The process follows a simple flow: an authenticated user makes a request, the system checks their permissions, and then either allows or denies the action.
Without proper authorization, authenticated users could access or modify data they should not have access to, leading to serious security vulnerabilities.
OAuth
OAuth allows applications to access user data from another service without directly handling the user’s credentials.
- Users authenticate through a trusted third-party provider.
- The provider issues an access token to the application.
- The application uses the token to access user data securely.
Details
OAuth is a protocol designed for delegated access. Instead of sharing credentials like passwords with multiple applications, users authenticate with a trusted provider (such as Google), which then grants limited access to the application through a token.
The flow typically works as follows: the user chooses to log in with a provider, the provider authenticates the user, and then issues an access token to the application. This token represents the user’s permission and can be used to access specific resources.
This approach improves security because the application never sees or stores the user’s actual credentials. It also allows fine-grained control over what data the application can access.
OAuth is widely used for “Login with Google,” “Login with Facebook,” and similar integrations, enabling secure third-party authentication and controlled data sharing.
JSON Web Tokens (JWT)
JWTs are compact tokens that carry authenticated identity and are sent with each request to verify the user.
- The server issues a signed JWT after successful authentication.
- The client stores the token and includes it in future requests for verification.
- The token encodes user identity, permissions, and expiration without server-side session storage.
Details
JSON Web Tokens (JWTs) are a common method for maintaining authentication in stateless systems. After a user logs in, the server generates a JWT and sends it to the client. The client then includes this token in future requests, typically in the HTTP Authorization header.
A JWT contains encoded information such as the user ID, permissions, and an expiration time. This data is signed by the server, allowing the backend to verify that the token has not been tampered with.
Because the token carries all necessary identity information, the server does not need to store session data for each user. This makes JWTs efficient and scalable, especially for distributed systems.
However, JWTs must be handled carefully. If a token is leaked, it can be used to impersonate a user until it expires. Proper expiration and secure storage on the client are critical.
Hashing Passwords
Passwords must be stored as hashed values so that even if data is exposed, the original passwords cannot be directly recovered.
- Passwords are transformed using a one-way hash function before storage.
- During login, the input password is hashed and compared to the stored hash.
- Secure algorithms like bcrypt, Argon2, and PBKDF2 are designed to resist attacks.
Details
Storing passwords in plain text is a critical security flaw. If a database is compromised, attackers would immediately gain access to all user passwords. To prevent this, systems store hashed versions of passwords instead.
A hash function takes an input (the password) and produces a fixed-length output (the hash). This process is one-way, meaning it is computationally infeasible to reverse the hash back into the original password.
When a user logs in, the system hashes the input password and compares it to the stored hash. If they match, the password is correct without ever exposing the original value.
Modern hashing algorithms such as bcrypt, Argon2, and PBKDF2 are intentionally slow and include features like salting to defend against brute-force and precomputed attacks. This makes them significantly more secure than basic hash functions.
Cross-Site Request Forgery (CSRF)
CSRF attacks exploit a user’s authenticated session to perform unintended actions without their knowledge.
User (Logged In)
Browser
Server
- Attackers trick a logged-in user’s browser into sending unauthorized requests.
- The server processes the request because it trusts the user’s session.
- Protection relies on validating that requests originate from trusted sources.
Details
Cross-Site Request Forgery (CSRF) occurs when a malicious website causes a user’s browser to send requests to another site where the user is already authenticated. Because the browser automatically includes session cookies, the server assumes the request is legitimate.
For example, if a user is logged into a banking application and visits a malicious site, that site could trigger a hidden request to transfer money. The server processes the request because it sees a valid session, even though the user did not intend to perform the action.
To prevent CSRF attacks, systems use techniques such as CSRF tokens and same-site cookies. CSRF tokens are unique values included in requests that the server verifies, ensuring the request originated from the correct application. Same-site cookies restrict when cookies are sent, reducing the risk of cross-site requests.
Without proper CSRF protection, attackers can exploit trusted user sessions to perform harmful actions without direct access to user credentials.
Cross-Site Scripting (XSS)
XSS attacks inject malicious scripts into web pages, causing them to execute in other users’ browsers.
- Untrusted user input can be injected and executed as code in the browser.
- Attackers can steal session data or manipulate user interactions.
- Defense requires strict handling of all user-provided content.
Details
Cross-Site Scripting (XSS) occurs when an application includes untrusted user input in a web page without properly validating or escaping it. This allows attackers to inject scripts that run in the browser of other users.
For example, if a comment field allows raw HTML or JavaScript, an attacker could insert a script that executes whenever another user views the page. This script could steal cookies, capture user input, or perform actions on behalf of the user.
To prevent XSS, systems must treat all user input as untrusted. Input sanitization removes potentially dangerous content, while output escaping ensures that data is rendered as text rather than executable code. Content Security Policies (CSP) add an additional layer of protection by restricting which scripts are allowed to run.
Without proper defenses, XSS vulnerabilities can compromise user accounts and undermine the security of the entire application.
Secrets Management
Secrets management ensures that sensitive credentials are stored, accessed, and rotated securely without being exposed in code or systems.
- Secrets include API keys, database credentials, and encryption keys.
- They must never be hardcoded or exposed in source code.
- Secure systems control access and rotate secrets regularly.
Details
Backend systems rely on sensitive credentials to communicate with databases, external services, and internal components. These secrets include API keys, database passwords, and encryption keys, all of which must be protected from unauthorized access.
Storing secrets directly in code or configuration files is a major security risk. If the codebase is exposed, all embedded credentials are immediately compromised. Instead, secrets should be stored in dedicated systems designed for secure storage and controlled access.
Secrets managers such as AWS Secrets Manager and HashiCorp Vault provide centralized storage, access control, and automatic rotation of credentials. Environment variables are sometimes used for simpler setups, but they still require careful handling.
Proper secrets management reduces the risk of credential leaks and ensures that systems can securely access the resources they need without exposing sensitive information.
Rate Limiting as Security Protection
Rate limiting acts as a security control by restricting request volume to prevent abuse and denial-of-service attacks.
- Limits the number of requests a client can make within a time window.
- Protects endpoints like login and APIs from brute-force and abuse.
- Excess requests are blocked or delayed once limits are exceeded.
Details
Rate limiting is not just a performance tool—it is a critical security mechanism. By controlling how many requests a client can send, systems can prevent abuse such as brute-force login attempts or denial-of-service attacks.
For example, limiting login attempts reduces the effectiveness of password guessing attacks. Similarly, enforcing API request quotas prevents a single client from overwhelming backend services.
The process is straightforward: incoming requests are checked against a defined limit, and if the threshold is exceeded, the request is rejected or delayed. This ensures fair usage and protects system resources.
When combined with other security measures, rate limiting significantly strengthens system resilience against malicious traffic and misuse.
Question Section
1 / 5
This track is locked
Buy this track once to unlock all of its lessons.