Automatically Detect Threats in an Input String using Java

Our content threat detection API helps you avoid some of the most common & explosive application security threats out there. It’ll auto-detect threats in an input string including Cross-Site Scripting (XXS) attacks, SQL Injection (SQLI), XML External Entities, Server-Side Request Forgeries (SSRF), and JSON Insecure Deserialization (JID).

You can take advantage of this API for free using Java (or any of 12 other programming languages with code from the Cloudmersive API Console) by following a few simple steps below:

Start by adding the below reference to the Maven repository in pom.xml:

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

Then, add a reference to the Maven dependency in pom.xml:

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

Finally, copy in the remaining code snippets to complete the validation function, and you’re all set:

// 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 {
StringAutomaticThreatDetection result = apiInstance.contentThreatDetectionAutomaticThreatDetectionString(value);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ContentThreatDetectionApi#contentThreatDetectionAutomaticThreatDetectionString");
e.printStackTrace();
}

You’ll receive an API response within seconds containing a list of potential threats and whether there is one present (true) or not (false). Check out the below JSON response model for reference.

To install with Gradle instead — visit the Cloudmersive API Console and find the relevant installation instructions within this API’s dropdown menu.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

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