feat: subresource integrity hashes for link and script tags - #339
Draft
troglodyne-bot wants to merge 2 commits into
Draft
feat: subresource integrity hashes for link and script tags#339troglodyne-bot wants to merge 2 commits into
troglodyne-bot wants to merge 2 commits into
Conversation
teodesian
reviewed
Jun 2, 2026
| @@ -46,6 +46,7 @@ sub render (%options) { | |||
| path => $template_dir, | |||
| function => { | |||
| render_it => $options{child_renderer}, | |||
Collaborator
There was a problem hiding this comment.
Would very much prefer we simply add render_it as a key to $options{extra_functions} prior to the XSlate::new call here.
teodesian
reviewed
Jun 2, 2026
| unless ( -f $file ) { | ||
| return $cache{$url_path} = ''; | ||
| } | ||
| open( my $fh, '<:raw', $file ) or return $cache{$url_path} = ''; |
Collaborator
There was a problem hiding this comment.
More concisely stated as
my $digestor = Digest::SHA->new(384);
$digestor->addfile($file);
return $cache{$url_path} = 'sha384-'.encode_base64($digestor->digest);
Collaborator
|
@troglodyne-bot rebase |
Implements subresource integrity (SRI) for all CSS and JS resources served in HTML pages, as requested in issue Troglodyne-Internet-Widgets#301. Trog::Renderer::html::sri_hash($url_path) computes a SHA-384 hash of the file at www/$url_path and returns it as a sri384-<base64> string. Results are memoized via `state %cache` for the process lifetime. Returns '' for missing files so the integrity attribute is omitted. Trog::Renderer::Base::render() accepts an extra_functions hashref to let subclasses inject custom Xslate template functions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
troglodyne-bot
force-pushed
the
koan/sri-integrity-hashes
branch
from
June 5, 2026 20:01
b6d7ea7 to
2d6765c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
integrity="sha384-..."attributes to all<link rel="stylesheet">,<link rel="preload">, and<script>tags inheader.tx.Why
Subresource Integrity (SRI) lets browsers verify that fetched resources haven't been tampered with. Even for same-origin assets, this provides defense-in-depth against injection attacks that might serve a modified JS or CSS file. Closes #301.
How
Trog::Renderer::html::sri_hash($url_path)— readswww/$url_pathfrom disk, returnssha384-<base64>. Caches viastate %cache(process lifetime). Returns''for missing files so theintegrityattribute is omitted rather than emitted empty.Trog::Renderer::Base::render()gains anextra_functionsoption that html.pm uses to injectsri_hashinto the top-level Xslate renderer.header.txcallssri_hash()per resource, conditionally emitting the attribute only when the hash is non-empty (so bundled files likereveal.cssandobsidian.min.css, not checked in, get no attribute).Testing
6 new tests in
t/Trog-Renderer-html.t: correct SHA-384 for an existing file, caching behavior, empty return for missing/non-absolute/undef inputs.The hash value is cross-verified against an independent
Digest::SHA + MIME::Base64computation.