GORM 1.31
Last reviewed Sep 6, 2026
Prompt Details
Prompt Composition
2prompts
- Go 1.27130 lines · 5.5K tokens
- GORM 1.3156 lines · 1.7K tokens
Total186 lines · 7.2K tokens
CWE Coverage
- 15
- 20
- 22
- 59
- 78
- 79
- 89
- 94
- 117
- 190
- 208
- 209
- 250
- 252
- 257
- 295
- 307
- 319
- 323
- 327
- 338
- 347
- 352
- 362
- 367
- 378
- 426
- 444
- 488
- 494
- 532
- 639
- 672
- 732
- 759
- 770
- 772
- 807
- 862
- 863
- 915
- 916
- 918
- 942
- 1004
- 1275
- 1287
- 1395
Prompt Preview
Apply the Go 1.27 baseline first. These rules cover GORM 1.31 queries, updates, associations, tenancy, transactions, hooks, connections, migrations, logging, and testing.
Queries and SQL construction
- Bind values with
?, named arguments, or typed clauses; never concatenate request text into SQL passed toRaw,Exec,Where, or other query methods. Use only trusted SQL templates ingorm.Exprandclause.Expr, even when passing them as placeholder arguments. - Allowlist every request-controlled identifier or expression used with
Select,Distinct,Pluck,Group,Having,Order,Table,Joins,Delete, or raw SQL because placeholders cannot protect SQL syntax. - Parse and type-check primary keys before calling shortcuts such as
First(&user, input); a string primary-key argument can be incorporated as SQL and is unsafe when untrusted. - Use bound conditions, maps, or explicitly named struct fields for tenant and authorization predicates;
Where(struct)omits zero values such as0,false, and empty strings by default. - Never copy the logger’s interpolated SQL back into an executable query; it is produced for display and is not guaranteed to preserve safe parameter binding.
- Use
WithContext(or a generics method's context argument) and a finite context deadline for every request query, and set driver-side timeouts and pool limits because GORM adds no universal database deadline by default. - Never cache or reuse a traditional-API
*gorm.DBafter a chain or finisher method; its conditions can carry into later operations, so derive each