【问题标题】:Why is CheckMarx flagging this code as an XSS vulnerability?为什么 CheckMarx 将此代码标记为 XSS 漏洞?
【发布时间】:2022-04-17 16:06:22
【问题描述】:

CheckMarx 将该组件标记为易受攻击。我不明白为什么。我不确定 CheckMarx 对 React 代码的理解程度,我不知道我会如何安抚 CheckMarx。

错误是Client_DOM_XSS: The application\'s renderes untrusted data embeddings untrusted data in generated output with state, 在 react-app\\src\\visualizer\\Visualization.js 的第 25 行。这种不受信任的数据直接嵌入到输出中,没有经过适当的清理或编码,使攻击者能够将恶意代码注入到输出中。

任何人都可以帮忙吗?

import React, {Component} from \'react\';


export default class Visualization extends Component {
    constructor(props) {
        super(props);
        this.state = {
            x: null,
        };
    }

    componentDidUpdate(prevProps, prevState, snapshot) {
        if(!this.props.x) {
            this.setState({
                x: null,
            });
        } else if(this.props.x !== prevProps.x) {
            this.setState({
                x: this.props.x,
            });
        }
    }

    render() {
        return (<div>X: {this.state.x}</div>)
    }
}
  • 看起来像 checkmarx 中的错误。

标签: reactjs checkmarx


【解决方案1】:

您提供的代码 sn-p 确实不易受到 XSS 的攻击。

我用 Checkmarx 的 SAST(最新版本)扫描了代码 sn-p,但无法重现结果。你有机会使用旧版本吗?

还值得一提的是,在某些情况下,可能会出现 XSS,例如,如果输入嵌入在 IFrame 元素的srcdoc 属性中(注意,在当前的 sn-p 中,不能说状态是否和道具受用户输入的影响)。

我希望这会有所帮助。

【讨论】:

  • 扫描由 Checkmarx Enterprise V9.4.4 HF10 运行。那是最新版本吗?简化代码后,道具被硬编码为简单的输入,并且该组件仅实例化一次,而不是在 iFrame 中。该漏洞仍然突出显示。
猜你喜欢
  • 1970-01-01
  • 2018-01-01
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2023-04-07
  • 1970-01-01
相关资源
最近更新 更多