#36000 closed Cleanup/optimization (fixed)

Update default from http to https in urlize when protocol not provided

Reported by: Saravana Owned by: Ahmed Nassar
Component: Template system Version: 5.1
Severity: Normal Keywords:
Cc: Saravana Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Sarah Boyce)

In django/utils/html.py, urlize there is:

url = smart_urlquote("http://%s" % html.unescape(middle))

When user input does not include a protocol it defaults to http (Insecure Protocol).

Example :
Considered a web app using urlize() for password reset email template

input = "Password reset link myapp.com/password/reset/{token}"

output:

"Password reset link <a href="http://myapp.com/password/reset/{token}"/>"

so when end user of myapp clicks it the url with token sent in http insecure protocol.
This behavior could potentially lead to man-in-the-middle attacks

Suggested Fix:
Default to HTTPS: If the URL doesn't specify a protocol, Django could default to ​https://

Change History (22)

comment:1 by Sarah Boyce, 23 months ago

Description: modified (diff)
Has patch: unset
Summary: Insecure URL Handling (HTTP Protocol Default) in urlize → Update default from http to https in urlize when protocol not provided
Triage Stage: Unreviewed → Accepted

Thank you!
Note that the security team discussed this and agreed this can be handled publicly. This is similar to #34380.

comment:2 by Sarah Boyce, 23 months ago

Component: HTTP handling → Template system

comment:3 by Saravana, 23 months ago

Owner: set to Saravana
Status: new → assigned

comment:4 by Adam Johnson, 22 months ago

I think we can use a plan similar to how #34380 shook out, with a plan like:

  1. Introduce a transitional setting (URLIZE_ASSUME_HTTPS) that defaults to False. This goes on the deprecation plan for removal in N+2 versions.
  2. When the ​responsible code path is hit (which should be fairly rare as it only applies to ​limited domains), check the setting. If it’s False, warn and use 'http', otherwise use 'https'.

comment:5 by Saravana, 21 months ago

Yeah sure,
i will work on that

comment:6 by IronJam, 21 months ago

I will be happy to work on this one if its available

comment:7 by Ahmed Nassar, 20 months ago

I’d love to contribute to this issue.

in reply to:  7 comment:8 by Saravana, 20 months ago

Replying to Ahmed Nassar:

I’d love to contribute to this issue.

Yeah you can work on it

Last edited 20 months ago by Saravana (previous) (diff)

comment:9 by Saravana, 20 months ago

Owner: changed from Saravana to Ahmed Nassar

comment:10 by Ahmed Nassar, 20 months ago

I've submitted a pull request for this ticket:
​https://github.com/django/django/pull/19240

The PR adds URLIZE_ASSUME_HTTPS setting to control the default protocol in urlize(), improving security by defaulting to HTTPS.

Version 0, edited 20 months ago by Ahmed Nassar (next)

comment:11 by Ahmed Nassar, 20 months ago

Has patch: set

comment:12 by Sarah Boyce, 19 months ago

Patch needs improvement: set

comment:13 by Ahmed Nassar, 19 months ago

I have completed all requested changes in the PR ​https://github.com/django/django/pull/19240, including:

Addressing all review comments.
Pushing a commit with the latest updates.
Ensuring all tests pass successfully.
Updating the documentation to reflect the introduced URLIZE_ASSUME_HTTPS setting.

Additionally, I have added and updated some tests and documentation to ensure proper coverage and clarity. Given that the Trac ticket currently has "Needs tests: No" and "Needs documentation: No", should these be updated to "Needs tests: Yes" and "Needs documentation: Yes" to reflect these additions?

Last edited 19 months ago by Ahmed Nassar (previous) (diff)

comment:14 by Sarah Boyce, 19 months ago

Additionally, I have added and updated some tests and documentation to ensure proper coverage and clarity. Given that the Trac ticket currently has "Needs tests: No" and "Needs documentation: No", should these be updated to "Needs tests: Yes" and "Needs documentation: Yes" to reflect these additions?

Yes when you want another review, you should do this as it will put the ticket in the review queue. I have given a review, so once you've resolved those comments you can update this ticket

comment:15 by Ahmed Nassar, 19 months ago

Thank you for the review and clarification.

Looking forward to your review and feedback!

Last edited 19 months ago by Ahmed Nassar (previous) (diff)

comment:16 by Ahmed Nassar, 19 months ago

Needs documentation: set
Needs tests: set

comment:17 by Ahmed Nassar, 19 months ago

Needs documentation: unset
Needs tests: unset

comment:18 by Ahmed Nassar, 19 months ago

Patch needs improvement: unset

comment:19 by Sarah Boyce, 19 months ago

Patch needs improvement: set

comment:20 by Ahmed Nassar, 19 months ago

Patch needs improvement: unset

comment:21 by Sarah Boyce, 19 months ago

Triage Stage: Accepted → Ready for checkin

comment:22 by Sarah Boyce <42296566+sarahboyce@…>, 19 months ago

Resolution: → fixed
Status: assigned → closed

In ec7044c7:

Fixed #36000 -- Deprecated HTTP as the default protocol in urlize and urlizetrunc.

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