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

Repaired 404 exemption inconsistency #220

Merged

Conversation

twolfson
Copy link
Contributor

We have noticed an inconsistent behavior for when a 404 is being exempted/not exempted from a CSRF check.

Initially in our repo, we had no @csrf.exempt calls and so a test like the following would receive a CSRF error (not a 404):

@app.route('/foo', methods=('GET', 'POST'))
def my_handler():
  return 'ok'

# CSRF error encountered on this request
self.app.post('/not-an-endpoint')

However, after we add an @csrf.exempt to an existing endpoint, we noticed that we would instead yield a 404 at the endpoint in our tests:

@csrf.exempt
@app.route('/foo', methods=('GET', 'POST'))
def my_handler():
  return 'ok'

#404 encountered on this request, not a CSRF error
self.app.post('/not-an-endpoint')

This inconsistent behavior is undesirable as some people might be writing integration tests to verify CSRF works.

To remedy that, we have decided to exempt all 404 requests to CSRF checks. In this PR:

  • Relocated 404 exemption for CSRF checks outside of self._exempt_views or self._exempt_blueprints conditional

@davidism davidism added the csrf label Jul 3, 2016
@davidism davidism modified the milestone: v0.14 Sep 29, 2016
@davidism davidism merged commit f306c36 into wtforms:master Oct 9, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

2 participants