sql-injection-prevention by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill sql-injection-prevention使用预处理语句、参数化查询、ORM 最佳实践和输入验证来实现全面的 SQL 注入防护。
最小工作示例:
// secure-db.js
const { Pool } = require("pg");
class SecureDatabase {
constructor() {
this.pool = new Pool({
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
}
/**
* ✅ SECURE: Parameterized query
*/
async getUserById(userId) {
const query = "SELECT * FROM users WHERE id = $1";
const values = [userId];
try {
const result = await this.pool.query(query, values);
// ... (完整实现请参阅参考指南)
references/ 目录下的详细实现:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 指南 | 内容 |
|---|---|
| Node.js with PostgreSQL | Node.js 与 PostgreSQL |
| Python with SQLAlchemy ORM | Python 与 SQLAlchemy ORM |
| Java JDBC with Prepared Statements | Java JDBC 与预处理语句 |
| Input Validation & Sanitization | 输入验证与净化 |
每周安装量
120
代码仓库
GitHub 星标数
121
首次出现
2026年1月21日
安全审计
安装于
opencode102
gemini-cli101
codex96
claude-code93
cursor90
github-copilot83
Implement comprehensive SQL injection prevention using prepared statements, parameterized queries, ORM best practices, and input validation.
Minimal working example:
// secure-db.js
const { Pool } = require("pg");
class SecureDatabase {
constructor() {
this.pool = new Pool({
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
}
/**
* ✅ SECURE: Parameterized query
*/
async getUserById(userId) {
const query = "SELECT * FROM users WHERE id = $1";
const values = [userId];
try {
const result = await this.pool.query(query, values);
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Node.js with PostgreSQL | Node.js with PostgreSQL |
| Python with SQLAlchemy ORM | Python with SQLAlchemy ORM |
| Java JDBC with Prepared Statements | Java JDBC with Prepared Statements |
| Input Validation & Sanitization | Input Validation & Sanitization |
Weekly Installs
120
Repository
GitHub Stars
121
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode102
gemini-cli101
codex96
claude-code93
cursor90
github-copilot83
Azure RBAC 权限管理工具:查找最小角色、创建自定义角色与自动化分配
135,700 周安装