Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : agentilab-web8 * File : scripts/audit-content.mjs9 * Module : Scripts10 * Repository : https://git.spboucher.ai/agentilab-web11 * Project Website : Not specified12 * Created : 2026-12-0513 * Last Modified : 2026-12-0514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Audit du contenu public et des verrous de lancement.44// node scripts/audit-content.mjs contrôles permanents (CI)45// node scripts/audit-content.mjs --launch ajoute les verrous d’ouverture publique46// Sort avec le code 1 si un contrôle échoue.47import { readdir, readFile, stat } from 'node:fs/promises';48import path from 'node:path';49import { fileURLToPath } from 'node:url';5051const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');52const launch = process.argv.includes('--launch');53const failures = [];54const fail = (message) => failures.push(message);5556async function walk(dir) {57 const out = [];58 for (const entry of await readdir(dir, { withFileTypes: true }).catch(() => [])) {59 const full = path.join(dir, entry.name);60 if (entry.isDirectory()) out.push(...(await walk(full)));61 else out.push(full);62 }63 return out;64}65const rel = (file) => path.relative(root, file);6667// 1. Texte publié : ni reliquat, ni coordonnée non confirmée, ni renseignement privé.68const FORBIDDEN = [69 [/lorem ipsum|\bTODO\b|\bFIXME\b|\bTBD\b/i, 'reliquat de rédaction'],70 [/[\w.+-]+@agentilab\.ai/i, 'adresse @agentilab.ai (aucune boîte confirmée)'],71 [/\b[ABCEGHJ-NPRSTVXY]\d[A-Z] ?\d[A-Z]\d\b/, 'code postal (adresse privée ?)'],72 [/\(?\b\d{3}\)?[ .-]\d{3}[ .-]\d{4}\b/, 'numéro de téléphone'],73 [/actionnaire|shareholder|droits? de vote|voting right/i, 'renseignement sur l’actionnariat'],74 [/\b\d[\d ]{2,}\s?(utilisateurs|users|clients|customers|employés|employees)\b/i, 'chiffre d’utilisateurs ou d’effectifs'],75];76const textFiles = [77 ...(await walk(path.join(root, 'content', 'public'))),78 ...(await walk(path.join(root, 'components'))),79 ...(await walk(path.join(root, 'app'))),80].filter((f) => /\.(ts|tsx|json)$/.test(f));81for (const file of textFiles) {82 // Les commentaires documentent l’audit (ils citent des adresses essayées) : seul le code compte.83 const source = (await readFile(file, 'utf8')).replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm, '');84 for (const [pattern, label] of FORBIDDEN) {85 const match = pattern.exec(source);86 if (match) fail(`${rel(file)} : ${label} → « ${match[0]} »`);87 }88}8990// 2. Dossier public : seulement des formats attendus, aucun document interne.91const ALLOWED = /\.(svg|png|webp|avif|ico|txt|webmanifest)$/;92for (const file of await walk(path.join(root, 'public'))) {93 if (path.basename(file) === '.DS_Store') continue;94 if (!ALLOWED.test(file)) fail(`${rel(file)} : format inattendu dans public/`);95 if ((await stat(file)).size > 600 * 1024) fail(`${rel(file)} : fichier de plus de 600 Ko`);96}9798// 3. Bundle client (si le build existe) : aucun secret, aucune preuve interne.99const SECRET = [100 [/STAGING_PASSWORD|STAGING_USER/, 'variable du staging'],101 [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, 'clé privée'],102 [/\b(sk|pk|rk)_(live|test)_[A-Za-z0-9]{16,}|\bAKIA[0-9A-Z]{16}\b|\bghp_[A-Za-z0-9]{30,}/, 'clé d’API'],103 [/EV-(KA|ORIX|TECH|REQ)\b/, 'référence de preuve interne'],104 [/10\.67\.\d+\.\d+|192\.168\.\d+\.\d+/, 'adresse de réseau interne'],105];106const bundle = (await walk(path.join(root, '.next', 'static'))).filter((f) => /\.(js|css)$/.test(f));107for (const file of bundle) {108 const source = await readFile(file, 'utf8');109 for (const [pattern, label] of SECRET) if (pattern.test(source)) fail(`${rel(file)} : ${label} dans le bundle client`);110}111112// 4. Verrous de lancement (mandat, section 26).113const { launchGates } = await import(path.join(root, 'content', 'public', 'legal.ts'));114const { contactChannels } = await import(path.join(root, 'content', 'public', 'contact.ts'));115const gates = [116 [contactChannels.some((c) => c.verified && c.verifiedAt), 'Aucun canal de contact confirmé (content/public/contact.ts).'],117 [launchGates.privacyOfficer !== null, 'Personne responsable de la protection des renseignements personnels non confirmée.'],118 [launchGates.legalTextsReviewed, 'Politique de confidentialité et mentions légales non validées par une personne compétente.'],119 [launchGates.tradeNameReviewed, 'Nom d’usage « AgentiLab Technologies » et noms utilisés au Québec non vérifiés.'],120];121const open = gates.filter(([ok]) => !ok).map(([, message]) => message);122123console.log(`Contenu : ${textFiles.length} fichiers source, ${bundle.length} fichiers de bundle${bundle.length ? '' : ' (pas de build : étape ignorée)'}.`);124if (open.length) {125 console.log(`\nVerrous de lancement ouverts (${open.length}) :`);126 for (const message of open) console.log(` ✗ ${message}`);127 if (launch) failures.push(...open.map((m) => `LANCEMENT BLOQUÉ : ${m}`));128} else console.log('Verrous de lancement : tous levés.');129130if (failures.length) {131 console.error(`\n${failures.length} problème(s) :`);132 for (const message of failures) console.error(` ✗ ${message}`);133 process.exit(1);134}135console.log(launch ? '\nAudit de lancement réussi.' : '\nAudit du contenu réussi.');136