Summary
Ghidra's BSim component performs unsafe string concatenation of user-controlled filter values into SQL queries without proper parameterization.
An attacker who can send crafted BSim network queries may inject arbitrary SQL, potentially reading, modifying, or deleting data in the backing PostgreSQL database.
Affected context
The vulnerability occurs in Ghidra deployments that use BSim with a PostgreSQL backend and accept BSim network queries from external clients.
It is most relevant where BSim servers are reachable over a network and process user-supplied filter criteria that are directly incorporated into SQL.
Environments that expose BSim services beyond tightly controlled internal networks are more likely to be at risk.
Exploit preconditions
- Attack surface: BSim network query protocol endpoint backed by PostgreSQL
- Required access: Ability to connect to the BSim service and submit filter values (e.g., as an authenticated or unauthenticated BSim client, depending on configuration)
- Trigger point: Execution of SQL statements that embed user-supplied filter types or values via string concatenation
- Why exploitation is possible: The query construction logic does not use parameterized statements or robust escaping, allowing user input to alter the SQL structure instead of being treated as data
Why this happens
The bug is rooted in constructing SQL queries by concatenating raw user input into query strings instead of using prepared statements with bound parameters.
This pattern maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where meta-characters such as quotes and delimiters are not neutralized before being sent to the database.
As a result, the database interprets attacker-controlled fragments as part of the executable query, enabling arbitrary SQL operations within the privileges of the BSim database account.
Potential impact
- Read sensitive data stored in the BSim PostgreSQL database
- Modify or delete existing records, including analysis metadata and similarity indexes
- Insert crafted data that can skew similarity results or mislead analysts
- Potentially escalate impact by abusing database-level features accessible to the BSim account
General mitigation guidance
Effective mitigation focuses on eliminating direct string concatenation in SQL construction and tightening trust boundaries around BSim inputs.
Common defensive patterns include:
- Refactoring query builders to use parameterized queries or prepared statements for all user-controlled fields
- Applying strict whitelisting and validation to filter types and values, constraining them to known-safe sets or formats
- Limiting the database privileges of the BSim service account to the minimum required for normal operation
- Restricting network exposure of BSim services, placing them behind authenticated, internal-only access where possible
How teams detect issues like this
Detection typically combines code-level and runtime observations:
- Static analysis rules that flag SQL string concatenation patterns involving BSim filter inputs
- Manual code review focused on query-building utilities, ensuring that all dynamic fields are bound parameters
- Database logging and monitoring for anomalous or syntactically unusual queries originating from the BSim service
- Integration of automated secure-coding checks into CI pipelines to prevent reintroduction of direct SQL concatenation

