feat(supabase): V1-2.1 M4/M5 secure sheet access and review workflow
M4 20261028100000_sheet_access_hardening + M5 20261028110000_sheet_review_workflow (applied together; no unprotected window). Implements contract §5-§14. - Catalogue rights table + owner RPCs; has_mfa / has_aal2_session (live auth.sessions check); grant_active vs caller_has split; catalogue reader predicate; can_edit_sheet on the sheet_editor capability (F14). - AR-1 B: aal2 required on every platform role change, target verified factor, race-free last-owner guard (F18/F19); service_role loses table privileges on the catalogue + profiles/profile_roles and EXECUTE on the role RPCs (F12/F17). - Reviewed lifecycle: version provenance + review columns, content/freeze/ author triggers, rounds/comments/acknowledgments, save/submit/withdraw/ comment/acknowledge/decide, atomic publish_sheet_version(review_id) on the stored verdict, deprecate/archive/restore, species RPCs, equine working copy, uploads with the storage check (F7) + editor INSERT policy + 2 MiB bucket. F1-F3,F5,F6,F8,F9,F13,F15,F16 closed. Verdict is a fixture until M6 (V1-2.3). - O22: SQL business mirror removed, declared status check kept; pgTAP 011 and the Rust generator's SQL parts deleted, ledger retargeted. - Access layer sheets.ts (closed SheetFailure kinds); old client publish gate deleted; types regenerated; upload tool reads via get_sheet_asset_state. Tested on the throwaway sandbox only; DEV untouched. pgTAP 850 (real stack) / 122 (PGlite) green; real-GoTrue AR-1 B + F18 race green; fresh install and M3->M5 upgrade green; V1-1 regression green; rust:check, typecheck, lint, build, types drift clean. BDR-084, LRN-095.
This commit is contained in:
1 parent
9c13bae4bc
commit
77e5fa4cf5
33 files changed
+4613
-1617
No files matched your search
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* RFC 6238 TOTP codes for the sandbox MFA tests (contract
|
||||
* docs/development/V1-2_ANATOMICAL_SHEETS.md §15): HMAC-SHA1, 30 s steps,
|
||||
* 6 digits, the parameters GoTrue v2.197.0 uses. Node `crypto` only, no
|
||||
* dependency. The secret stays in the test's memory: never printed, logged or
|
||||
* written anywhere.
|
||||
*/
|
||||
import { createHmac } from 'node:crypto'
|
||||
|
||||
const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
|
||||
export const TOTP_STEP_SECONDS = 30
|
||||
|
||||
function base32Decode(text: string): Buffer {
|
||||
const clean = text.replace(/=+$/, '').toUpperCase()
|
||||
const bytes: number[] = []
|
||||
let buffer = 0
|
||||
let bits = 0
|
||||
for (const char of clean) {
|
||||
const value = BASE32.indexOf(char)
|
||||
if (value < 0) throw new Error('totp: secret is not base32')
|
||||
buffer = (buffer << 5) | value
|
||||
bits += 5
|
||||
if (bits >= 8) {
|
||||
bits -= 8
|
||||
bytes.push((buffer >> bits) & 0xff)
|
||||
}
|
||||
}
|
||||
return Buffer.from(bytes)
|
||||
}
|
||||
|
||||
/** The 6-digit code of `secret` for the step holding `at` (ms since epoch). */
|
||||
export function totpCode(secret: string, at = Date.now()): string {
|
||||
const counter = Buffer.alloc(8)
|
||||
counter.writeBigUInt64BE(BigInt(Math.floor(at / 1000 / TOTP_STEP_SECONDS)))
|
||||
const mac = createHmac('sha1', base32Decode(secret)).update(counter).digest()
|
||||
const offset = mac[mac.length - 1] & 0x0f
|
||||
const value = (mac.readUInt32BE(offset) & 0x7fffffff) % 1_000_000
|
||||
return value.toString().padStart(6, '0')
|
||||
}
|
||||
|
||||
/** Milliseconds until the next step starts (a fresh code). */
|
||||
export function msToNextStep(at = Date.now()): number {
|
||||
const step = TOTP_STEP_SECONDS * 1000
|
||||
return step - (at % step)
|
||||
}
|
||||
Reference in new issue
Block a user