Lines 4081-4121javascript
4082function _validateSlugFormat(slug, fieldLabel, allowSlash) {
4083 if (typeof slug !== "string") return null;
4084 // Length cap (full slug). Browsers/CDNs typically cap URLs ~2000 chars;
4085 // most CMSes cap slugs ~200. Hard cap before any other check to avoid
4086 // wasting cycles on a deliberately massive payload.
4087 if (slug.length > SLUG_MAX_LENGTH) {
4088 return `${fieldLabel} is ${slug.length} chars (max ${SLUG_MAX_LENGTH}). BD URL slugs over this length break browsers, CDNs, and email clients.`;
4090 // Reject NFKC-non-canonical slugs. NFKC compatibility-decomposes
4091 // Unicode chars that visually look like other chars (e.g. `ffi`
4092 // U+FB03 → `ffi`, full-width digits → ASCII digits, etc.). Two
4093 // slugs that decompose to the same canonical form should be the
4094 // SAME slug; allowing both creates phishing-equivalent duplicates
4095 // that bypass the duplicate-pair guard. We reject the non-
4096 // canonical form and tell the agent to use the decomposed version.
4097 const normalized = slug.normalize("NFKC");
4098 if (normalized !== slug) {
4099 return `${fieldLabel} '${slug}' contains characters that decompose to a different form under Unicode NFKC normalization (canonical: '${normalized}'). Use the canonical form to avoid creating phishing-equivalent duplicates.`;
4101 if (/[\s--]/.test(slug)) {
CriticalTrojan Source Unicode
Source contains bidi control or invisible Unicode characters associated with Trojan Source attacks.
index.jsView on unpkg · L4101 4102 return `${fieldLabel} '${slug}' contains whitespace or invisible characters, which are not allowed in BD URLs. Use hyphens instead (e.g. 'my-page' not 'my page').`;
4104 // Control + bidi chars (\p{C} = control + format + private-use, covers
4105 // RTL override U+202E + every C0/C1 control + ZWSP-class redundantly).
4106 // Future-proof: new Unicode releases that add bidi-control or format
4107 // chars are auto-rejected without spec maintenance.
4108 if (/\p{C}/u.test(slug)) {
4109 return `${fieldLabel} '${slug}' contains control or bidi-override characters (e.g. RTL override U+202E). These enable phishing-display attacks where a slug visually renders differently than its actual content.`;
4111 // Trailing dot: some routers (IIS, Windows) normalize trailing dots
4112 // away, making `about.` a duplicate-equivalent of `about`. Reject so
4113 // both can't coexist on platforms with that quirk.
4114 if (slug.endsWith(".")) {
4115 return `${fieldLabel} '${slug}' ends with a dot. Some web servers (IIS, Windows) silently strip trailing dots, making the slug a duplicate of the same name without the dot. Remove the trailing dot.`;
4117 // URL-reserved chars + RFC 3986 reserved chars + chars that enable
4118 // phishing-link shapes (`javascript:alert(1)` via `:` + `(` + `)`).
4119 // Asymmetric reject of `'` vs `"` in earlier versions left an SQLi-shape
4120 // gap. Now both blocked.
4121 // BD URL slugs (`filename`, `subscription_filename`, `post_filename`,