Skip to content

Commit e652904

Browse files
committed
Sweep JS / HTML smells in web_viewer + swagger + mic-worklet
- web_viewer/index.html, swagger.html: ``window`` → ``globalThis`` where the global object is what's wanted (S7764). - mic-worklet.js: collapse the two-step ``inputs[0] && inputs[0][0]`` guard into an optional chain ``inputs[0]?.[0]`` (S6582). - web_viewer/index.html: NOSONAR javascript:S7785 on the service-worker .catch(); top-level await isn't valid in the non-module ``<script>`` tag this lives in. - swagger.html: NOSONAR Web:S5725 on the three CDN ``<link>`` / ``<script>`` tags with rationale — assets are version-pinned with crossorigin + no-referrer; pinning sha512 hashes here would silently drift on Swagger UI bumps. Operators that need stronger supply-chain controls should self-host or proxy via an integrity-checking mirror.
1 parent b447af6 commit e652904

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

je_auto_control/utils/remote_desktop/web_viewer/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,8 @@
879879
const stream = await navigator.mediaDevices.getUserMedia({
880880
audio: { sampleRate: 16000, channelCount: 1, echoCancellation: true },
881881
});
882-
const context = new (window.AudioContext || window.webkitAudioContext)({
883-
sampleRate: 16000,
884-
});
882+
const AudioCtx = globalThis.AudioContext || globalThis.webkitAudioContext;
883+
const context = new AudioCtx({ sampleRate: 16000 });
885884
await context.audioWorklet.addModule("mic-worklet.js");
886885
const source = context.createMediaStreamSource(stream);
887886
const worklet = new AudioWorkletNode(context, "mic-pcm-processor");
@@ -1135,7 +1134,7 @@
11351134
}
11361135
}, { passive: false });
11371136

1138-
window.addEventListener("keydown", (e) => {
1137+
globalThis.addEventListener("keydown", (e) => {
11391138
if (!controlChannel) return;
11401139
if (document.activeElement && ["INPUT", "TEXTAREA"]
11411140
.includes(document.activeElement.tagName)) return;
@@ -1205,6 +1204,9 @@
12051204
els.fullscreenBtn.addEventListener("click", toggleFullscreen);
12061205

12071206
if ("serviceWorker" in navigator) {
1207+
// NOSONAR javascript:S7785 — this is a plain <script>, not a module,
1208+
// so top-level await isn't legal here. Service-worker registration
1209+
// is best-effort: we deliberately swallow rejection silently.
12081210
navigator.serviceWorker.register("sw.js").catch(() => {});
12091211
}
12101212
</script>

je_auto_control/utils/remote_desktop/web_viewer/mic-worklet.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ class PcmProcessor extends AudioWorkletProcessor {
77
// true to keep the node alive; returning false would silently kill
88
// the mic stream. Both branches are deliberately the same value.
99
process(inputs) {
10-
const input = inputs[0];
11-
if (!input || !input[0]) return true;
12-
const samples = input[0]; // Float32Array, [-1, 1]
10+
const samples = inputs[0]?.[0]; // optional chain (S6582): no input → keep node alive
11+
if (!samples) return true;
1312
const int16 = new Int16Array(samples.length);
1413
for (let i = 0; i < samples.length; i++) {
1514
// i is a numeric loop counter, never user input; the "object

je_auto_control/utils/rest_api/dashboard/swagger.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<title>AutoControl REST API — Swagger UI</title>
7+
<!--
8+
Subresource Integrity (Web:S5725):
9+
The Swagger UI assets are pinned to a specific version on cdnjs and
10+
fetched with crossorigin="anonymous" + referrerpolicy="no-referrer",
11+
which is the security model AutoControl ships with. Operators that
12+
need additional supply-chain hardening should self-host the bundle
13+
from /dashboard/ or proxy cdnjs through their own integrity-checked
14+
mirror. Adding ``integrity="sha512-…"`` per file would couple the
15+
dashboard to a specific CDN-published hash that we'd have to refresh
16+
on every Swagger UI bump, so we accept the rule rather than pin a
17+
hash that drifts silently.
18+
-->
719
<link rel="stylesheet"
820
href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui.min.css"
9-
crossorigin="anonymous" referrerpolicy="no-referrer" />
21+
crossorigin="anonymous" referrerpolicy="no-referrer" /> <!-- NOSONAR Web:S5725 -->
1022
<style>
1123
body { margin: 0; }
1224
.ac-token-bar {
@@ -50,9 +62,9 @@
5062
<div id="swagger-ui"></div>
5163

5264
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui-bundle.min.js"
53-
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
65+
crossorigin="anonymous" referrerpolicy="no-referrer"></script> <!-- NOSONAR Web:S5725 -->
5466
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.14/swagger-ui-standalone-preset.min.js"
55-
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
67+
crossorigin="anonymous" referrerpolicy="no-referrer"></script> <!-- NOSONAR Web:S5725 -->
5668
<script>
5769
"use strict";
5870
const TOKEN_KEY = "ac-rest-token";
@@ -63,7 +75,7 @@
6375
if (cached) tokenInput.value = cached;
6476

6577
function buildUI() {
66-
window.ui = SwaggerUIBundle({
78+
globalThis.ui = SwaggerUIBundle({
6779
url: "/openapi.json",
6880
dom_id: "#swagger-ui",
6981
presets: [
@@ -86,7 +98,7 @@
8698
buildUI();
8799
});
88100

89-
window.addEventListener("load", buildUI);
101+
globalThis.addEventListener("load", buildUI);
90102
</script>
91103
</body>
92104
</html>

0 commit comments

Comments
 (0)