SQL Injection Prevention

SQL Injection Prevention

Guides an AI agent to prevent SQL injection with parameterised queries, prepared statements, ORM practices and input validation across Node, Python and Java.

Skill files7 files

references/

scripts/

templates/

SKILL.md97 lines
1
---
2
name: sql-injection-prevention
3
description: >
4
Prevent SQL injection attacks using prepared statements, parameterized
5
queries, and input validation. Use when building database-driven applications
6
securely.
7
---
8
9
# SQL Injection Prevention
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement comprehensive SQL injection prevention using prepared statements, parameterized queries, ORM best practices, and input validation.
22
23
## When to Use
24
25
- Database query development
26
- Legacy code security review
27
- Security audit remediation
28
- API endpoint development
29
- User input handling
30
- Dynamic query generation
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// secure-db.js
38
const { Pool } = require("pg");
39
40
class SecureDatabase {
41
constructor() {
42
this.pool = new Pool({
43
host: process.env.DB_HOST,
44
database: process.env.DB_NAME,
45
user: process.env.DB_USER,
46
password: process.env.DB_PASSWORD,
47
max: 20,
48
idleTimeoutMillis: 30000,
49
connectionTimeoutMillis: 2000,
50
});
51
}
52
53
/**
54
* ✅ SECURE: Parameterized query
55
*/
56
async getUserById(userId) {
57
const query = "SELECT * FROM users WHERE id = $1";
58
const values = [userId];
59
60
try {
61
const result = await this.pool.query(query, values);
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Node.js with PostgreSQL](references/nodejs-with-postgresql.md) | Node.js with PostgreSQL |
72
| [Python with SQLAlchemy ORM](references/python-with-sqlalchemy-orm.md) | Python with SQLAlchemy ORM |
73
| [Java JDBC with Prepared Statements](references/java-jdbc-with-prepared-statements.md) | Java JDBC with Prepared Statements |
74
| [Input Validation & Sanitization](references/input-validation-sanitization.md) | Input Validation & Sanitization |
75
76
## Best Practices
77
78
### ✅ DO
79
80
- Use prepared statements ALWAYS
81
- Use ORM frameworks properly
82
- Validate all user inputs
83
- Whitelist dynamic values
84
- Use least privilege DB accounts
85
- Enable query logging
86
- Regular security audits
87
- Use parameterized queries
88
89
### ❌ DON'T
90
91
- Concatenate user input
92
- Trust client-side validation
93
- Use string formatting for queries
94
- Allow dynamic table/column names
95
- Grant excessive DB permissions
96
- Skip input validation
97

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…