I have a web application and I used OWASP ZAP for checking XSS. I tried two cases as example bellow:
URL: localhost:8888/test/login
Öogin page HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>Login Page</title>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<h3>Login with email and password</h3>
<form id="testForm" action="login" method="post">
<strong>User Email</strong>:<input type="text" name="email" id="email"><br>
<strong>Password</strong>:<input type="pass" name="pass" id="pass"><br>
<input type="submit" value="Login" id="subForm">
<div id="result"><%=request.getAttribute("email")%></div>
</form>
<br>
If you are new user, please <a href="register.html">register</a>.
</body>
</html>
Case 1: Application return HTML (HTML response)
Start ZAP
Submit login form
Choose Active scan XSS for this URL: localhost:8888/test/login
Result: ZAP found 1 XSS alert script
Case 2: Application return JSON (REST API)
URL: localhost:8888/api/login
Request JSON data format: {"email":"abc", "pass": "123456"}
Response JSON data format: {"email":"abc", "pass": "123456"}
Using Ajax to call API with JSON request
<script> function sendAjax() { var user = new Object(); var email = $('#email').val(); var pass = $('#pass').val(); $.ajax({ url: "localhost:8888/api/login", type: 'POST', dataType: 'json', data: JSON.stringify({"email":email,"pass":pass}), contentType: 'application/json', mimeType: 'application/json', success: function (data) { $("#result").html("email: "+data.email+" pass: "+data.pass) }, error:function(data,status,er) { alert("error: "+data+" status: "+status+" er:"+er); } }); } </script>
Start ZAP
Click button summit (call sendAjax function to send request data)
Choose Active scan XSS for this URL: localhost:8888/api/login
Result: Nothing found
What exactly I want to known is that: ZAP can check for XSS in rest API or not? If it can't then how can I check for XSS in this API (case 2)?