·
Last changedVersion:
This version passed the hardening gate. Hardening applied 11 targeted changes and preserved all other text. Classified findings before hardening: 0. Classified findings closed: 0. Classified findings remaining: 0. Unclassified scanner findings remaining: 0. Review findings closed: 14. Review findings remaining: 0.
None
None
Expand | File | Group | Subtype | Severity | Status |
|---|
No findings available
0 findings
Use this guide with the exact @prisma/driver-adapter-utils version installed by the target Prisma release. Driver adapters are a protocol boundary: type-compatible code can still corrupt values, leak connections, or break transactions.
SqlDriverAdapterFactory, SqlMigrationAwareDriverAdapterFactory, SqlDriverAdapter, or TransactionP2039, transaction leaks, shadow-database failures, or adapter-specific query behaviorIsolationLevel currently includes READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SNAPSHOT, and SERIALIZABLE; validate what the concrete database supports.
| Priority | Rule | Impact |
|---|---|---|
CRITICAL | One dedicated connection per transaction | Prevents interleaving and leaks |
CRITICAL |
| Prevents duplicate COMMIT/ROLLBACK |
CRITICAL | Savepoints live on | Makes nested scopes connection-local |
CRITICAL | Preserve original database error code/message | Enables useful |
HIGH | Map arguments and result metadata exactly | Prevents silent value corruption |
HIGH | Shadow databases are isolated and always cleaned up | Makes Migrate safe |
HIGH | Dispose only resources the adapter owns | Prevents shutting down caller-owned pools |
SqlQuery contains sql, args, and parallel argTypes. Map each argument using both value and ArgType; do not discard type/arity information. Execute in the driver's array/tuple row mode so column order is stable.
Return columnNames, columnTypes, and rows with identical lengths/order. Map driver metadata to ColumnTypeEnum deliberately:
Int32/Int64; preserve 64-bit values without JS number truncationNumeric using the representation expected by PrismaUint8Array/BytesDate, Time, and DateTimeDriverAdapterError({ kind: 'UnsupportedNativeDataType', type })Test null, empty arrays, array element types, big integers, decimals, byte arrays, JSON, dates, and user-defined/unknown native types.
executeScript must execute a migration script as the provider expects. Prefer the driver's native multi-statement/script facility or a real SQL parser. Naively splitting on ; breaks functions, triggers, quoted strings, and dialect-specific blocks. Only pass trusted scripts generated by Prisma Migrate to this method, and keep user-controlled input out of it. Use least privilege credentials for migration and shadow connections.
startTransaction must acquire one dedicated connection, start the database transaction, apply the requested isolation level, and return a Transaction bound to that same connection. If setup fails, release it immediately. If setup fails after BEGIN succeeded, issue a best effort ROLLBACK or explicitly destroy the connection instead of relying on driver specific release behavior.
The isolation level helper must look the level up in a fixed map from each supported isolation level to its provider SQL keywords. Any other value must fail as InvalidIsolationLevel, so raw strings never reach the statement. Some providers require setting the isolation level before the transaction begins, so order the statements to match the provider.
Prisma coordinates the SQL COMMIT/ROLLBACK through executeRaw. The transaction object's commit() and rollback() methods are lifecycle hooks: detach listeners and release the dedicated connection exactly once. They must not issue a second SQL commit/rollback. If a control statement failed, or the driver reports the connection is still inside a transaction at release time, destroy the connection instead of returning it to the pool.
Implement the optional savepoint methods only where the provider supports them. Validate/quote savepoint identifiers. The savepoint helper must accept only names that start with a letter or underscore, contain only letters, digits, and underscores, and fit the provider identifier length limit; it must reject anything else with a DriverAdapterError and then apply provider identifier quoting. After commit() or rollback() releases the connection, the transaction must reject further queries and savepoint calls with the closed transaction error kind of the installed version. For providers whose savepoints are intentionally no-ops, document and test that limitation.
Never keep transaction depth on the shared adapter. Parallel transactions make adapter-global depth incorrect; nested state belongs to the returned transaction connection and Prisma's savepoint calls.
Wrap recognized driver failures in DriverAdapterError. Map known conditions to MappedError kinds such as constraint violations, authentication/reachability, missing table/column/database, timeouts, closed transactions, invalid input, value range, and write conflicts.
For database errors, preserve originalCode and originalMessage even when falling back to the provider-specific raw variant:
Prisma uses preserved original details when an unmapped driver error becomes P2039. Do not replace every unknown exception with a fabricated GenericJs id; rethrow genuinely unexpected non-driver errors so programming bugs remain visible.
Database error messages and details, including P2039 output, may contain row values or schema names. Applications should keep them in server logs and return generic errors to end users. Keep connection strings and credentials out of adapter error messages.
connect() returns a fresh usable adapter connection/pool wrapper.dispose() closes owned pools and only detaches listeners from caller-owned pools unless an explicit option transfers ownership.SqlMigrationAwareDriverAdapterFactory only when connectToShadowDb() can create an isolated shadow database, connect to it, and drop it during disposal/failure cleanup.getConnectionInfo() should accurately report schemaName, maxBindValues when applicable, and supportsRelationJoins.@prisma/driver-adapter-utils versionqueryRaw preserves column order, types, nulls, and precisionexecuteRaw reports affected rows correctlyexecuteScript handles provider-specific multi-statement syntaxInvalidIsolationLevelP2039These links follow a moving branch. Compare them against the release tag matching the installed version, and treat the typecheck against the exact installed package as authoritative.
Get started with chainctlchainctl skill install public/prisma/prisma-driver-adapter-implementation:latest
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
skills.cgr.dev/public/github.com/prisma/prisma-driver-adapter-implementation:latest
MIT
HARDENING.md
LICENSE
SKILL.md