Drop crypto-browserify polyfills by moving 2FA TOTP to WebCrypto

The frontend build pulled in crypto-browserify, stream-browserify and
vm-browserify (via tsconfig paths) only because otplib's
@otplib/plugin-crypto requires Node's crypto. That chain carried the
last production npm audit findings - the elliptic advisory
(GHSA-848j-6mx2-7j84, no fixed release) plus browserify-sign/create-ecdh
(issue #1634, item 3).

The two-factor-auth settings dialog is the only browser consumer of
otplib. It now uses a small WebCrypto TOTP service
(src/app/shared/services/totp.service.ts, RFC 6238: HMAC-SHA1, 6 digits,
30s step) instead, so otplib is no longer bundled and the three
polyfills plus their tsconfig path mappings are removed.

The backend still verifies login tokens with otplib, so the new service
must match it exactly - verified byte-for-byte against otplib and the
RFC 6238 test vectors (generateSecret/keyuri/generate/check parity).
Existing authenticator enrollments keep working. token check() is now
async (WebCrypto's digest is promise-based); the dialog's verify handler
was updated to match, and the value was never used for control flow.

Production npm audit now reports zero vulnerabilities (from 13, incl. 2
critical, at the start of this cleanup series). Verified on the docker
fixture: enrolled a 2FA secret from the new service, confirmed the
backend otplib accepts a token it produces at login, rejected
wrong/absent tokens. Unit spec covers RFC 6238 vectors, keyuri parity
and base32 round-trip; both API suites and the full frontend suite (204
specs) pass.
This commit is contained in:
saubyk 2026-07-19 18:22:50 -07:00 committed by Suheb
parent 4276a03463
commit c5dc49711c
23 changed files with 202 additions and 2405 deletions

View file

@ -24,13 +24,7 @@
"lib": [
"ES2022",
"dom"
],
"paths": {
"crypto": ["node_modules/crypto-browserify"],
"stream": ["node_modules/stream-browserify"],
"vm": ["node_modules/vm-browserify"],
"process": ["node_modules/process/browser"]
}
]
},
"include": [
"./server/**/*",