From 1acce89aad5f30b332243d7fbe98ed736c80e9dd Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Mon, 20 Nov 2017 18:46:52 +0000 Subject: [PATCH] Automatically recompute integrity hashes in templates Uses 'go generate' to invoke sri.py. --- server/bindata.go | 6 +++--- server/http.go | 1 + server/sri.py | 14 ++++++++------ server/templates/page.html | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/server/bindata.go b/server/bindata.go index d383806..ec1216a 100644 --- a/server/bindata.go +++ b/server/bindata.go @@ -1239,7 +1239,7 @@ var _templatesPageHtml = []byte(`{{define "header"}}<!DOCTYPE html> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> {{if .U2FSignRequest}}<meta name="u2f_request" value="{{json .U2FSignRequest}}">{{end}} <link rel="stylesheet" href="/static/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"> - <link rel="stylesheet" href="/static/css/signin.css" integrity="sha384-zxlIX2SfN6SpDKbrkQNcrn07kaD/iSlYdEKRCab8ZAcTEvpWshVV4xqTpoQaeyPq"> + <link rel="stylesheet" href="/static/css/signin.css" integrity="sha384-cd2kbbMX+cYhUlp/Xc7Mu9yBphBGNEvZpeIltWsgUMlkt1kNO3hytQQeTglDcMF/"> <title>Sign In</title> </head> @@ -1255,7 +1255,7 @@ var _templatesPageHtml = []byte(`{{define "header"}}<!DOCTYPE html> <script src="/static/js/bootstrap-4.0.0-beta.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"></script> {{if .U2FSignRequest}} <script type="text/javascript" src="/static/js/u2f-api.js" integrity="sha384-9ChevE6pp8ArGK03HgolnFjZbF3webZQtYkwcabzbcI28Lx1/2x2j2fbaAWD4cgR"></script> - <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-Aw1M0kx84dOGmcbSKwVf6MWXFfyF8YK7LFfpAPqBMG+843kqUeyHNUpEom8kSIiz"></script> + <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-vd6lytRvVm189G5gr34wlOvN672vVBceTZqV+lTSeec0DBLc0GlWLyKDHc6mrIZS"></script> {{end}} </body> </html> @@ -1272,7 +1272,7 @@ func templatesPageHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/page.html", size: 1493, mode: os.FileMode(436), modTime: time.Unix(1510996183, 0)} + info := bindataFileInfo{name: "templates/page.html", size: 1493, mode: os.FileMode(436), modTime: time.Unix(1511203590, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/server/http.go b/server/http.go index 464cda6..1c97ff4 100644 --- a/server/http.go +++ b/server/http.go @@ -1,5 +1,6 @@ package server +//go:generate python sri.py templates/*.html //go:generate go-bindata --nocompress --pkg server static/... templates/... import ( diff --git a/server/sri.py b/server/sri.py index aea5ac2..ba1a60c 100755 --- a/server/sri.py +++ b/server/sri.py @@ -3,9 +3,10 @@ # Automatically fix Subresource Integrity links in the HTML templates. # # Pass templates as command-line arguments. Expects to be run from the -# resources/ directory. +# base resource directory. # +import glob import re import sys from hashlib import sha384 @@ -44,9 +45,10 @@ def fix_sri(path): if __name__ == '__main__': - for path in sys.argv[1:]: - try: - fix_sri(path) - except Exception as e: - print >>sys.stderr, "Error fixing %s: %s" % (path, e) + for arg in sys.argv[1:]: + for path in glob.glob(arg): + try: + fix_sri(path) + except Exception as e: + print >>sys.stderr, "Error fixing %s: %s" % (path, e) diff --git a/server/templates/page.html b/server/templates/page.html index 65ebc46..e16b0f6 100644 --- a/server/templates/page.html +++ b/server/templates/page.html @@ -5,7 +5,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> {{if .U2FSignRequest}}<meta name="u2f_request" value="{{json .U2FSignRequest}}">{{end}} <link rel="stylesheet" href="/static/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"> - <link rel="stylesheet" href="/static/css/signin.css" integrity="sha384-zxlIX2SfN6SpDKbrkQNcrn07kaD/iSlYdEKRCab8ZAcTEvpWshVV4xqTpoQaeyPq"> + <link rel="stylesheet" href="/static/css/signin.css" integrity="sha384-cd2kbbMX+cYhUlp/Xc7Mu9yBphBGNEvZpeIltWsgUMlkt1kNO3hytQQeTglDcMF/"> <title>Sign In</title> </head> @@ -21,7 +21,7 @@ <script src="/static/js/bootstrap-4.0.0-beta.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"></script> {{if .U2FSignRequest}} <script type="text/javascript" src="/static/js/u2f-api.js" integrity="sha384-9ChevE6pp8ArGK03HgolnFjZbF3webZQtYkwcabzbcI28Lx1/2x2j2fbaAWD4cgR"></script> - <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-Aw1M0kx84dOGmcbSKwVf6MWXFfyF8YK7LFfpAPqBMG+843kqUeyHNUpEom8kSIiz"></script> + <script type="text/javascript" src="/static/js/u2f.js" integrity="sha384-vd6lytRvVm189G5gr34wlOvN672vVBceTZqV+lTSeec0DBLc0GlWLyKDHc6mrIZS"></script> {{end}} </body> </html> -- GitLab