{"id":16031782,"url":"https://github.com/realorangeone/django-sri","last_synced_at":"2025-05-08T19:49:35.424Z","repository":{"id":44031931,"uuid":"260696298","full_name":"RealOrangeOne/django-sri","owner":"RealOrangeOne","description":"Subresource Integrity for Django","archived":false,"fork":false,"pushed_at":"2025-04-24T19:51:48.000Z","size":139,"stargazers_count":19,"open_issues_count":9,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T20:42:20.667Z","etag":null,"topics":["django","security","sri","subresource-integrity"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-sri/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RealOrangeOne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"RealOrangeOne","ko_fi":"theorangeone","liberapay":"theorangeone","custom":["https://theorangeone.net/support/"]}},"created_at":"2020-05-02T13:47:09.000Z","updated_at":"2025-01-21T09:04:18.000Z","dependencies_parsed_at":"2023-02-12T09:20:25.340Z","dependency_job_id":"1ada4f21-d85e-47a3-958f-2d809c2bf53c","html_url":"https://github.com/RealOrangeOne/django-sri","commit_stats":{"total_commits":92,"total_committers":5,"mean_commits":18.4,"dds":0.25,"last_synced_commit":"e692699103e68712fee8c90a9df7c000120c9f91"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrangeOne%2Fdjango-sri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrangeOne%2Fdjango-sri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrangeOne%2Fdjango-sri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrangeOne%2Fdjango-sri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RealOrangeOne","download_url":"https://codeload.github.com/RealOrangeOne/django-sri/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253140980,"owners_count":21860534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","security","sri","subresource-integrity"],"created_at":"2024-10-08T21:05:36.769Z","updated_at":"2025-05-08T19:49:35.403Z","avatar_url":"https://github.com/RealOrangeOne.png","language":"Python","funding_links":["https://github.com/sponsors/RealOrangeOne","https://ko-fi.com/theorangeone","https://liberapay.com/theorangeone","https://theorangeone.net/support/"],"categories":[],"sub_categories":[],"readme":"# Django SRI\n\n![CI](https://github.com/RealOrangeOne/django-sri/workflows/CI/badge.svg)\n![PyPI](https://img.shields.io/pypi/v/django-sri.svg)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-sri.svg)\n![PyPI - Status](https://img.shields.io/pypi/status/django-sri.svg)\n![PyPI - License](https://img.shields.io/pypi/l/django-sri.svg)\n\n\n[Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) for Django.\n\n\n## Installation\n\n```\npip install django-sri\n```\n\nAnd add `sri` to your `INSTALLED_APPS`.\n\n## Usage\n\n### Template Tags\n\n__Note__: By default, integrity hashes are not output when `DEBUG` is `True`, as static files change a lot during local development. To override this, set `USE_SRI` to `True`.\n\n`django-sri` is designed to primarily be used through template tags:\n\n```html\n{% load sri %}\n\n{% sri_static \"index.js\" %} \u003c!-- Will output \"\u003cscript src='/static/index.js' integrity='sha256-...'\u003e\u003c/script\u003e\" --\u003e\n{% sri_static \"index.css\" %} \u003c!-- Will output \"\u003clink rel='stylesheet' href='/static/index.css' integrity='sha256-...'/\u003e\" --\u003e\n```\n\nFor performance, the hashes of files are caches in Django's [caching framework](https://docs.djangoproject.com/en/dev/topics/cache/). It will attempt to use the \"sri\" cache, but fall back to \"default\" if it doesn't exist. The cache keys are the hash of the file path in the specified algorithm in hex. Caches are stored for as long as `DEFAULT_TIMEOUT` is set to.\n\n#### Algorithms\n\nThe SRI standard supports 3 algorithms: sha256, sha384 and sha512. By default, SHA256 is used. To override this, supply an additional `algorithm` argument to the `sri` template tag (or the specific ones):\n\n```html\n{% load sri %}\n\n{% sri_static \"index.js\" algorithm=\"sha512\" %} \u003c!-- Will output \"\u003cscript src='/static/index.js' integrity='sha512-...'\u003e\u003c/script\u003e\" --\u003e\n```\n\nThe default algorithm can be changed by setting `SRI_ALGORITHM` to the required algorithm.\n\n#### Additional attributes\n\nTo add additional attributes to the output tag (such as `async` / `defer`), specify them as additional arguments to the template tag:\n\n```html\n{% load sri %}\n\n{% sri_static \"index.js\" 'defer' 'async'%}\n{% sri_static \"index.woff2\" preload as=\"font\" %}\n```\n\n#### Just the integrity value\n\nTo retrieve just the integrity hash (the contents of the `integrity` attribute), you can use the `{% sri_integrity_static %}` tag, which supports the same arguments as the other tags.\n\n```html\n{% load sri %}\n\n{% sri_integrity_static \"index.js\" \"sha512\" %} \u003c!-- Will output \"sha512-...\" --\u003e\n```\n\n#### Supported Files\n\nFor automatic tag output, the following files are supported:\n\n- `.js`\n- `.css`\n\nUnknown extensions will emit a `link` tag with the URL as the `href` attribute.\n\n`sri_integrity_static` is unaffected by this limitation.\n\n### API\n\n```python\nfrom pathlib import Path\nfrom sri import calculate_integrity, calculate_integrity_of_static, Algorithm\n\ncalculate_integrity(Path(\"/path/to/myfile.txt\"))  # \"sha256-...\"\ncalculate_integrity_of_static(\"index.js\")  # \"sha256-...\"\n\ncalculate_integrity_of_static(\"index.js\", Algorithm.SHA512)  # \"sha512-...\"\n```\n\n### _\"Does this work with [whitenoise](https://whitenoise.evans.io/en/stable/) or alike?\"_\n\nYes. `django-sri` outputs the static file URL in the same way the builtin `static` template tag does. This means the correct cachebusted URLs are output.\n\nWhen using a manifest `STATICFILES_STORAGE`, `django-sri` will automatically retrieve the hashed and post-processed file as opposed to the original.\n\n### `jinja2`\n\nSupport for `jinja2` templates is provided using the `sri.jinja2.sri` extension, which adds the documented Django template tags as global functions. These functions work identically to the Django template versions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealorangeone%2Fdjango-sri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealorangeone%2Fdjango-sri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealorangeone%2Fdjango-sri/lists"}