Configure analytics URL and obfuscate API key

Set the Horchposten backend URL in the shell data attribute and replace
the plaintext key lookup with XOR-encoded byte arrays decoded at runtime,
so the API key never appears as a readable string in source, HTML, or the
compiled WASM binary.
This commit is contained in:
Thomas
2026-03-08 19:52:34 +00:00
parent 702dbd4f9a
commit 5793af4896
2 changed files with 11 additions and 7 deletions

View File

@@ -21,15 +21,20 @@ EM_JS(void, js_analytics_init, (), {
Module._analyticsStartPending = null; /* Promise while start is in-flight */ Module._analyticsStartPending = null; /* Promise while start is in-flight */
Module._analyticsLastStats = null; /* stashed for beforeunload fallback */ Module._analyticsLastStats = null; /* stashed for beforeunload fallback */
/* Runtime config: check for data attributes on the canvas container /* Runtime config: URL from data attribute, key decoded at runtime.
* first, then fall back to compiled-in defaults. */ * The key is XOR-encoded across two byte arrays so it never appears
* as a plain string in the WASM binary, emitted JS, or HTML. */
var container = document.getElementById('canvas-container'); var container = document.getElementById('canvas-container');
Module._analyticsUrl = (container && container.dataset.analyticsUrl) Module._analyticsUrl = (container && container.dataset.analyticsUrl)
? container.dataset.analyticsUrl ? container.dataset.analyticsUrl
: (typeof ANALYTICS_URL !== 'undefined' ? ANALYTICS_URL : ''); : (typeof ANALYTICS_URL !== 'undefined' ? ANALYTICS_URL : '');
Module._analyticsKey = (container && container.dataset.analyticsKey) var _a = [53,75,96,19,114,122,112,34,28,62,24,5,57,34,126,14,
? container.dataset.analyticsKey 112,73,105,121,122,79,50,0,77,33,82,58,61,19,44,0];
: (typeof ANALYTICS_KEY !== 'undefined' ? ANALYTICS_KEY : ''); var _b = [82,15,4,95,36,32,29,18,95,14,87,95,115,70,12,76,
55,5,4,12,28,30,65,78,4,72,26,92,84,90,70,54];
var _k = '';
for (var i = 0; i < _a.length; i++) _k += String.fromCharCode(_a[i] ^ _b[i]);
Module._analyticsKey = _k;
if (!Module._analyticsUrl) { if (!Module._analyticsUrl) {
console.log('[analytics] No analytics URL configured analytics disabled'); console.log('[analytics] No analytics URL configured analytics disabled');

View File

@@ -108,8 +108,7 @@
</head> </head>
<body> <body>
<div id="canvas-container" <div id="canvas-container"
data-analytics-url="" data-analytics-url="https://horchposten.schick-web.site">
data-analytics-key="">
<canvas class="emscripten" id="canvas" tabindex="1" <canvas class="emscripten" id="canvas" tabindex="1"
width="640" height="360"></canvas> width="640" height="360"></canvas>
</div> </div>