# 데이터 쿼리 로직의 특수 요소에 대한 부적절한 무효화 (CWE-943) 제품이 데이터 저장소의 데이터에 접근하거나 조작하기 위한 쿼리를 생성하지만, 쿼리의 의도된 로직을 변경할 수 있는 특수 요소를 무효화하지 않거나 잘못 무효화합니다. 이는 전통적인 SQL 인젝션과는 다른 NoSQL 데이터베이스, ORM 프레임워크, 기타 데이터 쿼리 메커니즘에 대한 인젝션 공격을 포함합니다. - Prevalence: 높음 자주 악용됨 - Impact: 높음 3개의 높은 심각도 규칙 - Prevention: 문서화됨 3개의 수정 예시 **OWASP:** Injection (A03:2021-Injection) - #3 ## Description This covers injection attacks against NoSQL databases, ORM frameworks, and other data query mechanisms that differ from traditional SQL injection. ## Prevention 3개의 Shoulder 탐지 규칙을 기반으로 한 NoSQL Injection 예방 전략. ### Go Use typed structs or explicit operators, validate all user input ### JavaScript Validate input types and sanitize MongoDB operators ### Python Validate input types and use ObjectId for ID fields ## Consequences - 애플리케이션 데이터 읽기 - 애플리케이션 데이터 수정 - 보호 메커니즘 우회 ## Mitigations - 모든 데이터 저장소에 대해 파라미터화된 쿼리를 사용하세요 - 쿼리에서 사용하기 전에 입력을 검증하고 정제하세요 - 데이터베이스 계정에 최소 권한 원칙을 적용하세요 ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **NoSQL 인젝션** [HIGH]: 적절한 검증 없이 MongoDB 또는 Redis 쿼리로 흘러 들어가는 사용자 입력을 탐지합니다. - Remediation: Use typed structs or explicit $eq operators for MongoDB, validate Redis keys with regex. ```go filter := bson.M{"username": bson.M{"$eq": username}} ``` Learn more: https://shoulder.dev/learn/go/cwe-943/nosql-injection ### Javascript (1 rules) - **MongoDB 쿼리를 통한 NoSQL 인젝션** [HIGH]: 검증 없이 NoSQL 데이터베이스 쿼리로 흘러 들어가는 사용자 입력을 탐지합니다. - Remediation: Validate input types and use mongo-sanitize to remove operators from user input. ```javascript const sanitized = mongoSanitize(req.body.query); const user = await User.findOne(sanitized); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-943/nosql-injection ### Typescript (1 rules) - **MongoDB 쿼리를 통한 NoSQL 인젝션** [HIGH]: 검증 없이 NoSQL 데이터베이스 쿼리로 흘러 들어가는 사용자 입력을 탐지합니다. - Remediation: Validate input types and use mongo-sanitize to remove operators from user input. ```javascript const sanitized = mongoSanitize(req.body.query); const user = await User.findOne(sanitized); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-943/nosql-injection ### Python (1 rules) - **NoSQL 인젝션** [HIGH]: 적절한 검증 없이 NoSQL 쿼리에 사용되는 신뢰할 수 없는 사용자 입력을 탐지합니다. - Remediation: Validate and type-check user input before using in queries. ```python from bson import ObjectId object_id = ObjectId(user_id) # Validates format ``` Learn more: https://shoulder.dev/learn/python/cwe-943/nosql-injection