pallets-eco / pallets-eco/flask-debugtoolbar
Use CSRF header on ajax calls, if available
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 978
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I just discovered template editor, but was unable to preview and save template edits.
After further inspection, it seems to be that in template_editor.html' all ajax calls don't use the CSRF header provided by Flask-WTF.
The code suggested in their site regarding javascript requests has no effect.
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrf_token);
}
}
});
I hope it can be fixed, thanks for this great tool.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in flask_debugtoolbar/templates/panels/template_editor.html around the AJAX calls linked in the issue, then compare them with Flask-WTF's JavaScript request guidance. Done means template preview and save work when CSRF protection is enabled, while requests still behave appropriately when no token is available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, javascript, python
- Domain
- frontend, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100