security: fix SAS verification bypass and unauthenticated frame injection; release v5.5.2
CodeQL Analysis / Analyze CodeQL (push) Canceled after 0s
Deploy Application / deploy (push) Canceled after 0s
Mirror to Codeberg / mirror (push) Canceled after 0s
Mirror to PrivacyGuides / mirror (push) Canceled after 0s

A security review of the transport and verification layers. Every item is a fix
to how untrusted peer input is handled; no features changed.

- SAS verification could be bypassed. `verification_both_confirmed` is an
  unauthenticated frame on a channel that is not yet trusted, but it was taken as
  proof that both sides had compared their codes — so a peer who completed the
  signalling exchange could send it right after the data channel opened and drive
  the other side to a "verified" session while the user never looked at the code.
  It is now only an acknowledgement: refused unless this side already confirmed
  locally, and _setVerifiedStatus() independently rejects any SAS-based
  transition without a local confirmation. Holding ECDH-derived keys was never
  proof of identity — a MITM has those too.

- Unauthenticated frames could be injected into the chat. A bare
  {type:"message"} frame, a raw non-JSON frame and a binary frame were each
  decoded and rendered, bypassing decryption, the HMAC check and the verification
  gate; the injected text was indistinguishable from a genuine message. Chat
  content now reaches the UI only through the authenticated enhanced_message
  path.

- A peer could supply the verification code. `sas_code` announcements were
  adopted verbatim when no local SAS had been derived yet. They may now only
  corroborate the locally derived code.

- Anti-replay never ran. The sequence-number and AAD validators were defined on
  SecureKeyStorage instead of the connection manager, so every call site failed
  with a TypeError and the sliding replay window was dead code. Moved onto the
  manager, wired into the live chat path, and a missing or non-numeric sequence
  number now fails closed instead of sailing through the range checks.

- File transfers are gated on verification in both directions. Control frames are
  written straight to the data channel by the transfer system; sending was
  already gated, receiving now is too.

- Tighter CSP: connect-src and img-src no longer allow arbitrary https: hosts
  (nothing in the app talks to a third party), plus base-uri 'none'.

- The SAS is no longer written to logs, and is compared in constant time on every
  path. Fixed SecureMasterKeyManager.isUnlocked() testing a field renamed long
  ago, so it never actually gated anything.

- Fixed the header showing "Secure undefined%": getRealSecurityLevel() became
  reachable for the first time by the move above and returned only per-feature
  booleans, while the header renders `level` and `score` directly. It now runs
  the same verified scoring as every other consumer.

Adds regression tests for the verification gate, inbound frame authentication and
the security-level shape.
This commit is contained in:
lockbitchat
2026-07-27 00:10:29 -04:00
parent b3fcf54670
commit 6152a77b51
18 changed files with 1184 additions and 521 deletions
+25 -24
View File
@@ -8,14 +8,15 @@
script-src 'self';
style-src 'self' 'unsafe-inline';
font-src 'self' data:;
connect-src 'self' https: wss: ws: stun: stuns: turn: turns:;
img-src 'self' data: https:;
connect-src 'self' stun: stuns: turn: turns:;
img-src 'self' data:;
media-src 'self' blob:;
object-src 'none';
frame-src 'none';
worker-src 'self';
manifest-src 'self';
form-action 'self';
base-uri 'none';
upgrade-insecure-requests;">
<meta http-equiv="X-Content-Type-Options" content="nosniff">
<meta http-equiv="X-XSS-Protection" content="1; mode=block">
@@ -23,7 +24,7 @@
<!-- PWA Manifest -->
<link rel="manifest" href="./manifest.json">
<link rel="icon" type="image/x-icon" href="./logo/favicon.ico?v=1784825757783">
<link rel="icon" type="image/x-icon" href="./logo/favicon.ico?v=1785125039593">
<!-- PWA Meta Tags -->
<meta name="mobile-web-app-capable" content="yes">
@@ -89,7 +90,7 @@
<link rel="apple-touch-startup-image" media="screen and (device-width: 744px) and (device-height: 1133px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="./logo/splash/splash_screens/8.3__iPad_Mini_portrait.png">
<!-- Apple Touch Icons -->
<link rel="apple-touch-icon" href="./logo/icon-180x180.png?v=1784825757783">
<link rel="apple-touch-icon" href="./logo/icon-180x180.png?v=1785125039593">
<link rel="apple-touch-icon" sizes="57x57" href="./logo/icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="./logo/icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="./logo/icon-72x72.png">
@@ -98,7 +99,7 @@
<link rel="apple-touch-icon" sizes="120x120" href="./logo/icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="./logo/icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="./logo/icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./logo/icon-180x180.png?v=1784825757783">
<link rel="apple-touch-icon" sizes="180x180" href="./logo/icon-180x180.png?v=1785125039593">
<!-- Microsoft Tiles -->
<meta name="msapplication-TileColor" content="#ff6b35">
@@ -182,7 +183,7 @@
<!-- Render-blocking JS is deferred: classic deferred scripts and module scripts
both execute in document order after parsing, so React still runs before the
app modules below, but the parser / first paint is no longer blocked. -->
<script defer src="config/ice-servers.js?v=1784825757783"></script>
<script defer src="config/ice-servers.js?v=1785125039593"></script>
<script defer src="libs/react/react.production.min.js"></script>
<script defer src="libs/react-dom/react-dom.production.min.js"></script>
<!-- Prism syntax highlighting (vendored, offline). Tokenizes code as TEXT only —
@@ -190,8 +191,8 @@
Its CSS is loaded async via load-async-css.js (not paint-critical). -->
<script defer src="libs/prism/prism.js"></script>
<!-- Critical, paint-defining CSS stays render-blocking (avoids FOUC / layout shift). -->
<link rel="stylesheet" href="assets/tailwind.css?v=1784825757783">
<link rel="icon" type="image/x-icon" href="/logo/favicon.ico?v=1784825757783">
<link rel="stylesheet" href="assets/tailwind.css?v=1785125039593">
<link rel="icon" type="image/x-icon" href="/logo/favicon.ico?v=1785125039593">
<!-- Preload only the fonts needed for first paint. fa-solid covers the bulk of UI
icons; fa-regular/fa-brands are loaded on demand by their CSS (rarely on the
first screen). Inter latin 400/700 cover body text and headings/buttons. -->
@@ -199,31 +200,31 @@
<link rel="preload" href="/assets/fonts/inter/files/inter-latin-400.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/assets/fonts/inter/files/inter-latin-700.woff2" as="font" type="font/woff2" crossorigin>
<link rel="stylesheet" href="/assets/fonts/inter/inter.css">
<link rel="stylesheet" href="src/styles/main.css?v=1784825757783">
<link rel="stylesheet" href="src/styles/animations.css?v=1784825757783">
<link rel="stylesheet" href="src/styles/components.css?v=1784825757783">
<link rel="stylesheet" href="src/styles/main.css?v=1785125039593">
<link rel="stylesheet" href="src/styles/animations.css?v=1785125039593">
<link rel="stylesheet" href="src/styles/components.css?v=1785125039593">
<!-- Non-critical CSS (FontAwesome ~102KB, Prism) loaded async — no longer blocks paint. -->
<script defer src="src/scripts/load-async-css.js?v=1784825757783"></script>
<script defer src="src/scripts/load-async-css.js?v=1785125039593"></script>
<noscript>
<link rel="stylesheet" href="/assets/fontawesome/css/all.min.css">
<link rel="stylesheet" href="libs/prism/prism.css">
</noscript>
<script defer src="src/scripts/fa-check.js?v=1784825757783"></script>
<script defer src="src/scripts/fa-check.js?v=1785125039593"></script>
<!-- Update Manager - система принудительного обновления -->
<script defer src="src/utils/updateManager.js?v=1784825757783"></script>
<script type="module" src="src/components/UpdateChecker.jsx?v=1784825757783"></script>
<script type="module" src="dist/qr-local.js?v=1784825757783"></script>
<script type="module" src="src/components/QRScanner.js?v=1784825757783"></script>
<script defer src="src/utils/updateManager.js?v=1785125039593"></script>
<script type="module" src="src/components/UpdateChecker.jsx?v=1785125039593"></script>
<script type="module" src="dist/qr-local.js?v=1785125039593"></script>
<script type="module" src="src/components/QRScanner.js?v=1785125039593"></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="dist/app-boot.js?v=1784825757783"></script>
<script type="module" src="dist/app.js?v=1784825757783"></script>
<script type="module" src="dist/app-boot.js?v=1785125039593"></script>
<script type="module" src="dist/app.js?v=1785125039593"></script>
<script defer src="src/scripts/pwa-register.js?v=1784825757783"></script>
<script src="./src/pwa/install-prompt.js?v=1784825757783" type="module"></script>
<script src="./src/pwa/pwa-manager.js?v=1784825757783" type="module"></script>
<script defer src="./src/scripts/pwa-offline-test.js?v=1784825757783"></script>
<link rel="stylesheet" href="./src/styles/pwa.css?v=1784825757783">
<script defer src="src/scripts/pwa-register.js?v=1785125039593"></script>
<script src="./src/pwa/install-prompt.js?v=1785125039593" type="module"></script>
<script src="./src/pwa/pwa-manager.js?v=1785125039593" type="module"></script>
<script defer src="./src/scripts/pwa-offline-test.js?v=1785125039593"></script>
<link rel="stylesheet" href="./src/styles/pwa.css?v=1785125039593">
</body>
</html>