Repository navigation
fix(server): do not return database errors from the skill endpoints - #494
Conversation
Recent skill calls and missing-skill stats put pgx text in the HTTP body. The server now logs that error and returns a fixed message.
kubernetes-client/python#2786 - fix(stream): handle tuple _request_timeout - 3 files, score: 77/100, 2 critical issues kubernetes-client/python#2762 - Regenerate Python clients with shared legacy - 30 files, score: 77/100, 13 critical issues kubernetes-client/python#2698 - Support _request_timeout in dynamic client - 2 files, score: 66/100, clean code BaaRai/ARTEX#494 - fix(server): do not return database errors - 2 files, score: 68/100, 1 security issue torvalds/GuitarPedal#60 - WebMIDI: keep queued BLE writes - 2 files, score: 77/100, clean code
BaaRai
left a comment
There was a problem hiding this comment.
PR #494 — fix(server): do not return database errors from the skill endpoints
- Head checked:
068a4630(068a463), detached worktree, matches GitHub. - Base:
main@94757c5d(merge base = 94757c5). GitHub: MERGEABLE, 2 files, +5/-2. - Verdict: request changes. The two handlers the PR touches are fixed, but the PR title covers "the skill endpoints", and two of them still return driver text (finding 1).
What the PR changes
server/server_mgmt.go fsSkillUsage and fsMissingSkills: a DB error is now
logged with log.Printf("... %v", err) and the client gets a fixed string
(failed to load skill usage / failed to load missing skills).
Path trace (every path the new code adds)
GET /api/skills/{name}/usage->fsSkillUsage->pg.RecentSkillCalls
(db/skill_usage.go:164). Errors come back raw fromd.Query/rows.Scan/
rows.Err(no%w, no wrapping at all). Response: fixed string. Log: driver text.GET /api/skills/missing->fsMissingSkills->pg.MissingSkillStats
(db/skill_usage.go:106), which also callsarchivedTaskAggregates
(db/task_archive_aggregate_stats.go:21): ajson.Unmarshalerror from an archived
row can also reach the log. Response: fixed string.- What the log line can contain: pgx
PgError.Error()isERROR: <msg> (SQLSTATE x);
it does not print the query text, the DSN, orDetail(row values). A connect
failure printsfailed to connect to `user=... database=...` host:port; no password.
Ajson.Unmarshalerror prints the offending type/offset, not the row. namein the log line is gated byvalidSkillName([a-z0-9-]plus Unicode
letters/digits, max 64 runes), so no log-line injection through the path value.s.pg(w)nil path (503) is unchanged and returns a fixed message.
Findings
- blocking for the stated scope — same leak remains on the other DB-backed skill endpoints; this is why I am not approving.
server/server_mgmt.go:2034(pgSkillVisibility,GETskill visibility) and
server/server_mgmt.go:2055(pgToggleSkillVisibility) still do
writeErr(w, 500, err.Error()). Scenario: PG pool closed or a query fails ->
the client receives the driver string. The PR title says "the skill endpoints";
either extend the fix to these two or narrow the title/CHANGELOG line.
Reproduced: throwaway test with a closed pool returned
{"error":"sql: database is closed"}forpgSkillVisibility, while the two fixed
handlers returned the fixed strings. - should — no regression test. A test that drives both handlers with a failing
DB (closed pool is enough) and asserts the body is the fixed string would keep
this from coming back. Read only. - nit — the pattern
writeErr(w, 500, err.Error())is used ~50 more times in
server_mgmt.go(non-skill handlers). Out of scope here; worth a tracked follow-up
if the goal is "no driver text in responses". Read only. - nit — the server log still carries full driver text (including DB user and
database name on connect failures). That is the intended place for it; noting only
so log shipping is considered. Read only.
Tests run (throwaway review Postgres container, ARTEX_PG_DSN set)
| Command | Exit |
|---|---|
go test -count=1 -run TestZZReview494SkillErrors -v ./server/ (throwaway test, deleted after) |
0 |
go test -count=1 -run TestSkillUsageLedger -v ./db/ |
0 (PASS, not skipped) |
go test -count=1 -run Skill ./server/ |
0 |
go vet ./server/ |
0 |
gofmt -l server/server_mgmt.go |
0, no output |
Throwaway test output (abridged):
- usage: 500
{"error":"failed to load skill usage"} - missing: 500
{"error":"failed to load missing skills"} - visibility (not in PR): 500
{"error":"sql: database is closed"} - server log:
[skills] recent calls for zz: sql: database is closed,
[skills] missing skills: sql: database is closed
Note: a first run failed with "connection refused" because the review DB container
had stopped; it was started again and the run above is the clean one.
Not verified
- A real PostgreSQL error (e.g. missing table, constraint) through these handlers;
only the closed-pool error was exercised. pgx error formatting was read, not run. - Full
./server/and./db/suites were not run, only the targeted tests. - Web UI handling of the new fixed messages (no web change in this PR).
Skill usage and missing-skill stats already returned a fixed message. Skill visibility and its toggle still sent err.Error() to the client. Those two now log the driver text and return a fixed message. A closed pool test covers all four handlers.
|
Closing and reopening to retrigger CI. The review commits did not start a workflow run. |
|
Review notes Looks good to merge. It's correct for the 4 skill endpoints it touches, and the test covers it. There are still about 250 |
83ad4bc to
3fb3ac5
Compare
3fb3ac5 to
d844841
Compare
d844841 to
6863948
Compare
6863948 to
0d66d6f
Compare
Skill usage and missing-skill stats returned the database driver error to the client. Those failures are logged on the server and the client receives a fixed message. The server package compiles. Rebased onto current main; the only merge conflict was CHANGELOG.md.