> For the complete documentation index, see [llms.txt](https://docs.sec1.io/user-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sec1.io/user-docs/4-sast/2-java/unsanitized-user-input-in-aws-query.md).

# Unsanitized user input in AWS query

## Overview

* **Rule ID**: `java_third_parties_aws_query_injection`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-943

## Description

Including unsanitized data, such as user input or request data, in raw queries makes your application vulnerable to injection attacks.

## Remediation Guidelines

* **Always sanitize user input**, especially if it will be used in database queries. Sanitization should include the removal of special characters (such as ' or ") that could be used to manipulate the query's semantics.
* **Validate** user input to ensure it meets the expected format and length wherever possible.
* **Use parameterized queries** instead of concatenating user input directly into the query string. This separates query logic from user input, which is best practice and, in the case of AWS SimpleDB, allows for internal parameterization and sanitization through `SelectRequest`.

  ```java
  // query logic
  public static SelectResult executeQuery(String query, String itemName) {
      AmazonSimpleDB simpleDBClient = AmazonSimpleDBClientBuilder.defaultClient();
      SelectRequest selectRequest = new SelectRequest(query, true).withNextToken(itemName);

      return simpleDBClient.select(selectRequest);
    }

  public static void selectItem(String itemName) { // itemName is dynamic and could be malicious
    // parameterized query string
    String query = "select * from items where itemName = ?";

    SelectResult result = executeQuery(query, itemName);
    ...
   } 
  ```

## References

* [**AWS SimpleDB docs**](https://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/Welcome.html)
* [**CWE-943: Improper Neutralization of Special Elements in Data Query Logic**](https://cwe.mitre.org/data/definitions/943.html)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)
