The Drakes answer above bothered me, so I created a simple proof of concept to make sure I was right. I. Even with Content-Type: text/plain;charset=UTF-8 application can be compromised with a simple XSS attack.
The reason I tried to explain below for the first time is because the data processing and the possible context of the final destination and data rendering are important. Transport is not so important. I created a simple servlet that returns a response in the same way as an OP, including the Content-Type header. Here is the answer:
HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 Cache-Control: no-cache Content-Type: text/plain;charset=UTF-8 Content-Length: 73 Date: Thu, 18 Jun 2015 22:49:01 GMT Connection: close Invalid project area item id <iframe src=javascript:alert(1)></iframe>
And here is the image of the result. Please note that the attack payload has been executed: https://flic.kr/p/uRnSgo
Again, the reason is very simple. Data is not displayed in an AJAX request, but on a consumer web application page that has an HTML page.
In any case, I hope that in some cases it eliminates any doubts about the vulnerability ... especially when the response to the AJAX request that will be displayed on the consumption page.
----- Below is my initial answer. -----
A 400 response with an error message drops out of the REST API response.
If it was a REST request ( X-Requested-With: XMLHttpRequest or Accept: application/json in the request headers), you are facing a serious problem. Although this answer is not affected, the data is likely to be displayed and displayed in the end user UI on the consumption page. Since it is not correctly encoded, it performs . This is not always the answer you need to worry about, but the possible location of the attack payload. Assuming this is a response to an XMLHttpRequest or REST call, this is a serious error.
You can test using the <iframe src=javascript:alert(1)></iframe> attack payload, and I'm sure you will see that pop in the consuming application.
I would suggest: Invalid project area item id and leave an invalid value. The cheapest solution.
So you cannot rely on Content-Type at all to save you. Data may be displayed in a different context where .
Always check the input and correctly process the output, which may include encoding in some format or in another, depending on the context in which it will be displayed. Anyone who tells you otherwise is trying to get out of some necessary work. :-)