APIHow to Block Insecure Deserialization Threats in JSON Files using JavaScript

Cloudmersive
1 min readJun 26, 2023

--

Validating and sanitizing JSON object serialization files before uploading them to a sensitive application is vitally important to avoid JID (JSON Insecure Deserialization) and other forms of cyber-attack. Using the below code, you can identify and block insecure deserialization threats, manually restrict file upload types to a limited number of extensions AND scan all file uploads for millions of virus and malware signatures — all in one API request.

You can structure your API call using the following ready-to-run JavaScript code examples (with XHR capability):

var data = new FormData();
data.append("inputFile", fileInput.files[0], "file");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});

xhr.open("POST", "https://api.cloudmersive.com/virus/scan/file/advanced");
xhr.setRequestHeader("allowExecutables", "<boolean>");
xhr.setRequestHeader("allowInvalidFiles", "<boolean>");
xhr.setRequestHeader("allowScripts", "<boolean>");
xhr.setRequestHeader("allowPasswordProtectedFiles", "<boolean>");
xhr.setRequestHeader("allowMacros", "<boolean>");
xhr.setRequestHeader("allowXmlExternalEntities", "<boolean>");
xhr.setRequestHeader("allowInsecureDeserialization", "<boolean>");
xhr.setRequestHeader("allowHtml", "<boolean>");
xhr.setRequestHeader("restrictFileTypes", "<string>");

xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");

xhr.send(data);

You can complete your request with a free-tier Cloudmersive API key (this comes with a limit of 800 API calls per month and no commitment).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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