41. Explain server-side request forgery and its significance in cloud applications.
SSRF lets an attacker influence where a server sends an outbound request. In cloud applications, that server may reach internal services or instance metadata that the attacker cannot access directly. Prevent it with destination allowlists, URL and IP validation, scheme and redirect restrictions, egress controls, metadata protections, safe rejection, and secret-free logging.
Server-side request forgery, or SSRF, means an attacker controls a URL or destination that a server later requests. The important point is that the request originates from the server, not from the attacker's machine. In a cloud environment, that server may have network access that an external user does not have. A successful SSRF path can therefore reach internal services or instance metadata and may expose temporary credentials, access tokens, instance information, or other sensitive data. The security goal is to stop untrusted destination input from becoming unrestricted server-side network access across the cloud trust boundary.
- Does the application need to fetch only a known set of destinations, or arbitrary public Internet URLs?
- Can the cloud workload reach an instance metadata service or private internal services?
- Which URL schemes are legitimately required by the feature?
- Are HTTP redirects required, or can they be disabled?
Start with the approved request flow. A malicious user supplies an untrusted URL to a server feature such as an image fetcher, webhook handler, or import function. The vulnerable application runs in the cloud and makes the outbound request on the user's behalf. That request crosses the important trust boundary from the application toward the internal cloud network.
The protected assets are the internal services and cloud instance metadata that should not be reachable by an external user. Internal services can include databases, internal APIs, or administrative services. An instance metadata service can provide instance information and, depending on the cloud configuration and workload identity, temporary credentials or access tokens. This is why SSRF can be more significant in cloud applications than a normal external URL-fetching bug.
The first defensive decision is whether the application really needs arbitrary destinations. If it only needs known destinations, use a strict allowlist and reject everything else. This is easier to reason about than trying to recognize every malicious destination.
If the feature must fetch arbitrary public Internet resources, validate the URL with a trusted parser and restrict it to only the schemes the application actually needs. Resolve the destination and reject loopback, private, link-local, cloud-metadata, and other non-public or reserved addresses. The validation must apply to the destination actually used for the outbound connection.
Redirects are another important SSRF path. An initially acceptable public URL can redirect the server to an internal or metadata address. Disable redirects when the feature does not require them. If redirects are required, validate every redirect destination using the same scheme, hostname, and resolved-address rules before following it.
Use network egress controls as another layer. The cloud workload should not have unrestricted outbound access to internal networks or sensitive destinations that the application does not need. Firewalls and cloud network rules can reduce which destinations are reachable, but they are defense in depth rather than proof that the application is safe.
Cloud metadata protections provide an additional layer. For Amazon EC2, the Instance Metadata Service uses the link-local IPv4 address 169.254.169.254. IMDSv2 uses session-oriented requests and can be configured so metadata access requires a token. Requiring IMDSv2 can reduce exposure to some SSRF paths, but it does not protect unrelated internal services and is not a substitute for application validation and egress controls.
The safe failure path is fail closed. If the requested destination is not explicitly allowed or cannot be validated safely, the application rejects the outbound request rather than attempting a less-restricted fallback. It should log the rejected attempt for investigation without recording credentials, authorization headers, tokens, or other secrets.
Detection can use those sanitized rejection logs to identify repeated attempts to access private, link-local, metadata, or otherwise prohibited destinations. Monitoring is useful evidence of abuse or bypass attempts, but it does not replace prevention.
A concrete regression test should verify that approved public destinations work, prohibited loopback, private, link-local, and metadata destinations are rejected, unsafe redirects are blocked or revalidated, unsupported schemes are rejected, and the rejection log contains useful security context without secrets.
The main tradeoff is security versus flexibility. A strict allowlist provides a smaller attack surface but may not support features that genuinely need arbitrary public URLs. Allowing broad Internet destinations requires more complex URL parsing, DNS and resolved-address checks, redirect handling, and egress policy. A WAF or input filter can help as one layer, but passing through that layer does not prove the request is safe.
- Identify every server feature that accepts a URL or network destination from an untrusted user.
- If the feature needs only known destinations, enforce a strict destination allowlist.
- If arbitrary public destinations are required, parse the URL with a trusted library and allow only the required schemes.
- Resolve the destination and reject loopback, private, link-local, cloud-metadata, and other non-public or reserved addresses.
- Disable redirects when they are unnecessary; otherwise revalidate every redirect destination before following it.
- Restrict outbound connectivity with firewall or cloud-network egress controls so the workload cannot freely reach sensitive internal destinations.
- Apply cloud metadata protections, such as requiring AWS IMDSv2 where applicable.
- If validation fails or the destination is prohibited, reject the request without a permissive fallback.
- Log rejected attempts without secrets and monitor repeated suspicious destinations.
- Add regression tests for allowed destinations, prohibited address ranges, schemes, redirects, safe rejection, and sanitized logging.
Strict allowlists are simpler to operate and provide strong control, but they reduce flexibility when users need arbitrary external URLs. Broader URL-fetching features require more engineering for URL parsing, DNS resolution, address-range checks, redirects, and egress policies. Network controls also add infrastructure maintenance. Security logging adds storage and monitoring work. These costs are important because SSRF can turn one attacker-controlled URL into access from a more trusted cloud network position.
This question tests whether the candidate understands SSRF as a server-side trust-boundary problem rather than only an input-validation bug. A strong answer explains how attacker-controlled destination input becomes a request from a cloud workload with different network reachability, why internal services and instance metadata matter, how layered defenses reduce the risk, how the application should fail safely, and why a WAF, input filter, or metadata protection alone is not complete protection.
Common mistakes include treating SSRF as only a string-filtering problem; relying only on a denylist; validating the hostname but not its resolved address; failing to block loopback, private, link-local, metadata, or other non-public destinations; permitting unnecessary URL schemes; following redirects without revalidating the new destination; assuming a WAF or input filter proves the request is safe; assuming network controls alone prevent SSRF; relying on IMDSv2 as complete protection; failing open when validation or DNS resolution fails; and recording credentials or tokens in security logs.
Explain SSRF as a trust-boundary problem: attacker-controlled destination input becomes an outbound request from a more trusted server. Walk through the flow from the malicious user to the vulnerable cloud application and then to internal services or metadata. Finish with layered defenses, fail-closed rejection, secret-free logging, verification tests, and the limitation that no single control completely removes SSRF risk.







