bugfix(#24 #25):PBKDF2 600k→100k(CF Workers runtime 上限,真雲 bootstrap 500)+http_request 補 global_fetch_strictly_public(1042) (#56)

This commit was merged in pull request #56.
This commit is contained in:
Leo
2026-07-14 13:23:58 +00:00
parent 52dbd31dea
commit 1e85dfb49b
6 changed files with 70 additions and 11 deletions
+10 -4
View File
@@ -6,8 +6,8 @@
* credential 原語(那些屬 WASM auth primitive,本檔不碰 crypto.subtle.decrypt /
* RSASSA / template 展開)。只用 WebCrypto 原生 PBKDF2crypto.subtle.deriveBits)。
*
* 規格OWASP 現行建議值)
* - PBKDF2-SHA256、600,000 iterations、salt 16 bytes、輸出 256-bit
* 規格:
* - PBKDF2-SHA256、100,000 iterationsCF Workers runtime 上限,見下)、salt 16 bytes、輸出 256-bit
* - 儲存格式 `pbkdf2-sha256$<iterations>$<salt_b64>$<hash_b64>`(自帶演算法前綴,
* 未來換 KDF 可共存漸進遷移——verify 按前綴解析,不寫死參數)
* - 驗證用常數時間比對(同 mcp/src/oauth/crypto.ts PR#15 慣例)
@@ -15,7 +15,13 @@
*/
export const PBKDF2_ALGO_PREFIX = 'pbkdf2-sha256';
export const PBKDF2_ITERATIONS = 600_000;
/**
* CF Workers **正式 runtime** 的 PBKDF2 上限是 100,000 iterations——超過時
* `crypto.subtle.deriveBits` 直接拒絕(2026-07-14 uncle6 真雲實撞:/portal/admin/bootstrap 500
* miniflare 無此限制 → 本機測試全綠的假象)。OWASP 建議 600k 但平台封頂只能 100k。
* 儲存格式自帶迭代數(verify 從儲存值解析)→ 未來平台放寬可無痛升,舊 hash 照驗。
*/
export const PBKDF2_ITERATIONS = 100_000;
function b64encode(bytes: Uint8Array): string {
let bin = '';
@@ -61,7 +67,7 @@ export function constantTimeEqual(a: string, b: string): boolean {
return diff === 0;
}
/** 雜湊一組密碼 → `pbkdf2-sha256$600000$<salt_b64>$<hash_b64>`。 */
/** 雜湊一組密碼 → `pbkdf2-sha256$100000$<salt_b64>$<hash_b64>`。 */
export async function hashPassword(password: string, iterations: number = PBKDF2_ITERATIONS): Promise<string> {
const salt = crypto.getRandomValues(new Uint8Array(16));
const hash = await deriveBits(password, salt, iterations);