当用户尝试访问任何未经身份验证的 URL(包括不存在的 URL)时,我的 Web 服务会返回 HTTP 401 响应。此响应是 JSON 编码的,并且此响应的正文包含用户请求的路径,可能是出于诊断目的。响应还包括www-authenticate标头。如果用户在浏览器中访问此 URL,则会触发他们的浏览器要求提供凭据。
但是,自动扫描工具报告这是一个 XSS 漏洞。这似乎是因为包含了请求的路径,并且如果请求的路径也恰好是有效的 JavaScript,则此路径与响应一起返回。请参阅下面的 cURL 输出:
curl -i 'https://myservice.example.com/<script>alert(1)</script>'
HTTP/2 401
server: nginx
date: Tue, 19 May 2020 15:02:20 GMT
content-type: application/json;charset=UTF-8
content-length: 167
strict-transport-security: max-age=31536000 ; includeSubDomains
www-authenticate: Basic realm="Spring"
{"timestamp":1589900540080,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/<script>alert(1)</script>"}%
我认为这是一个误报,因为 API 响应是 JSON 编码的,根据这个问题:Reflected XSS via JSON execute with Burp, but how to do it in real conditions?
我对么?