Configuration Management / Content Type Incorrectly Stated
Content type incorrectly stated, also known as CWE-200, is a type of vulnerability related to configuration management in web and API applications. It occurs when an application incorrectly states the content type of a response when the content type is not correctly given by the application. This can be dangerous because maliciously crafted content can be interpreted as safe by the application, allowing attackers to perform malicious activities such as cross-site scripting. According to the OWASP Testing Guide, this vulnerability can be detected through manual testing and automated scanning.
Content type incorrectly stated is a medium risk vulnerability as it can allow attackers to bypass security restrictions and execute malicious scripts on the application. If left unchecked, this vulnerability can lead to the disclosure of sensitive data or other malicious activities.
The best way to mitigate the risk of content type incorrectly stated is to properly set the content type of all responses. This should be done by setting the ‘Content-Type’ header in the response to the correct value. Additionally, input validation should be performed to ensure that the content type is valid before setting the response’s content type.
The following code example shows how to set the content type for a response in an Express application.