fix(beliefs): write reliability outcomes with literal statements, not assembled SQL

The static allow-list test caught an identifier chosen from two literals
being formatted into the statement. Two literal statements replace it; no
identifier is ever built from a value.
This commit is contained in:
Andy Dixon
2026-08-16 19:33:31 +01:00
parent cff87af28d
commit 814057b680
+7 -4
View File
@@ -50,12 +50,15 @@ func (s *Store) RecordOutcome(ctx context.Context, q storage.Querier, mind ids.I
if domain == "" { if domain == "" {
domain = "*" domain = "*"
} }
col := "wrong" // Two literal statements rather than an assembled one: no identifier is
// ever built from a value, however constrained.
stmt := `INSERT INTO source_reliability (mind_id, source, domain, wrong) VALUES ($1,$2,$3,1)
ON CONFLICT (mind_id, source, domain) DO UPDATE SET wrong = source_reliability.wrong + 1, updated_at = now()`
if correct { if correct {
col = "correct" stmt = `INSERT INTO source_reliability (mind_id, source, domain, correct) VALUES ($1,$2,$3,1)
ON CONFLICT (mind_id, source, domain) DO UPDATE SET correct = source_reliability.correct + 1, updated_at = now()`
} }
_, err := q.Exec(ctx, fmt.Sprintf(`INSERT INTO source_reliability (mind_id, source, domain, %s) VALUES ($1,$2,$3,1) _, err := q.Exec(ctx, stmt, mind, source, domain)
ON CONFLICT (mind_id, source, domain) DO UPDATE SET %s = source_reliability.%s + 1, updated_at = now()`, col, col, col), mind, source, domain) // #nosec G202 -- col is one of two literals
return err return err
} }