Summary
Terrascan server mode exposes a Server-Side Request Forgery (SSRF) vulnerability in its remote directory scan endpoint, allowing attacker-controlled URLs to be fetched by the server without proper validation.
By abusing go-getter's HTTP fetching and redirection behavior, an unauthenticated attacker can coerce Terrascan into reading local files and leaking credentials from the server's environment.
Affected context
This issue affects Terrascan instances run in server mode (terrascan server) that:
- Bind the API to a network-accessible interface (default
0.0.0.0) - Do not sit behind an authenticating reverse proxy or gateway
- Expose the remote directory scan endpoint:
POST /v1/{iac}/{iacVersion}/{cloud}/remote/dir/scan- Allow clients to supply
remote_urlwithremote_typeset to"http"
In this context, Terrascan delegates fetching of the remote URL to the hashicorp/go-getter library, inheriting its support for redirects and .netrc credential usage.
Exploit preconditions
- Attack surface: Network-accessible Terrascan server endpoint at
/v1/{iac}/{iacVersion}/{cloud}/remote/dir/scan. - Required access: None; the endpoint is unauthenticated by default when Terrascan is run in server mode.
- Input control: Attacker can freely set:
remote_typeto"http"remote_urlto an HTTP URL under their control.- Trigger point: When the remote directory scan is invoked, Terrascan passes
remote_urldirectly tohashicorp/go-getter'sHttpGetter. - Why exploitation is possible:
- The URL is not validated, sanitized, or restricted to trusted locations.
HttpGetterhonors theX-Terraform-Getresponse header, enabling redirects tofile://URLs and other schemes.HttpGetterhasNetrcset totrue, causing it to read~/.netrcand automatically send stored credentials to attacker-controlled hostnames.
Why this happens
The root cause combines unvalidated remote resource fetching with implicit trust in helper library behavior:
- Terrascan's remote scan API accepts a user-supplied
remote_urland forwards it directly tohashicorp/go-getterwithout constraining the scheme, host, or response headers. go-getter'sHttpGettersupports theX-Terraform-Getresponse header, which can instruct the client to follow redirects to arbitrary URIs, includingfile://paths on the local filesystem (CWE-73: External Control of File Name or Path).- With
Netrcenabled,HttpGetterautomatically loads and uses credentials from~/.netrc, sending them to remote hosts specified in attacker-controlled URLs (CWE-610: Use of Insufficiently Random Values in security context is related to credential management concerns; more broadly, it reflects insufficient control over credential usage). - This pattern maps primarily to CWE-918: Server-Side Request Forgery (SSRF), where a server acts as a proxy for attacker-controlled outbound requests, exposing internal resources and sensitive data.
Conceptually, the bug arises from treating a user-provided URL as fully trusted input for a powerful network/file retrieval client, without imposing scheme restrictions, host allowlists, or safeguards around credential usage and local file access.
Potential impact
- May allow reading of arbitrary files accessible to the Terrascan process via
file://redirection (e.g., configuration files, SSH keys, cloud credentials). - Could lead to exfiltration of credentials stored in
~/.netrc, potentially including tokens or passwords for internal services. - Can be used to perform SSRF against internal HTTP services reachable from the Terrascan server, such as metadata endpoints or private APIs.
- May facilitate lateral movement or privilege escalation if sensitive configuration or secrets are exposed.
- Could enable reconnaissance of internal network topology through controlled request/response behavior.
General mitigation guidance
Since Terrascan has been archived and no patch will be released, mitigation revolves around deployment hardening and input constraints:
- Restrict exposure of server mode:
- Avoid running
terrascan serveron untrusted networks. - Place Terrascan behind an authenticating reverse proxy or API gateway that enforces authentication and network-level access controls.
- Constrain outbound access:
- Use network policies or egress filters to limit which hosts and protocols the Terrascan server can contact.
- Block or strictly control access to internal metadata services and sensitive infrastructure endpoints.
- Reduce local data exposure:
- Run Terrascan under a dedicated, least-privileged account with minimal sensitive files and no critical entries in
~/.netrc. - Limit filesystem permissions so the process cannot read secrets or sensitive configuration files not strictly required for operation.
- Harden URL handling at integration boundaries:
- If Terrascan is wrapped or proxied by custom tooling, introduce validation to:
- Allow only specific schemes (e.g.,
https) and approved hosts. - Reject or normalize values that could influence scheme redirects or file access.
- Segregate environments:
- Operate Terrascan in isolated environments (e.g., dedicated containers or VMs) where compromise yields minimal access to broader infrastructure.
How teams detect issues like this
Detection should focus both on code-level patterns and operational signals:
- Code and configuration review:
- Identify any internal tooling or wrappers that expose Terrascan's server API without proper authentication or network restrictions.
- Look for patterns where user-controlled URLs are passed to generic fetch libraries (like
go-getter) without scheme or host validation. - Static and dynamic analysis:
- Use static analysis to flag:
- Unvalidated input used in network request constructors or HTTP clients.
- Calls into libraries known to support multiple schemes (
http,file, etc.) without explicit filtering. - Apply dynamic application security testing (DAST) to Terrascan deployments to probe SSRF-like behavior on the remote scan endpoint.
- Logging and monitoring:
- Enable detailed HTTP access logs for the Terrascan server and any reverse proxies, focusing on:
- Repeated or unusual use of the remote directory scan endpoint.
- Suspicious
remote_urlvalues pointing to unexpected hosts. - Monitor outbound traffic from Terrascan hosts for connections to unknown or unapproved destinations.
- Track anomalous filesystem access patterns if OS-level auditing is available (reads of sensitive files when running scans).
- Policy enforcement:
- Enforce infrastructure policies that disallow direct exposure of analysis tools like Terrascan to the internet.
- Integrate security checks into CI/CD pipelines to verify that Terrascan is only used in offline or tightly controlled modes.

