Summary
The Snowflake Terraform Provider contains SQL injection flaws that allow attacker-controlled input to be embedded directly into privileged SQL sessions.
When an attacker can influence pipeline workspace variables or user-related resource fields, they could trigger arbitrary SQL and DDL execution, leading to data exfiltration and unauthorized account creation.
Affected context
This vulnerability manifests in infrastructure-as-code deployments that use the Snowflake Terraform Provider to manage Snowflake resources.
It becomes relevant when:
- Pipelines expose workspace variables or data source inputs to user or external influence
- Terraform runs with a highly privileged Snowflake session configured for the provider
- User management and other security-sensitive operations (e.g., credential minting, role assignment) are expressed as Terraform resources or data sources
Exploit preconditions
- Attack surface: Terraform plans and applies that invoke Snowflake data sources or user-related resources.
- Required access: Ability to control or significantly influence workspace variables or resource input fields used by the vulnerable provider configuration.
- Trigger point: Execution of
terraform apply(or plan/apply cycles) where the provider builds SQL statements incorporating these inputs. - Why exploitation is possible: The provider improperly neutralizes SQL identifier and data content, allowing attacker input to be concatenated into SQL/DDL statements without robust escaping or parameterization, enabling injection.
Why this happens
The underlying bug is improper construction of SQL and DDL statements from untrusted configuration input.
Instead of treating Terraform variables and resource fields as data bound through parameterized queries, the provider appears to interpolate them directly into SQL strings, particularly in data source queries and user management statements.
This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where meta-characters and control tokens are not safely handled, allowing attackers to break out of the intended query structure and inject arbitrary commands.
Potential impact
- Attacker may execute arbitrary SQL under the provider's privileged Snowflake session.
- Sensitive data could be exfiltrated from Snowflake databases and schemas.
- Long-lived access credentials and roles can be minted or modified without operator intent.
- User accounts could be created or altered with attacker-controlled credentials and missing security controls (e.g., MFA, role restrictions).
- Infrastructure-as-code pipelines can be abused as a control plane for persistent Snowflake compromise.
General mitigation guidance
Effective mitigation focuses on reducing trust in configuration inputs and enforcing safe query construction patterns:
- Use strict parameterization or binding APIs for all SQL and DDL operations, treating Terraform variables and resource fields as data, never as raw query fragments.
- Normalize and whitelist identifier-like inputs (e.g., usernames, role names) against allowed character sets and patterns instead of attempting to escape arbitrary strings.
- Separate security-sensitive operations (user creation, role grants, credential management) from dynamic or user-provided variables, ensuring these flows rely only on controlled, operator-owned configuration.
- Run Terraform and its providers under least-privilege Snowflake roles, so even if injection occurs, the reachable impact surface is reduced.
- Establish secure defaults in Terraform modules and pipelines, avoiding patterns that pass unvalidated external data directly into provider resources or data sources.
How teams detect issues like this
Detection often involves a combination of code and configuration review plus behavioral monitoring:
- Apply static analysis or custom linters to Terraform configurations and provider code (where accessible) to flag direct string concatenation of variables into SQL or DDL commands.
- During review of infrastructure-as-code modules, look for resources and data sources that accept uncontrolled workspace or environment inputs and feed them into security-sensitive operations (user management, grants, credential creation).
- Enforce policy-as-code (e.g., using tools like Open Policy Agent or similar) to restrict patterns where external data can influence identifiers or queries within provider blocks.
- Monitor Snowflake audit logs for anomalous DDL sequences originating from Terraform-managed sessions, such as unexpected account creation, unusual grants, or large-scale data access patterns.
- Integrate automated IaC security scanning tools that understand Terraform and can detect high-risk injection patterns and overly privileged provider configurations.

