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: Unintended form submit at CommandButton click #9424

Closed
mihaiDumea opened this issue Nov 18, 2022 · 6 comments · Fixed by #9425
Closed

CSP: Unintended form submit at CommandButton click #9424

mihaiDumea opened this issue Nov 18, 2022 · 6 comments · Fixed by #9425
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@mihaiDumea
Copy link

Describe the bug

With CSP enabled, form submit event gets triggered after a commandButton is triggered. Two HTTP requests are generated instead of one.
jsWrapper does not manage to cancel the default action of the event. Maybe the event.cancelable property should be checked only if available, like typeof event.cancelable !== 'boolean' || event.cancelable.

Reproducer

 <h:form>
    <p:commandButton id="cb" action="#{mb.action}" />
    <p:commandButton id="cb2" value="cb2" onclick="$('#cb').click();return false;" type="button" />
 </h:form>

Click on the cb2.

Expected behavior

Generate only one HTTP request(for commandButton).

PrimeFaces edition

No response

PrimeFaces version

11.0.0

Theme

No response

JSF implementation

Mojarra

JSF version

2.2.19

Java version

1.8

Browser(s)

Especially on Chrome

@mihaiDumea mihaiDumea added ‼️ needs-triage Issue needs triaging 🐞 defect Bug...Something isn't working labels Nov 18, 2022
@melloware
Copy link
Member

Have you tested a fix?

@mihaiDumea
Copy link
Author

Yes I had

@mihaiDumea
Copy link
Author

From here I got the inspiration: https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable

@melloware
Copy link
Member

OK check out my PR I think it makes sense.

@melloware melloware removed the ‼️ needs-triage Issue needs triaging label Nov 18, 2022
@melloware melloware self-assigned this Nov 18, 2022
@melloware melloware added this to the 13.0.0 milestone Nov 18, 2022
@mihaiDumea
Copy link
Author

Indeed. Without CSP would have an inline event handler onclick="PrimeFaces.ab({...});return false;" and returning false is enough to prevent the default action, either generating the event by the browser and having the event.cancelable defined, or triggering it via JQuery and having event.cancelable undefined.

@melloware
Copy link
Member

Thanks for the report and the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants