Detect XXE Attacks from XML Text Input in Go

A motivated hacker with XXE attacks in his arsenal can be a dire threat to your system. Never fear — you can easily detect this form of attack by inputting suspicious XML text into our XXE Security API iteration. In a few short seconds, you can find out if XML text contains an XXE attack (‘true’) or not (‘false’), and put yourself in a position to stop the issue quickly. Use the below code examples to connect in Golang, or head to the Cloudmersive API Console and select one of 13 common programming languages to connect in.

First things first — if you don’t currently have a Cloudmersive API key, head to our website (www.Cloudmersive.com) and create a free account to receive an API key with 800 monthly API calls. After that, copy the below code and include your XML string where indicated:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/security/threat-detection/content/xxe/detect/xml/string"
method := "POST"
payload := strings.NewReader(`"<string>"`)client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

--

--

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

Cloudmersive

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