Change barcode scan form to use requestSubmit() to fix CSRF token error #1191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On the Label Scanner page I have developed scanning of LCSC barcodes. During testing the redirect to the Part page was not working and I was getting CSRF token errors and the request failing with a HTTP 422 error.
I noticed that the CSRF Token value being sent on the form submission had the placeholder text
scan_dialog[_token] csrf-token, so the token itself was not being generated and submitted.In the assets/controllers/csrf_protection_controller.js file it specifically states;
Sure enough the Label Scanner form submission was using
form.submit()and not the requiredform.requestSubmit(). This PR patches that bug so CSRF token is now correctly generated on form submission.I further note that this bug maybe present else where in the code as a grep shows;
The other possible bug is in the
assets/controllers/helpers/form_cleanup_controller.jsfile, but as I am not sure which part of the code this effects, I have not proposed a change here. However that could be the failure for other CSRF issues in #911 and #1095