Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSP blocks the delay script block #94

Open
phiw13 opened this issue Sep 2, 2024 · 3 comments
Open

CSP blocks the delay script block #94

phiw13 opened this issue Sep 2, 2024 · 3 comments

Comments

@phiw13
Copy link

phiw13 commented Sep 2, 2024

Textpattern 4.9dev, plugin version:4.9.0-beta.

Relevant CSP setting: script-src-elem 'strict-dynamic' '<txp:smd_token name="csp_token" prefix="nonce-" />'

Add a honeypot field to the form: <txp:com_connect_text hidden label="" name="r_u_human" default="yes" expected="yes" delay="6" required="0" />

The script block as inserted

<script>document.addEventListener("DOMContentLoaded", () => {
    let theForm = document.getElementById('com31f8a29dd4f03ba39d7ddc447d33add7');
    theForm.addEventListener("focusin", (ev) => {
    setTimeout(function() {
    let fedadccecfb = document.getElementById("com31f8a29dd4f03ba39d7ddc447d33add7");
    fedadccecfb.insertAdjacentHTML('beforeend', '<input class="comText" id="r_u_human" name="r_u_human" type="text" value="yes" maxlength="100" form="com31f8a29dd4f03ba39d7ddc447d33add7" hidden>');
}, (["6"][["6"].length * Math.random() | 0]) * 1000);
}, { once: true })
});</script>

The browser blocks this as no nonce is specified.

Expected: <script nonce="xxxxxx">…</script>

Result: on submitting the form it is treated as spam.

@phiw13
Copy link
Author

phiw13 commented Sep 2, 2024

I should have noted this. The nonce is added to each script or style via the smd_token plugin and
script src="nnnnn" nonce="<txp:smd_token name="csp_token" />"></script>. The value is generated once at the very start of the page template.

@Bloke
Copy link
Member

Bloke commented Sep 2, 2024

That's really odd. com_connect uses script_js() to inject the delay JavaScript code, which is internally wired to use UI\Script, which is internally wired to add CSP nonces where necessary. We'll have to try and chase this through to find out why it's not adding them to the page in this case.

Thank you for the report.

@phiw13
Copy link
Author

phiw13 commented Sep 3, 2024

Hmm. This the public side of the website. How would that detect how the nonce is currently generated (currently via the smd_token plugin)? If some ideas discussed in issue 1933 are implemented that might be possible. For nowI have to add the nonce in my templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants