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

When pyramid.debug_authorization is enabled, invalid Unicode HTTP request raises URLDecodeError #3736

Closed
mckea opened this issue Nov 29, 2023 · 1 comment · Fixed by #3741

Comments

@mckea
Copy link

mckea commented Nov 29, 2023

Defining an error view for URLDecodeError will handle HTTP requests containing invalid Unicode characters, but if pyramid.debug_authorization is enabled in the application config file, a URLDecodeError is still raised on this line:

url = getattr(request, 'url', None)

To reproduce, define an error view for URLDecodeError:

from pyramid.exceptions import URLDecodeError
from pyramid.httpexceptions import HTTPBadRequest
from pyramid.security import NO_PERMISSION_REQUIRED

@view_config(                                                                    
    context=URLDecodeError,                                                      
    permission=NO_PERMISSION_REQUIRED                                            
)                                                                                
def url_decode_error_view(context, request):                                     
    return HTTPBadRequest()

In the application config file, set pyramid.debug_authorization = true

Make a request containing invalid unicode:

wget http://127.0.0.1:6543/%EF%BF

This will raise an exception and return a 500.

Repeating this with pyramid.debug_authorization = false will handle the exception properly and return a 400.

@mmerickel
Copy link
Member

Thanks for reporting this - I've uncovered a couple bugs in the code related to this.

  1. I recommend that you use exception_view_config as there are some explicit optimizations in the code.
  2. Even if you did that, there were still some issues that I've fixed in fix secured views to avoid being applied to exception views #3741.

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

Successfully merging a pull request may close this issue.

2 participants