Detect SQLI Attacks from Text Input using Java

Cloudmersive
2 min readMar 31, 2022

There are a few flavors of SQLI attacks, but they all have the same goal: accessing and exploiting our sensitive backend data. Thankfully, these attacks aren’t a new phenomenon, and they’re detectable and preventable. With our SQLI detection API, you can easily uncover such attacks before they reach their destination. Implementing this API with Java is even easier — just follow steps below (installation with Maven) to rapidly improve your threat profile.

First install the Java SDK. Add the below reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

After that, add this reference to to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

For the last step, copy in the below snippets, starting with imports at the top of the controller & then calling the validation function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ContentThreatDetectionApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
ContentThreatDetectionApi apiInstance = new ContentThreatDetectionApi();
String value = "value_example"; // String | User-facing text input.
try {
StringSqlInjectionDetectionResult result = apiInstance.contentThreatDetectionCheckSqlInjectionString(value);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ContentThreatDetectionApi#contentThreatDetectionCheckSqlInjectionString");
e.printStackTrace();
}

Say goodbye to SQLI.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.