@@ -39,22 +39,32 @@ go run examples/logical_operators/logical_operators.go
39
39
go run examples/precedence/precedence.go
40
40
```
41
41
42
- ## 🔒 Security: Injection Protection
42
+ ## ** 🔒 Security: SQL Injection Protection**
43
43
44
- ** ODataSQL** enforces strict validation to prevent SQL injection risks:
44
+ ** ODataSQL** enforces strict validation to prevent SQL injection attacks and ensure safe query generation.
45
45
46
- - ✅ ** Rejects Always-True Expressions **
47
- - ❌ ` "age gt 30 or true eq true" ` ( _ Rejected _ )
48
- - ❌ ` "name eq 'Alice' or 1 eq 1" ` ( _ Rejected _ )
46
+ - ** SQL Injection via Malicious Values **
47
+ - ❌ ` "id eq '1; DROP TABLE users --'" `
48
+ - ❌ ` "DROP TABLE users" `
49
49
50
- - ✅ ** Ensures Valid Field Names **
51
- - ❌ ` "true eq false" ` ( _ Rejected _ )
52
- - ❌ ` "null eq null" ` ( _ Rejected _ )
53
- - ❌ ` "SELECT eq 'Alice'" ` ( _ Rejected _ )
50
+ - ** Always-True / Always-False Attacks **
51
+ - ❌ ` "username eq 'admin' or true eq true" `
52
+ - ❌ ` "age gt 30 or 1 eq 1" `
53
+ - ❌ ` "status eq 'active' and false eq false" `
54
54
55
- - ✅ ** Preserves SQL Safety**
56
- - Only ** valid identifiers** can be used as field names.
57
- - Strings, numbers, and booleans ** cannot be misused** as field names.
55
+ - ** Logical Operator & Parentheses Exploits**
56
+ - ❌ ` "()" ` , ` "not" ` , ` "name eq 'Alice' or" `
57
+
58
+ - ** Dangerous SQL Syntax**
59
+ - ❌ ` "name eq 'Alice' --" ` (SQL comment injection)
60
+ - ❌ ` "color in ()" ` (Empty ` IN ` list)
61
+ - ❌ ` "SELECT eq 'Alice'" ` (Reserved SQL keyword as a field)
62
+
63
+ #### ** ✅ How ODataSQL Ensures Safety:**
64
+
65
+ - ** Strict field validation** – Only valid identifiers allowed.
66
+ - ** Safe value handling** – Prevents misuse of SQL syntax.
67
+ - ** Input sanitization** – Blocks ` ; ` , ` -- ` , and comment injection.
58
68
59
69
💡 ** Note:** While ODataSQL ensures safe query generation, always apply ** standard SQL security measures** in your
60
70
database layer.
0 commit comments