Databases

GoGormDB

Represents gorm.DB, the primary database handle in GORM v2. Raw(), Exec(), and Where() with string arguments are SQL injection sinks when called with unsanitized user input.

3 sinks
Taint flow0 sources 3 sinks
Sinks — dangerous call
.Raw()
.Exec()
.Where()
Quick-start rule — copy and run
from codepathfinder.go_rule import GoGinContext, GoGormDB, GoStrconv
from codepathfinder import flows
from codepathfinder.presets import PropagationPresets
from codepathfinder.go_decorators import go_rule

@go_rule(
    id="GO-GORM-SQLI-002",
    severity="HIGH",
    cwe="CWE-89",
    owasp="A03:2021",
    message="String concatenation in GORM query builder. Use ? placeholders.",
)
def detect_gorm_sqli_concat():
    return flows(
        from_sources=[
            GoGinContext.method("Query", "Param", "PostForm"),
        ],
        to_sinks=[
            GoGormDB.method("Where", "Having", "Order"),
        ],
        propagates_through=PropagationPresets.standard(),
        scope="global",
    )
pathfinder scan --ruleset custom/security --project .

Sinks

.Raw()Sink
#
Signature
Raw(sql string, values ...any) *DB

Executes raw SQL. The sql string is an injection sink when built with user input.

tracks:0
.Exec()Sink
#
Signature
Exec(sql string, values ...any) *DB

Executes raw SQL DML. Same risk as Raw().

tracks:0
.Where()Sink
#
Signature
Where(query any, args ...any) *DB

Adds WHERE clause. Sink when query is a string with user input concatenated.

tracks:0

Other Methods

.Find()Neutral
#
Signature
Find(dest any, conds ...any) *DB

Executes SELECT with optional conditions. Safe when using struct conditions.

.Create()Neutral
#
Signature
Create(value any) *DB

Inserts record. Safe when using struct with parameterized fields.

Fully-Qualified Names

FQNField
gorm.io/gorm.DBfqns[0]
*.DBpatterns

Wrong FQN → 0 findings. Verify with: change fqns to garbage → must produce 0 results.

Import

go.mod
require gorm.io/gorm v1.25.5
rule.py
from codepathfinder.go_rule import GoGormDB

Rules Using This Class