Fingerprint Console browser resources by content

This commit is contained in:
Andrei Smaliak 2026-11-02 07:24:29 +01:00
parent cdba25924e
commit a07871f4d7
7 changed files with 61 additions and 7 deletions

View File

@ -0,0 +1,6 @@
# Console 3.1.33 — content-versioned browser resources
- The existing static file response owner fingerprints Console JS, translations and CSS in served HTML. Changing a file changes its URL even if the release label was reused.
- Retain no-store headers and existing asset endpoints. No UI controls or installation logic are duplicated.
- This hardens browser refresh after deployment; it does not prove the cause of the reported missing update button in an existing browser session.
- Tests verify stable URLs for unchanged content and invalidation for a same-version JavaScript change.

View File

@ -14,7 +14,7 @@
"version": "1.0.1" "version": "1.0.1"
}, },
"stage_ui": { "stage_ui": {
"version": "3.1.32" "version": "3.1.33"
}, },
"stage_avahi": { "stage_avahi": {
"version": "1.0.0" "version": "1.0.0"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import glob import glob
import hashlib
import base64 import base64
import importlib.util import importlib.util
import ipaddress import ipaddress
@ -60,7 +61,7 @@ APP_DIR = "/opt/iomatex-console"
PUBLIC_DIR = os.path.join(APP_DIR, "public") PUBLIC_DIR = os.path.join(APP_DIR, "public")
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
CONFIG_PATH = "/etc/iomatex/console.json" CONFIG_PATH = "/etc/iomatex/console.json"
UI_VERSION = "V 3.1.32" UI_VERSION = "V 3.1.33"
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health" STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
ZONEINFO_ROOT = "/usr/share/zoneinfo" ZONEINFO_ROOT = "/usr/share/zoneinfo"
@ -2977,6 +2978,17 @@ def get_itscreen_binary_candidates():
return [path for path in candidates if os.path.exists(path)] return [path for path in candidates if os.path.exists(path)]
def fingerprint_console_assets(html, directory):
"""Invalidate browser assets on content changes, including same-version deploys."""
text = html.decode("utf-8")
for name in ("console.js", "console.i18n.js", "console.css"):
with open(os.path.join(directory, name), "rb") as stream:
fingerprint = hashlib.sha256(stream.read()).hexdigest()[:16]
pattern = r'(["\'])/' + re.escape(name) + r'(?:\?[^"\']*)?(["\'])'
text = re.sub(pattern, lambda match: match[1] + "/" + name + "?sha=" + fingerprint + match[2], text)
return text.encode("utf-8")
def client_update_request(action=None): def client_update_request(action=None):
"""Console adapter only: the privileged updater owns feeds and installation.""" """Console adapter only: the privileged updater owns feeds and installation."""
if action not in (None, "check_only", "update"): if action not in (None, "check_only", "update"):
@ -3474,6 +3486,8 @@ class Handler(BaseHTTPRequestHandler):
except FileNotFoundError: except FileNotFoundError:
self.send_error(404) self.send_error(404)
return return
if os.path.basename(path) == "index.html":
data = fingerprint_console_assets(data, os.path.dirname(path))
self.send_response(200) self.send_response(200)
self.send_header("Content-Type", content_type) self.send_header("Content-Type", content_type)
self.send_header("Content-Length", str(len(data))) self.send_header("Content-Length", str(len(data)))

View File

@ -0,0 +1,34 @@
import ast
import hashlib
import os
from pathlib import Path
import re
import tempfile
import unittest
source = Path(__file__).with_name('app.py').read_text()
node = next(n for n in ast.parse(source).body if isinstance(n, ast.FunctionDef) and n.name == 'fingerprint_console_assets')
namespace = dict(hashlib=hashlib, os=os, re=re)
exec(compile(ast.Module(body=[node], type_ignores=[]), '<asset-owner>', 'exec'), namespace)
class AssetVersionTest(unittest.TestCase):
def test_same_release_changed_content_gets_new_url(self):
with tempfile.TemporaryDirectory() as directory:
for name in ('console.js', 'console.i18n.js', 'console.css'):
Path(directory, name).write_text('original')
html = b'<script src="/console.js?v=3.1.32&amp;rev=old"></script><link href="/console.css?v=3.1.32">'
render = lambda: namespace['fingerprint_console_assets'](html, directory)
first = render()
self.assertIn(b'?sha=', first)
self.assertNotIn(b'rev=old', first)
self.assertEqual(first, render())
Path(directory, 'console.js').write_text('new same-version bundle')
self.assertNotEqual(first, render())
self.assertEqual(first.split(b'<link')[1], render().split(b'<link')[1])
def test_html_response_uses_shared_asset_owner(self):
handler = source.split(' def send_file(', 1)[1].split(' def send_sse_headers', 1)[0]
self.assertIn('fingerprint_console_assets(data, os.path.dirname(path))', handler)
self.assertLess(handler.index('fingerprint_console_assets'), handler.index('Content-Length'))
if __name__ == '__main__': unittest.main()

View File

@ -49,7 +49,7 @@
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" }, { mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
{ mode: "custom", label: "Custom", host: "" } { mode: "custom", label: "Custom", host: "" }
]; ];
const UI_VERSION = "V 3.1.32"; const UI_VERSION = "V 3.1.33";
const ITSCREEN_LOG_INITIAL_LINES = 50; const ITSCREEN_LOG_INITIAL_LINES = 50;
const ITSCREEN_LOG_BUFFER_LIMIT = 300; const ITSCREEN_LOG_BUFFER_LIMIT = 300;
const ITSCREEN_LOG_BATCH_MS = 250; const ITSCREEN_LOG_BATCH_MS = 250;

View File

@ -23,7 +23,7 @@
} catch (error) {} } catch (error) {}
})(); })();
</script> </script>
<link rel="stylesheet" href="/console.css?v=3.1.32&amp;rev=edge-runtime-profile-1"> <link rel="stylesheet" href="/console.css?v=3.1.33&amp;rev=edge-runtime-profile-1">
</head> </head>
<body> <body>
<main class="shell"> <main class="shell">
@ -109,7 +109,7 @@
</main> </main>
<div id="menuBackdrop" class="menuBackdrop" hidden></div> <div id="menuBackdrop" class="menuBackdrop" hidden></div>
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div> <div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
<script src="/console.i18n.js?v=3.1.32&amp;rev=edge-runtime-profile-1"></script> <script src="/console.i18n.js?v=3.1.33&amp;rev=edge-runtime-profile-1"></script>
<script src="/console.js?v=3.1.32&amp;rev=edge-runtime-profile-1"></script> <script src="/console.js?v=3.1.33&amp;rev=edge-runtime-profile-1"></script>
</body> </body>
</html> </html>

View File

@ -1,3 +1,3 @@
{ {
"version": "3.1.32" "version": "3.1.33"
} }