Opened 3 years ago

Last modified 2 years ago

#29490 new New feature

Subresource integrity for form assets

Reported by: Meiyer Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


SRI gives the web site author some guarantees that an external resource (typically, a script), included within the web page, has not been altered. For example, various external libraries are loaded from a CDN or another third-party repository, implicitly trusting that repositories’ security, but these libraries can be modified or tampered with to include malicious code, with the web site author not aware that this malicious code is now running on their web site in the context of their own web application. SRI prevents the loading of such resources if they were modified.

SRI is implemented by the means of the “integrity” attribute on the <LINK> and <SCRIPT> HTML elements. It is relevant to Django, because the form assets (“Media”) may point to resources on external repositories. But Django does not allow any way to specify the “integrity“ attribute (and the “crossorigin” attribute) for the assets of the forms.

I suggest modifying the Media class definitions such that the assets are not a simple list but a dict (with keys such as src, integrity, crossorigin), resulting in corresponding HTML elements being rendered appropriately. There can be a fallback to the simpler case when a list or tuple is provided, for backwards-compatibility.

Change History (3)

comment:1 Changed 3 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 3 years ago by Tim Graham

I'd say maybe. There's also some thought in #22298 to deprecate the Media class.

comment:3 Changed 2 years ago by Claude Paroz

Based on what I suggested in #29586 and this discussion, here's what could be a possible implementation (still WIP):

Considering it was suggested the original proposal should be first implemented as a 3rd party app, I don't want to go further without a green light for integrating such an implementation to Django.

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