Mots de passe fuités refusés (Have I Been Pwned, k-anonymat) à l'inscription et au changement
deploy / deploy (push) Successful in 35s

Remplace l'option payante « Prevent use of leaked passwords » de Supabase :
seuls 5 caractères de l'empreinte SHA-1 sont envoyés ; en cas de panne réseau
on laisse passer. CSP connect-src, message en 18 langues, politique de
confidentialité mise à jour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
Claude committed 2026-10-10 09:06:39 +00:00
1 parent 8eda394ae3
commit b68ddf895b
22 files changed
+63 -1

No files matched your search

+3
View File
@@ -1,5 +1,6 @@
import { t, type TKey } from '../../i18n'
import { SUPABASE_ANON_KEY, SUPABASE_URL } from './config'
import { isPwnedPassword } from '../pwned'
/**
* Connexion aux comptes (Supabase Auth), sans dépendance.
@@ -163,6 +164,7 @@ export async function signIn(email: string, password: string): Promise<void> {
/** Inscription. Le pseudo choisi est repris par la base à la création du profil (s'il est libre). */
export async function signUp(email: string, password: string, username?: string): Promise<boolean> {
if (password.length < PASSWORD_MIN) throw new AuthError(t('auth.err.weak', { n: PASSWORD_MIN }))
if (await isPwnedPassword(password)) throw new AuthError(t('auth.err.pwned'))
const data = await gotrue(`/signup?redirect_to=${encodeURIComponent(appUrl())}`, {
body: { email: cleanEmail(email), password, ...(username ? { data: { username } } : {}) },
})
@@ -180,6 +182,7 @@ export async function requestPasswordReset(email: string): Promise<void> {
export async function updatePassword(password: string): Promise<void> {
if (password.length < PASSWORD_MIN) throw new AuthError(t('auth.err.weak', { n: PASSWORD_MIN }))
if (await isPwnedPassword(password)) throw new AuthError(t('auth.err.pwned'))
const token = await getAccessToken()
if (!token) throw new AuthError(t('auth.err.session'))
await gotrue('/user', { method: 'PUT', body: { password }, token })
+40
View File
@@ -0,0 +1,40 @@
/**
* Mot de passe déjà apparu dans une fuite de données ? (base publique Have I Been Pwned)
*
* k-anonymat : seuls les 5 premiers caractères de l'empreinte SHA-1 du mot de passe sont envoyés ;
* le service renvoie toutes les empreintes qui commencent pareil (avec du remplissage aléatoire)
* et la comparaison se fait ici. Le mot de passe, et même son empreinte complète, ne quittent jamais l'appareil.
*
* Remplace l'option payante « Prevent use of leaked passwords » de Supabase.
* En cas de panne réseau, on laisse passer (la longueur minimale reste vérifiée).
*/
export async function isPwnedPassword(password: string): Promise<boolean> {
try {
const digest = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(password))
const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('').toUpperCase()
const prefix = hex.slice(0, 5)
const suffix = hex.slice(5)
const ctrl = new AbortController()
const timer = setTimeout(() => ctrl.abort(), 5000)
try {
const res = await fetch(`https://api.pwnedpasswords.com/range/${prefix}`, {
headers: { 'Add-Padding': 'true' },
signal: ctrl.signal,
credentials: 'omit',
referrerPolicy: 'no-referrer',
})
if (!res.ok) return false
const text = await res.text()
for (const line of text.split('\n')) {
const [s, count] = line.trim().split(':')
// Les lignes de remplissage ont un compteur à 0
if (s === suffix && Number(count) > 0) return true
}
return false
} finally {
clearTimeout(timer)
}
} catch {
return false
}
}