fix(aep-15a): ce que le public écrit et relit hors des fiches (checkpoint)
POST /api/organisations et POST /api/avis : limite de débit, seuls les
champs que pages/ajouter.vue envoie, contrôlés en type et longueur (bornes
de /api/submit pour nom), statut imposé pending (moderation_status,
ai_processed false), toute autre clé ignorée, réponse réduite à { Id }.
GET /api/comment/[orgId] et /api/avis/[orgId] : numéro strict, lignes
publiées seulement, champs affichés seulement (jamais auteur_email).
url d'une fiche publique : rendue seulement en http(s).
Test : scripts/test-fiche-publique.mjs, 189 cas (CRLF toléré).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,7 +65,9 @@ for (const c of interdits) verifier(`« ${c} » absent de la liste publique`, !C
|
||||
verifier('la garde CHAMPS_JAMAIS_PUBLICS couvre les huit champs du brief', interdits.every((c) => CHAMPS_JAMAIS_PUBLICS.includes(c)))
|
||||
verifier('aucun champ de la garde dans la liste', CHAMPS_JAMAIS_PUBLICS.every((c) => !CHAMPS_PUBLICS_FICHE.includes(c)))
|
||||
for (const c of ['moderation_status', 'projet_adresse', 'CreatedAt', 'submission_type', 'type_principal', 'projet_lien', 'status', 'categorie', 'type_plateforme']) {
|
||||
verifier(`« ${c} » (lu par aucune page) hors de la liste`, !CHAMPS_PUBLICS_FICHE.includes(c))
|
||||
// Aucun n'est lu par une page depuis ces routes ; CreatedAt seulement en dernier repli du sitemap
|
||||
// (utils/seo.ts, après UpdatedAt, toujours rempli) : non rendu par choix.
|
||||
verifier(`« ${c} » hors de la liste`, !CHAMPS_PUBLICS_FICHE.includes(c))
|
||||
}
|
||||
verifier('pas de doublon dans la liste', new Set(CHAMPS_PUBLICS_FICHE).size === CHAMPS_PUBLICS_FICHE.length)
|
||||
// Ce que FicheDetail et la page de la fiche affichent doit rester dans la liste (rien ne casse à l'écran)
|
||||
@@ -130,6 +132,19 @@ console.log('\n4. Ligne approuvée : champs publics seulement')
|
||||
verifier('colonne inconnue → non rendue (liste fermée par défaut)', !('nouvelle_colonne_privee' in r) && !('telephone' in r))
|
||||
}
|
||||
|
||||
{
|
||||
// url : http(s) seulement (FicheDetail en fait un lien cliquable)
|
||||
const urlDe = async (url) => (await lireFichePublique('7', base(ligne({ url })).charger))
|
||||
for (const u of ['javascript:alert(1)', 'JavaScript:alert(1)', ' javascript:alert(1)', 'mailto:essai@exemple.invalid', 'data:text/html,x', 'ftp://exemple.invalid', 'exemple.invalid', '', 42]) {
|
||||
const r = await urlDe(u)
|
||||
verifier(`url ${JSON.stringify(u)} → champ absent, fiche rendue`, !!r && !('url' in r) && r.nom === 'Atelier d essai')
|
||||
}
|
||||
verifier('url https → rendue', (await urlDe('https://exemple.invalid/a')).url === 'https://exemple.invalid/a')
|
||||
verifier('url http → rendue', (await urlDe('http://exemple.invalid')).url === 'http://exemple.invalid')
|
||||
verifier('url null → null (pas de lien)', (await urlDe(null)).url === null)
|
||||
verifier('liste de la carte : url javascript: absente aussi', !('url' in fichesPubliques([ligne({ url: 'javascript:alert(1)' })])[0]))
|
||||
}
|
||||
|
||||
// ── 5. La liste de la carte (/api/organisations) ───────────────────────────
|
||||
console.log('\n5. Liste de la carte')
|
||||
{
|
||||
@@ -148,7 +163,7 @@ const lire = (p) => readFileSync(join(racine, p), 'utf-8')
|
||||
for (const p of ['server/api/fiche/[id].get.ts', 'server/routes/api/organisations/[id].get.ts']) {
|
||||
const s = lire(p)
|
||||
verifier(`${p} : lit la fiche par lireFichePublique`, /lireFichePublique\(getRouterParam\(event, 'id'\)/.test(s))
|
||||
verifier(`${p} : ne rend jamais la ligne brute`, !/return record/.test(s) && !/return data\s*$/m.test(s) && /return fiche\n\}\)/.test(s))
|
||||
verifier(`${p} : ne rend jamais la ligne brute`, !/return record/.test(s) && !/return data\s*$/m.test(s) && /return fiche\r?\n\}\)/.test(s))
|
||||
verifier(`${p} : le filtre NocoDB ne prend que le numéro validé`, /where=\(Id,eq,\$\{id\}\)/.test(s) && /async \(id\) =>/.test(s))
|
||||
verifier(`${p} : une seule réponse d'erreur, 404`, (s.match(/createError/g) ?? []).length === 1 && /statusCode: 404/.test(s))
|
||||
}
|
||||
@@ -159,5 +174,101 @@ for (const p of ['server/api/fiche/[id].get.ts', 'server/routes/api/organisation
|
||||
verifier('organisations.get.ts : filtre approved conservé côté base', /where=\(moderation_status,eq,approved\)/.test(s))
|
||||
}
|
||||
|
||||
// ── 7. Ce que le public écrit et relit hors des fiches (checkpoint du 21/11) ──
|
||||
console.log('\n7. Proposer une fiche, un avis ; relire commentaires et avis')
|
||||
const {
|
||||
ligneOrganisationProposee, ligneAvisPropose, reponseInsertion, commentairesPublics, avisPublics,
|
||||
CHAMPS_PUBLICS_COMMENTAIRE, CHAMPS_PUBLICS_AVIS,
|
||||
} = await jiti.import(join(racine, 'utils', 'contributionsPubliques.ts'))
|
||||
|
||||
const corpsPage = { nom: 'Atelier d essai', type_org: 'association', description: 'Une description d essai.', lien: 'https://exemple.invalid', tags: 'formation, essai', status: 'pending' }
|
||||
{
|
||||
const r = ligneOrganisationProposee(corpsPage)
|
||||
verifier('corps de pages/ajouter.vue accepté', r.ok === true)
|
||||
verifier('… ligne pending, ai_processed false', r.ok && r.ligne.moderation_status === 'pending' && r.ligne.ai_processed === false && r.ligne.status === 'pending')
|
||||
verifier('… exactement les champs de la page + statuts serveur', r.ok && Object.keys(r.ligne).sort().join(',') === 'ai_processed,description,lien,moderation_status,nom,status,tags,type_org')
|
||||
}
|
||||
{
|
||||
const r = ligneOrganisationProposee({
|
||||
...corpsPage, moderation_status: 'approved', ai_processed: true, status: 'approved', Id: 1, moderator_note: 'x',
|
||||
submitted_at: '2020-01-01', submitted_by_email: COURRIEL, colonne_inconnue: 'x', latitude: 1, prioritaire: true,
|
||||
})
|
||||
verifier('moderation_status « approved » du client → ligne pending', r.ok && r.ligne.moderation_status === 'pending' && r.ligne.status === 'pending' && r.ligne.ai_processed === false)
|
||||
for (const k of ['Id', 'moderator_note', 'submitted_at', 'submitted_by_email', 'colonne_inconnue', 'latitude', 'prioritaire']) {
|
||||
verifier(`clé « ${k} » du client ignorée`, r.ok && !(k in r.ligne))
|
||||
}
|
||||
}
|
||||
{
|
||||
const lien = (v) => ligneOrganisationProposee({ ...corpsPage, lien: v })
|
||||
verifier('lien vide → null', lien('').ok && lien('').ligne.lien === null)
|
||||
verifier('lien null → null', lien(null).ok && lien(null).ligne.lien === null)
|
||||
verifier('sans lien ni tags → null', (() => { const r = ligneOrganisationProposee({ nom: 'Atelier', type_org: 'media', description: 'x' }); return r.ok && r.ligne.lien === null && r.ligne.tags === null })())
|
||||
const refus = [
|
||||
['nom de 151 caractères', { nom: 'a'.repeat(151) }],
|
||||
['nom de 2 caractères', { nom: 'ab' }],
|
||||
['nom de 3 espaces + 2 lettres', { nom: ' ab ' }],
|
||||
['nom nombre', { nom: 12345 }],
|
||||
['nom tableau', { nom: ['Atelier'] }],
|
||||
['type_org hors du <select>', { type_org: 'entreprise' }],
|
||||
['type_org vide', { type_org: '' }],
|
||||
['description vide', { description: ' ' }],
|
||||
['description de 2001 caractères', { description: 'a'.repeat(2001) }],
|
||||
['description objet', { description: { texte: 'x' } }],
|
||||
['lien javascript:', { lien: 'javascript:alert(1)' }],
|
||||
['lien sans protocole', { lien: 'exemple.invalid' }],
|
||||
['lien de 501 caractères', { lien: 'https://exemple.invalid/' + 'a'.repeat(477) }],
|
||||
['tags de 201 caractères', { tags: 'a'.repeat(201) }],
|
||||
['tags nombre', { tags: 3 }],
|
||||
]
|
||||
for (const [nom, sur] of refus) verifier(`${nom} → refusé`, ligneOrganisationProposee({ ...corpsPage, ...sur }).ok === false)
|
||||
verifier('nom de 150 caractères → accepté (borne)', ligneOrganisationProposee({ ...corpsPage, nom: 'a'.repeat(150) }).ok === true)
|
||||
verifier('description de 2000 caractères → acceptée (borne)', ligneOrganisationProposee({ ...corpsPage, description: 'a'.repeat(2000) }).ok === true)
|
||||
for (const c of [null, undefined, 'texte', 42, []]) verifier(`corps ${JSON.stringify(c) ?? 'undefined'} → refusé`, ligneOrganisationProposee(c).ok === false)
|
||||
}
|
||||
{
|
||||
const corpsAvis = { organisation_id: 12, auteur: 'Prénom', texte: 'Un avis d essai.', status: 'approved', published: true, Id: 3 }
|
||||
const r = ligneAvisPropose(corpsAvis)
|
||||
verifier('avis avec status « approved » du client → pending', r.ok && r.ligne.status === 'pending')
|
||||
verifier('… clés inconnues ignorées', r.ok && Object.keys(r.ligne).sort().join(',') === 'auteur,organisation_id,status,texte')
|
||||
for (const [nom, sur] of [['organisation_id chaîne', { organisation_id: '12' }], ['organisation_id négatif', { organisation_id: -1 }],
|
||||
['organisation_id flottant', { organisation_id: 1.5 }], ['auteur de 101 caractères', { auteur: 'a'.repeat(101) }],
|
||||
['texte vide', { texte: ' ' }], ['texte de 2001 caractères', { texte: 'a'.repeat(2001) }]]) {
|
||||
verifier(`avis : ${nom} → refusé`, ligneAvisPropose({ ...corpsAvis, ...sur }).ok === false)
|
||||
}
|
||||
}
|
||||
verifier('réponse d’insertion réduite au numéro', JSON.stringify(reponseInsertion({ Id: 5, nom: 'x', moderation_status: 'pending' })) === '{"Id":5}')
|
||||
verifier('réponse d’insertion sans numéro entier → {}', JSON.stringify(reponseInsertion({ Id: '5' })) === '{}' && JSON.stringify(reponseInsertion(null)) === '{}')
|
||||
{
|
||||
const lignes = [
|
||||
{ Id: 1, orga_id: 7, contenu: 'Publié.', auteur_pseudo: 'Pseudo', auteur_email: COURRIEL, published: true, safe_check: 'safe', safe_reason: null, submitted_at: '2026-11-01T10:00:00.000Z' },
|
||||
{ Id: 2, orga_id: 7, contenu: 'En attente.', auteur_email: COURRIEL, published: false, safe_check: 'flagged', safe_reason: 'raison d essai' },
|
||||
{ Id: 3, orga_id: 8, contenu: 'Autre fiche.', published: true },
|
||||
null,
|
||||
]
|
||||
const l = commentairesPublics(lignes, 7)
|
||||
verifier('commentaire avec courriel → courriel non rendu', l.length === 1 && !JSON.stringify(l).includes(COURRIEL))
|
||||
verifier('commentaire : ni safe_check ni safe_reason ni published', l.every((c) => !('safe_check' in c) && !('safe_reason' in c) && !('published' in c)))
|
||||
verifier('commentaire non publié ou d’une autre fiche → absent', l[0].Id === 1)
|
||||
verifier('commentaire : champs lus par CommentSection seulement', l.every((c) => Object.keys(c).every((k) => CHAMPS_PUBLICS_COMMENTAIRE.includes(k))))
|
||||
verifier('auteur_email jamais dans les champs publics d’un commentaire', !CHAMPS_PUBLICS_COMMENTAIRE.includes('auteur_email'))
|
||||
}
|
||||
{
|
||||
const l = avisPublics([
|
||||
{ Id: 1, organisation_id: 7, auteur: 'Prénom d essai', texte: 'Avis approuvé.', status: 'approved' },
|
||||
{ Id: 2, organisation_id: 7, auteur: 'Prénom d essai', texte: 'Avis en attente.', status: 'pending' },
|
||||
], 7)
|
||||
verifier('avis : approuvés seulement, sans prénom ni statut', l.length === 1 && !('auteur' in l[0]) && !('status' in l[0]) && Object.keys(l[0]).every((k) => CHAMPS_PUBLICS_AVIS.includes(k)))
|
||||
}
|
||||
{
|
||||
const post = lire('server/routes/api/organisations.post.ts')
|
||||
verifier('organisations.post.ts : limite de débit de /api/submit', /checkRateLimit\(ip, 'submit', 3\)/.test(post))
|
||||
verifier('organisations.post.ts : n’envoie que r.ligne, ne rend que reponseInsertion', /body: JSON\.stringify\(r\.ligne\)/.test(post) && /return reponseInsertion\(data\)/.test(post) && !/JSON\.stringify\(body\)/.test(post))
|
||||
const avis = lire('server/routes/api/avis.post.ts')
|
||||
verifier('avis.post.ts : limite de débit, r.ligne, reponseInsertion', /checkRateLimit\(ip, 'avis', 5\)/.test(avis) && /JSON\.stringify\(r\.ligne\)/.test(avis) && /return reponseInsertion\(data\)/.test(avis))
|
||||
verifier('comment/[orgId].get.ts : passe par commentairesPublics et idFicheValide', /commentairesPublics\(data\?\.list, orgId\)/.test(lire('server/api/comment/[orgId].get.ts')) && /idFicheValide\(getRouterParam/.test(lire('server/api/comment/[orgId].get.ts')))
|
||||
verifier('avis/[orgId].get.ts : passe par avisPublics et idFicheValide', /avisPublics\(data\?\.list, orgId\)/.test(lire('server/routes/api/avis/[orgId].get.ts')) && /idFicheValide\(getRouterParam/.test(lire('server/routes/api/avis/[orgId].get.ts')))
|
||||
verifier('comment/index.post.ts : le statut publié vient du filtre, pas du client', /published,\r?\n/.test(lire('server/api/comment/index.post.ts')) && !/body\.published|body\.safe_check|body\.status/.test(lire('server/api/comment/index.post.ts')))
|
||||
}
|
||||
|
||||
console.log(`\n${ok} sur ${ok + ko}`)
|
||||
if (ko) process.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user