pallets-eco / pallets-eco/flask-debugtoolbar

Use CSRF header on ajax calls, if available

Open
#156 7 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.