Opened 8 weeks ago

Closed 8 weeks ago

Last modified 8 weeks ago

#35627 closed Bug (fixed)

LocaleMiddleware does not handle ValueError 'lang_code' exceeds the maximum accepted length

Reported by: Lorenzo Peña Owned by: Lorenzo Peña
Component: Internationalization Version: 5.0
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Try any Django powered site where LocaleMiddleware is enanled and visit domain.com/aaaaaaaaaaa.... (where there are 1000 'a').
This line kicks in: https://github.com/django/django/blob/main/django/utils/translation/trans_real.py#L520

I think the outcome should be a 404 instead of raising ValueError all the way up.

Change History (10)

comment:1 by Lorenzo Peña, 8 weeks ago

Owner: set to Lorenzo Peña
Status: newassigned

comment:2 by Lorenzo Peña, 8 weeks ago

Has patch: set

comment:3 by Sarah Boyce, 8 weeks ago

Component: UncategorizedInternationalization
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Regression in 9e9792228a6bb5d6402a5d645bc3be4cf364aefb
Perhaps we should raise a LookupError rather than a ValueError, I believe this needs backporting to 4.2, 5.0, 5.1

comment:4 by Lorenzo Peña, 8 weeks ago

I'd be happy to break the ice with Django contributions with this one, if possible. In the PR I am catching both ValueError and LookupError in the callers. I am happy to also raise LookupError instead and not modify anything else.

comment:6 by Sarah Boyce, 8 weeks ago

Summary: LocaleMiddleware: 'lang_code' exceeds the maximum accepted lengthLocaleMiddleware does not handle ValueError 'lang_code' exceeds the maximum accepted length
Triage Stage: AcceptedReady for checkin

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 8 weeks ago

Resolution: fixed
Status: assignedclosed

In 0e94f29:

Fixed #35627 -- Raised a LookupError rather than an unhandled ValueError in get_supported_language_variant().

LocaleMiddleware didn't handle the ValueError raised by
get_supported_language_variant() when language codes were
over 500 characters.

Regression in 9e9792228a6bb5d6402a5d645bc3be4cf364aefb.

comment:8 by Sarah Boyce <42296566+sarahboyce@…>, 8 weeks ago

In 741f33ea:

[5.1.x] Fixed #35627 -- Raised a LookupError rather than an unhandled ValueError in get_supported_language_variant().

LocaleMiddleware didn't handle the ValueError raised by
get_supported_language_variant() when language codes were
over 500 characters.

Regression in 9e9792228a6bb5d6402a5d645bc3be4cf364aefb.

Backport of 0e94f292cda632153f2b3d9a9037eb0141ae9c2e from main.

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 8 weeks ago

In e186012:

[5.0.x] Fixed #35627 -- Raised a LookupError rather than an unhandled ValueError in get_supported_language_variant().

LocaleMiddleware didn't handle the ValueError raised by
get_supported_language_variant() when language codes were
over 500 characters.

Regression in 9e9792228a6bb5d6402a5d645bc3be4cf364aefb.

Backport of 0e94f292cda632153f2b3d9a9037eb0141ae9c2e from main.

comment:10 by Sarah Boyce <42296566+sarahboyce@…>, 8 weeks ago

In 96a34974:

[4.2.x] Fixed #35627 -- Raised a LookupError rather than an unhandled ValueError in get_supported_language_variant().

LocaleMiddleware didn't handle the ValueError raised by
get_supported_language_variant() when language codes were
over 500 characters.

Regression in 9e9792228a6bb5d6402a5d645bc3be4cf364aefb.

Backport of 0e94f292cda632153f2b3d9a9037eb0141ae9c2e from main.

Note: See TracTickets for help on using tickets.
Back to Top