/** * The public security page (migration 040) and the due-care checklist for * importers and distributors. Shared by the API (validation) and the web app * (the editor and the product page), so both apply the same rules. */ /** Lower-case letters, digits and single hyphens; 3 to 60 characters; no hyphen at either end. */ export const DISCLOSURE_SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){1,58}[a-z0-9]$/; /** * Names a security page cannot have: words that read as ResilienceWP itself, * as a page of the site, or as a generic authority. */ export const DISCLOSURE_RESERVED_SLUGS: ReadonlySet = new Set([ 'admin', 'administrator', 'api', 'app', 'auth', 'billing', 'blog', 'cert', 'contact', 'csirt', 'dashboard', 'docs', 'enisa', 'eu', 'europa', 'example', 'help', 'login', 'logout', 'new', 'official', 'policy', 'pricing', 'privacy', 'report', 'reports', 'resiliencewp', 'resilience-wp', 'root', 'security', 'settings', 'signup', 'status', 'support', 'system', 'team', 'terms', 'test', 'www', ]); export const DISCLOSURE_SLUG_MIN = 3; export const DISCLOSURE_SLUG_MAX = 60; /** Why a slug cannot be used, or null when it can (whether it is taken is the API's to say). */ export function disclosureSlugProblem(slug: string): string | null { if (slug.length < DISCLOSURE_SLUG_MIN) return `Use at least ${DISCLOSURE_SLUG_MIN} characters.`; if (slug.length > DISCLOSURE_SLUG_MAX) return `Use at most ${DISCLOSURE_SLUG_MAX} characters.`; if (!DISCLOSURE_SLUG_PATTERN.test(slug)) return 'Use lower-case letters, digits and single hyphens, starting and ending with a letter or digit.'; if (DISCLOSURE_RESERVED_SLUGS.has(slug)) return 'This address is reserved. Pick another.'; return null; } /** A starting slug from a name: "Acme Security Ltd." -> "acme-security-ltd". */ export function suggestDisclosureSlug(name: string): string { const base = name .normalize('NFKD') .replace(/[̀-ͯ]/g, '') .toLowerCase() .replace(/[^a-z0-9]+/g, '-') .replace(/^-+|-+$/g, '') .slice(0, DISCLOSURE_SLUG_MAX) .replace(/-+$/g, ''); return base.length >= DISCLOSURE_SLUG_MIN ? base : ''; } /** The promised acknowledgement time, in days. */ export const DISCLOSURE_RESPONSE_DAYS = { min: 1, max: 90, default: 5 } as const; /** Limits on what a reporter can send through the public form. */ export const PUBLIC_REPORT_LIMITS = { name: 200, email: 320, version: 200, title: 200, description: 10_000, steps: 10_000, } as const; /** A public report's reference, as the reporter's receipt and the workspace show it. */ export function publicReportReference(id: string): string { return `VR-${id.replace(/-/g, '').slice(0, 8).toUpperCase()}`; } // ------------------------------------------------------------------ // Due care for importers and distributors (Art. 19, Art. 20) // ------------------------------------------------------------------ export type DueCareRole = 'importer' | 'distributor'; export interface DueCareItem { id: string; label: string; /** What it means in practice, in one sentence. */ help: string; cite: string; roles: readonly DueCareRole[]; } /** * The checks an importer (Art. 19) or distributor (Art. 20) makes on a * manufacturer's product before making it available. Wording agrees with * docs/cra-facts.md (Roles). */ export const DUE_CARE_ITEMS: readonly DueCareItem[] = [ { id: 'manufacturer_identified', label: 'Manufacturer name and contact details known', help: 'The manufacturer’s identity and contact address, as the user information must give them.', cite: 'Annex II', roles: ['importer', 'distributor'], }, { id: 'conformity_assessment', label: 'The manufacturer carried out the conformity assessment', help: 'Ask which route was used (internal control, or a notified body) and when.', cite: 'Art. 19', roles: ['importer'], }, { id: 'technical_documentation', label: 'Technical documentation drawn up, available on request', help: 'The manufacturer has it and will make it available to market surveillance authorities.', cite: 'Art. 19', roles: ['importer'], }, { id: 'ce_marking', label: 'CE marking checked', help: 'On the product, or for software on the declaration of conformity or the accompanying website.', cite: 'Art. 19, Art. 20', roles: ['importer', 'distributor'], }, { id: 'declaration_of_conformity', label: 'EU declaration of conformity received and kept for 10 years', help: 'Keep a copy for 10 years after the product is placed on the market.', cite: 'Art. 19', roles: ['importer'], }, { id: 'declaration_available', label: 'EU declaration of conformity available', help: 'You know where the declaration can be accessed.', cite: 'Art. 20', roles: ['distributor'], }, { id: 'user_information', label: 'Annex II user information and instructions present', help: 'Including the single point of contact for vulnerabilities and the end date of the support period.', cite: 'Art. 19, Art. 20, Annex II', roles: ['importer', 'distributor'], }, { id: 'vulnerabilities_reported', label: 'Vulnerabilities you find are reported to the manufacturer', help: 'You have a way to tell the manufacturer, and you use it.', cite: 'Art. 19', roles: ['importer'], }, ]; export const DUE_CARE_ITEM_IDS: ReadonlySet = new Set(DUE_CARE_ITEMS.map((i) => i.id)); /** The checks that apply to a role, in order. */ export function dueCareItemsFor(role: string): DueCareItem[] { return role === 'importer' || role === 'distributor' ? DUE_CARE_ITEMS.filter((i) => i.roles.includes(role)) : []; }