ERR_BLOCKED_BY_XSS_AUDITOR 使用 selenium 下载文件时

ERR_BLOCKED_BY_XSS_AUDITOR when downloading file using selenium

我正在尝试使用 selenium 通过模拟点击下载按钮来下载文件,但 Chrome 报告 ERR_BLOCKED_BY_XSS_AUDITOR。如果我使用 "--disable-xss-auditor" 参数绕过,页面将重新加载并且不会下载任何内容。令我感到奇怪的是,当我在甚至由 selenium 控制的 Chrome 会话中实际使用鼠标下载文件时,文件下载效果很好。

请帮助我理解 xss auditor 的作用?为什么我不能下载带有 selenium 的文件?

顺便说一句,如果重要的话,我正在使用 python

谢谢

XSS Auditor 是 Chrome 和 Safari 的内置功能,旨在缓解跨站点脚本 (XSS) 攻击。它旨在识别查询参数是否包含恶意 JavaScript 并在它认为有效载荷被注入服务器响应时阻止响应。

XSS 是当数据被(错误)解释为代码并在受害者的浏览器上执行时发生的漏洞。这个想法是使用像 Selenium WebDriver 这样的无头浏览器,并注入 XSS 有效载荷以及功能和用户交互测试

Python 与此无关,我认为可能是 chrome 版本或其他

我已经分享了 link 这将帮助您更好地理解。

我放慢了点击速度(下载需要 2 次点击,在它们之间添加了休眠)并且它有效!不知道发生了什么...

X-XSS-保护

禁用内联Java脚本('unsafe-inline')的HTTPX-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks. Although these protections are largely unnecessary in modern browsers when sites implement a strong Content-Security-Policy,它们仍然可以为用户提供保护尚不支持 CSP 的旧版 Web 浏览器。

Header type               Response header
-----------               ---------------
Forbidden header name     no

语法

  • X-XSS-Protection: 0: 禁用 XSS 过滤。
  • X-XSS-Protection: 1:启用 XSS 过滤(通常在浏览器中默认)。如果检测到跨站点脚本攻击,浏览器将清理页面(删除不安全的部分)。
  • X-XSS-Protection: 1: mode=block 启用 XSS 过滤。如果检测到攻击,浏览器将阻止呈现页面,而不是清理页面。
  • X-XSS-Protection: 1: report=(仅限 Chromium) 启用 XSS 过滤。如果检测到跨站点脚本攻击,浏览器将清理页面并报告违规行为。这使用 CSP report-uri 指令的功能来发送报告。

背景

根据 Intent to Ship: Changes to the XSS Auditor Chromium 团队进行了两项更改:

  • 将默认行为更改为 X-XSS-Protection: 1; mode=block,这会在检测到 XSS 时通过导航到唯一来源来阻止页面加载,而不是过滤掉特定的脚本。
  • 弃用过滤模式,打算在将来某个时候将其完全删除。

执行情况

XSS Auditor blocks by default: Chrome 的 XSS Auditor 应该默认阻止页面,而不是过滤掉可疑的反射 XSS。此外,我们应该删除过滤选项,因为过去破坏页面脚本的特定部分本身就是一个 XSS 向量。

根据 XSS Auditor: Block by default, remove filtering this issue was discussed and a fix was attempted. Some more discussion happened in False positives with ERR_BLOCKED_BY_XSS_AUDITOR and finally in ERR_BLOCKED_BY_XSS_AUDITOR on bona fide site when posting to a forum Chromium 团队决定 状态:WontFix

解决方案

您需要诱导 WebDriverWait 以使所需的 元素可点击 。以下是 WebDriverWait 实现的一些示例:

  • Java:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("text_within_the _link"))).click(); 
    
  • Python:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "text_within_the _link"))).click()
    
  • C#:

    new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.LinkText("text_within_the _link"))).Click();
    

参考