Summary
Budibase contains a SQL injection vulnerability in its PostgreSQL datasource connector when processing a user-controlled schema configuration value. An authenticated administrator who saves or tests a datasource may be able to execute unintended SQL, creating risks to database confidentiality, integrity, and availability.
Affected context
The issue affects Budibase deployments using the PostgreSQL datasource connector in versions before 3.39.19. It occurs when the connector builds a PostgreSQL SET search_path statement from the configured schema value without safely handling embedded double quotes, and the affected datasource is saved or tested.
Exploit preconditions
- Attack surface: Budibase's PostgreSQL datasource configuration workflow
- Required access: An authenticated account with administrator privileges sufficient to create, modify, save, or test a datasource
- Trigger point: Datasource save or test operations that process the configured schema value
- Why exploitation is possible: User-controlled schema content is interpolated into a SQL statement without adequate escaping or parameter-safe construction
Why this happens
The vulnerability results from constructing a SQL SET search_path statement by directly interpolating a user-controlled schema configuration value. Embedded delimiter characters are not safely escaped, allowing configuration data to alter the intended SQL statement structure. This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, commonly known as SQL injection.
Potential impact
- An attacker may execute unintended SQL statements within the datasource's database context.
- Database records may be read, altered, or deleted, depending on the connected account's privileges.
- Application data confidentiality and integrity could be affected.
- Database availability may be disrupted through unauthorized operations.
- Compromised database credentials or connected systems could increase the scope of impact.
General mitigation guidance
Mitigation centers on preventing configuration values from becoming executable SQL syntax.
Common defensive patterns include:
- Constructing database commands with trusted APIs and safe identifier-handling mechanisms rather than raw string interpolation.
- Validating schema and identifier values against an allowlist of permitted names.
- Separating configuration data from SQL syntax wherever the database interface permits.
- Limiting datasource credentials to the minimum required database privileges.
- Restricting which administrators can create, modify, or test datasource connections.
- Applying defense-in-depth database controls, including isolated roles and restricted network access.
How teams detect issues like this
Organizations can detect similar issues through:
- Static analysis rules identifying string concatenation or interpolation in SQL construction.
- Code review checks for user-controlled datasource fields used in identifiers or statements.
- Tests that verify delimiter characters and unexpected identifier values cannot change generated SQL structure.
- Database audit logging for unusual statements issued by Budibase datasource accounts.
- Policy enforcement requiring parameterized queries or approved identifier-quoting APIs for database access.
- Automated security review tools that flag untrusted input reaching SQL execution paths.

