在javascript的文章中sink指什么?

发布时间 2023-03-22 21:11:27作者: saaspeter
在介绍xss的英文文章中常看到sink这个词语。查了下:

A sink is a potentially dangerous JavaScript function that can caused undesirable effects if attacker controlled data is passed to it. Basically, if the function returns input back to the screen as output without security checks, it’s considered a sink. An example of this would be the “innerHTML” property used earlier as that changes the contents of the HTML page to whatever is given to it.

Common sinks include:

  • document.write()
  • document.writeln()
  • document.domain
  • element.innerHTML
  • element.outerHTML
  • element.insertAdjacentHTML
  • element.onevent

以上来自于:Understanding DOM-Based XSS: Sources and Sinks | by FATH3AD | Medium

我也问了chatgpt。

问:在关于javascript的介绍中经常有sink这个词,请问sink在这里是指什么?

答:在 JavaScript 中,"sink" 通常指的是一个函数或对象,该函数或对象在代码执行期间接收并处理系统中的所有事件、请求、错误等,类似于一个管道或汇聚点,将所有的数据流汇集到一起。

Sink 通常用于捕获和处理 JavaScript 中的异常、错误和警告信息,以及浏览器中的网络请求、鼠标点击、键盘输入等事件。例如,可以使用 sink 来记录日志、统计用户行为、分析性能瓶颈等。

在某些情况下,"sink" 还可以指代一种攻击方式,即将恶意数据或代码注入到系统中的某个接收点或处理器中,从而控制或破坏系统的正常运行。这种攻击方式通常被称为 "sinkhole attack" 或 "sink attack"。