Reflected cross-site scripting (XSS)
Description
The web application dynamically generates web content without validating the source of the potentially untrusted data.
Impact
Generate web pages that could contain malicious scripts injected into untrusted data.
Recommendation
Perform input data validations on the server-side to avoid common script injection attacks.
Threat
Authenticated attacker from the Internet.
Expected Remediation Time
โ 45 minutes.
Score
Default score using CVSS 3.1. It may change depending on the context of the vulnerability.
Base
- Attack vector: N
- Attack complexity: L
- Privileges required: N
- User interaction: R
- Scope: U
- Confidentiality: N
- Integrity: L
- Availability: N
Temporal
- Exploit code madurity: X
- Remediation level: X
- Report confidence: X
Result
- Vector string: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N/E:X/RL:X/RC:X
- Score:
- Base: 4.3
- Temporal: 4.3
- Severity:
- Base: Medium
- Temporal: Medium
Code Examples
Compliant code
Implement correct and secure validation of input data
namespace Controllers{
public class Calculate{
public static void ProcessRequest(HttpRequest req, HttpResponse res){
string name = req.QueryString["name"];
res.Write("Hello " + name);
string value = req.QueryString["value"];
//Server side validation of entry data
if (value == null || !Regex.IsMatch(value, "^[a-zA-Z0-9]+$")){
throw new InvalidOperationException("Invalid value");
}
res.AddHeader("X-Header", value);
}
}
}
Non compliant code
A method that reads input data and does not properly validate the information, so an XSS attack could still be executed
public void bad(HttpServletRequest request, HttpServletResponse response) throws Throwable{
String data = "";
Socket socket = null;
BufferedReader readerBuffered = null;
InputStreamReader readerInputStream = null;
try{
socket = new Socket("host.example.org", 39544);
readerInputStream = new InputStreamReader(socket.getInputStream(), "UTF-8");
readerBuffered = new BufferedReader(readerInputStream);
data = readerBuffered.readLine();
}
catch (IOException exceptIO){
IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO);
}
// Not shown: Code to close the socket...
if (data != null){
//* POTENTIAL FLAW: Display of data in web page after using replaceAll() to remove script tags,
// which will still allow XSS with strings like <scr<script>ipt>
response.getWriter().println("<br>bad(): data = " + data.replaceAll("(<script>)", ""));
}
}