Improper Neutralization of Special Elements in Data Query Logic
The product generates a query intended to access or manipulate data in a data store, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query.
This covers injection attacks against NoSQL databases, ORM frameworks, and other data query mechanisms that differ from traditional SQL injection.
इस भेद्यता को कैसे ठीक करें
3 Shoulder डिटेक्शन नियमों पर आधारित NoSQL Injection के लिए रोकथाम रणनीतियाँ।
Use typed structs or explicit operators, validate all user input
func findUser(w http.ResponseWriter, r *http.Request) { username := r.URL.Query().Get("username") - filter := bson.M{"username": username} + // Use explicit $eq to prevent operator injection + filter := bson.M{"username": bson.M{"$eq": username}} collection.FindOne(ctx, filter) }
Validate input types and sanitize MongoDB operators
- app.post('/login', async (req, res) => { - const { username, password } = req.body; - // Vulnerable: user can send { "$gt": "" } as password + const mongoSanitize = require('mongo-sanitize'); + + app.post('/login', async (req, res) => { + const username = mongoSanitize(req.body.username); + const password = mongoSanitize(req.body.password); const user = await User.findOne({ username, password }); if (user) { res.json({ success: true }); } });
Validate input types and use ObjectId for ID fields
from flask import request from pymongo import MongoClient db = MongoClient().mydb @app.route('/login', methods=['POST']) def login(): data = request.get_json() - # Vulnerable: entire dict from user - user = db.users.find_one(data) + # Safe: only use specific string fields + username = str(data.get('username', '')) + password = str(data.get('password', '')) + user = db.users.find_one({ + 'username': username, + 'password': password + }) return {'success': bool(user)}
अपने कोड में भेद्यताएँ खोजें
Improper Neutralization of Special Elements in Data Query Logic पैटर्न के लिए अपने कोडबेस को स्कैन करने के लिए Shoulder का उपयोग करें। 3 नियम.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=943 # Or scan entire project npx @shoulderdev/cli trust .
पहचान नियम (3)
कोड समीक्षा में किन बातों पर ध्यान दें
ये पैटर्न संभावित Improper Neutralization of Special Elements in Data Query Logic भेद्यताओं का संकेत देते हैं। कोड समीक्षा और सुरक्षा ऑडिट के दौरान इन्हें देखें।
अपने कोडबेस को इसके लिए स्कैन करें: Improper Neutralization of Special Elements in Data Query Logic
Shoulder CLI आपके पूरे कोडबेस में भेद्य पैटर्न खोजता है।