fix(import): sanitize row errors — never leak raw SQL, friendly constraint messages (#3566) - #3572
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 14 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
…raint messages (#3566) Import rows that hit a DB constraint surfaced the driver's raw error verbatim — including the full failing SQL statement (e.g. `insert into sys_user (...) - UNIQUE constraint failed: sys_user.phone_number`), which is unreadable and leaks the schema. - sanitizeRowError() maps SQLite/MySQL/Postgres UNIQUE and NOT NULL failures to human wording and, as a backstop, never lets a raw SQL statement reach the client. Already-friendly messages (better-auth's "User already exists") pass through. - isLikelyEmail rejects non-ASCII, so `x@柴仟.com` fails the import dry-run instead of only at real-import time inside better-auth. - Unit tests for both. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3566 (server side). Companion UI PR: objectstack-ai/objectui#2840.
Problem
A failing import row surfaced the driver's raw error verbatim. When a write hit a DB constraint (e.g.
sys_user.phone_numberisunique), the query builder embeds the entire failing statement inerr.message, andtoFailedResulthanded it straight back — the importer saw:Unreadable, and an information disclosure of the schema.
Changes
sanitizeRowError()(packages/rest/src/import-runner.ts) — maps common constraint failures to human wording and never lets a raw SQL statement reach the client:UNIQUE(SQLite / MySQL / Postgres) → "A record with this<column>already exists."NOT NULL→ "<column>is required."/data/:object/importand the identity import).isLikelyEmail(packages/plugins/plugin-auth/src/admin-user-endpoints.ts) — now rejects non-ASCII, so an address likex@柴仟.comfails the import dry-run pre-check instead of passing client + dry-run validation only to be rejected by better-auth's strict ASCII validator at real-import time. Single linear char-class test — no ReDoS.Tests
packages/rest/src/import-runner-error-sanitize.test.ts— 8 cases (SQLite/MySQL/PG unique, not-null, SQL backstop, friendly passthrough, empty).admin-user-endpoints.test.ts— non-ASCII rejection cases.🤖 Generated with Claude Code