Skip to content
← Back to rules

react/jsx-no-script-url Suspicious

🚧 An auto-fix is planned for this rule, but not implemented at this time.

作用

禁止使用 javascript: URL。

为什么这不好?

javascript: 开头的 URL 是一个危险的攻击面,因为很容易不小心 将未经过清理的输出包含到像 <a href> 这样的标签中,从而造成安全漏洞。

从 React 16.9 开始,任何以 javascript: 开头的 URL 都会记录警告。

在 React 19 中,javascript: URL 会被 完全禁止

示例

此规则的错误代码示例:

jsx
<a href="javascript:void(0)">Test</a>

此规则的正确代码示例:

jsx
<Foo test="javascript:void(0)" />

配置

此规则接受一个包含以下属性的配置对象:

components

type: Record<string, array>

default: {}

要额外检查的组件。

includeFromSettings

type: boolean

default: false

是否包含来自设置中的组件。

使用方法

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["react"],
  "rules": {
    "react/jsx-no-script-url": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["react"],
  rules: {
    "react/jsx-no-script-url": "error",
  },
});
bash
oxlint --deny react/jsx-no-script-url --react-plugin

版本

此规则于 v0.13.2 中添加。

参考资料