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

Fix badly encoded paths with an exception view instead #9

Open
seanh opened this issue Aug 27, 2020 · 0 comments
Open

Fix badly encoded paths with an exception view instead #9

seanh opened this issue Aug 27, 2020 · 0 comments

Comments

@seanh
Copy link
Contributor

seanh commented Aug 27, 2020

Pyramid actually raises a specific URLDecodeError when there's a badly-encoded path component, but by default it 500s because there isn't a builtin exception view for URLDecodeError. Apps or extensions can register a custom exception view to catch this and turn it into a 400:

@view_config(context=URLDecodeError)
def url_decode_error(request):
    return HTTPBadRequest()

This is simpler than our current invalid_path_info_tween_factory() and is also the right solution according to the Pyramid docs for URLDecodeError and multiple GitHub comments from Pyramid maintainers.

Unfortunately Pyramid does not raise URLDecodeError for badly encoded query params, so that one will still have to be fixed by a tween.

See Pylons/pyramid#312 (comment) (and there are also several other maintainer comments on GitHub telling people to use an exception view for this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant