T09 · Insecure Skill Coding Practices
- Location
scripts/inspect.js:27- Finding
SQL Injection Through the Unescaped --table Argument
- Content
View full analysis
- Remediation
View remediation
object.name)) if (!validNames.has(tableName)) { throw new Error('Unknown table or view') } const quotedTable = quoteIdentifier(tableName) const columns = await db.all(`PRAGMA table_info(${quotedTable})`) const rowCount = await db.get(`SELECT COUNT(*) AS count FROM ${quotedTable}`) const sampleRows = await db.all(`SELECT * FROM ${quotedTable} LIMIT 5`) const indexes = await db.all(`PRAGMA index_list(${quotedTable})`) ``` 4. Open databases in read-only mode for inspection operations: ```js const db = await open({ filename: dbPath, mode: sqlite3.OPEN_READONLY, driver: sqlite3.Database }) ``` 5. Add security tests covering table names containing double quotes, comment markers, semicolons, whitespace, and SQL keywords. 6. Apply query timeouts or operational limits where untrusted users can invoke the script against large databases. ]]>
