@behavioral-agentic-design-system/core 0.42.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/package.json +38 -8
  2. package/scripts/a11y-lint.cjs +101 -14
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-tokens.cjs +122 -7
  5. package/scripts/check-dark-contrast.mjs +204 -0
  6. package/scripts/check-flush-edges.mjs +245 -0
  7. package/scripts/check-spec.mjs +73 -0
  8. package/scripts/deal-directions.mjs +186 -0
  9. package/scripts/design-system-advisory/README.md +239 -0
  10. package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
  11. package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
  12. package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
  13. package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
  14. package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
  15. package/scripts/design-system-advisory/check-label-case.mjs +92 -0
  16. package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
  17. package/scripts/design-system-advisory/check-radius.mjs +56 -0
  18. package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
  19. package/scripts/design-system-advisory/check-small-text.mjs +72 -0
  20. package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
  21. package/scripts/design-system-advisory/defaults.mjs +90 -0
  22. package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
  23. package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
  24. package/scripts/design-system-advisory/lib.mjs +255 -0
  25. package/scripts/design-system-advisory/run.mjs +189 -0
  26. package/scripts/design-system-advisory/workflow.yml +82 -0
  27. package/scripts/health-report.mjs +20 -14
  28. package/scripts/lib/copy-strings.mjs +146 -0
  29. package/scripts/lib/counted-lint.mjs +100 -0
  30. package/scripts/lib/dark-contrast.mjs +120 -0
  31. package/scripts/lib/flush-edges.mjs +294 -0
  32. package/scripts/lib/lab-lint.mjs +62 -0
  33. package/scripts/lib/marketing-library.mjs +129 -0
  34. package/scripts/lib/mount-page.mjs +25 -0
  35. package/scripts/lib/on-system.mjs +249 -0
  36. package/scripts/lib/random.mjs +22 -0
  37. package/scripts/lib/source-scan.mjs +173 -0
  38. package/scripts/lib/spec-parse.d.mts +25 -0
  39. package/scripts/lib/spec-parse.mjs +188 -0
  40. package/scripts/lib/tells.mjs +366 -0
  41. package/scripts/lint-arbitrary-tokens.mjs +47 -0
  42. package/scripts/lint-component-token-refs.mjs +63 -0
  43. package/scripts/lint-content-hierarchy.mjs +114 -0
  44. package/scripts/lint-control-baseline.mjs +72 -0
  45. package/scripts/lint-copy-punctuation.mjs +60 -0
  46. package/scripts/lint-css-vars.mjs +175 -0
  47. package/scripts/lint-even-padding.mjs +58 -0
  48. package/scripts/lint-html-nesting.mjs +116 -0
  49. package/scripts/lint-label-case.mjs +219 -0
  50. package/scripts/lint-live-ctas.mjs +138 -0
  51. package/scripts/lint-microanimation.mjs +2 -2
  52. package/scripts/lint-proximity.mjs +181 -0
  53. package/scripts/lint-slop.mjs +1 -1
  54. package/scripts/lint-spacing-scale.mjs +78 -0
  55. package/scripts/lint-target-size.cjs +132 -0
  56. package/scripts/lint-token-primitives.mjs +307 -0
  57. package/scripts/on-system-score.mjs +95 -0
  58. package/scripts/size-audit.cjs +2 -2
  59. package/scripts/slop-rules.mjs +1 -1
  60. package/scripts/source-images.mjs +180 -0
  61. package/scripts/ux-tells.mjs +80 -0
  62. package/scripts/wcag-audit.cjs +25 -4
  63. package/src/api/brand-colors.ts +3 -0
  64. package/src/api/brand-fonts.ts +3 -0
  65. package/src/api/brand-mark.ts +6 -1
  66. package/src/api/dev-write-guard.ts +53 -0
  67. package/src/api/layers/file.ts +9 -4
  68. package/src/api/onboarding-extract.ts +85 -30
  69. package/src/api/onboarding.ts +3 -0
  70. package/src/api/save-tokens.ts +3 -0
  71. package/src/api/site-auth.ts +14 -2
  72. package/src/app/layout.tsx +6 -0
  73. package/src/app/preview/canvas/page.tsx +12 -0
  74. package/src/app/preview/components/page.tsx +828 -14
  75. package/src/app/preview/sticker-sheet/page.tsx +329 -0
  76. package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
  77. package/src/app/preview/studio/blank-screen.tsx +143 -0
  78. package/src/app/preview/studio/page.tsx +7 -0
  79. package/src/app/shell.tsx +164 -47
  80. package/src/components/Foundations/Colors.stories.tsx +119 -8
  81. package/src/components/canvas/canvas.tsx +458 -0
  82. package/src/components/canvas/layout.ts +72 -0
  83. package/src/components/canvas/parse-canvas.ts +32 -0
  84. package/src/components/canvas/sample.ts +90 -0
  85. package/src/components/canvas/spec-frame.tsx +43 -0
  86. package/src/components/canvas/types.ts +33 -0
  87. package/src/components/docs-tab.tsx +7 -7
  88. package/src/components/home-recent.tsx +73 -0
  89. package/src/components/home-tab.tsx +19 -14
  90. package/src/components/layers-tab.tsx +2 -2
  91. package/src/components/markdown-preview.tsx +60 -12
  92. package/src/components/onboarding-wizard.tsx +1 -1
  93. package/src/components/studio/control-panel.tsx +299 -0
  94. package/src/components/studio/control-row.tsx +77 -0
  95. package/src/components/studio/preview-frame.tsx +165 -0
  96. package/src/components/studio/preview-pane.tsx +247 -0
  97. package/src/components/studio/studio.tsx +133 -128
  98. package/src/components/studio/types.ts +218 -0
  99. package/src/components/studio/use-studio-tweaks.ts +128 -0
  100. package/src/components/studio/use-studio-view-state.ts +72 -0
  101. package/src/components/ui/autocomplete.tsx +1 -1
  102. package/src/components/ui/avatar.tsx +4 -0
  103. package/src/components/ui/chart.tsx +134 -42
  104. package/src/components/ui/checkbox-group.tsx +1 -1
  105. package/src/components/ui/checkbox.tsx +1 -1
  106. package/src/components/ui/color-picker.tsx +20 -4
  107. package/src/components/ui/combobox.tsx +1 -0
  108. package/src/components/ui/command.tsx +1 -1
  109. package/src/components/ui/data-table.tsx +64 -3
  110. package/src/components/ui/date-field.tsx +1 -1
  111. package/src/components/ui/date-picker.tsx +2 -0
  112. package/src/components/ui/date-range-picker.tsx +4 -0
  113. package/src/components/ui/editable.tsx +1 -0
  114. package/src/components/ui/faceted-filter.tsx +187 -0
  115. package/src/components/ui/file-upload.tsx +21 -2
  116. package/src/components/ui/gauge-chart.tsx +18 -4
  117. package/src/components/ui/heatmap.tsx +3 -1
  118. package/src/components/ui/inline-edit.tsx +175 -0
  119. package/src/components/ui/input-group.tsx +5 -2
  120. package/src/components/ui/month-picker.tsx +1 -1
  121. package/src/components/ui/multi-select.tsx +1 -0
  122. package/src/components/ui/number-input.tsx +28 -5
  123. package/src/components/ui/otp-input.tsx +208 -0
  124. package/src/components/ui/phone-input.tsx +274 -0
  125. package/src/components/ui/radio-group.tsx +2 -2
  126. package/src/components/ui/search-input.tsx +1 -1
  127. package/src/components/ui/sparkline.tsx +33 -4
  128. package/src/components/ui/spinner.tsx +23 -4
  129. package/src/components/ui/table.tsx +9 -0
  130. package/src/components/ui/tags-input.tsx +1 -1
  131. package/src/components/ui/timer.tsx +1 -0
  132. package/src/components/ui/transfer-list.tsx +13 -26
  133. package/src/components/ui/week-picker.tsx +1 -13
  134. package/src/components/ui/year-picker.tsx +1 -1
  135. package/src/data/component-added.json +966 -0
  136. package/src/data/docs-index.ts +35 -2
  137. package/src/data/history.json +161 -161
  138. package/src/data/sticker-sheet.json +9244 -0
  139. package/src/docs-trace-globs.json +1 -0
  140. package/src/hooks/use-global-mono-font.ts +1 -0
  141. package/src/hooks/use-global-primary-color.ts +1 -0
  142. package/src/hooks/use-global-sans-font.ts +1 -0
  143. package/src/hooks/use-global-serif-font.ts +1 -0
  144. package/src/hooks/use-global-type-scale.ts +17 -2
  145. package/src/hooks/use-mobile.ts +2 -0
  146. package/src/hooks/use-sync-type-scale.ts +7 -11
  147. package/src/lib/chart-motion.ts +41 -0
  148. package/src/lib/get-icon-color.ts +1 -1
  149. package/src/lib/spec-parse.ts +4 -0
  150. package/src/lib/svg-sanitize.ts +19 -9
  151. package/src/stories/Accordion.stories.tsx +7 -0
  152. package/src/stories/ActionBar.stories.tsx +5 -0
  153. package/src/stories/Affix.stories.tsx +4 -0
  154. package/src/stories/AiBadge.stories.tsx +9 -7
  155. package/src/stories/Alert.stories.tsx +13 -0
  156. package/src/stories/AlertDialog.stories.tsx +4 -0
  157. package/src/stories/Anchor.stories.tsx +5 -0
  158. package/src/stories/AngleSlider.stories.tsx +6 -3
  159. package/src/stories/AspectRatio.stories.tsx +4 -0
  160. package/src/stories/Autocomplete.stories.tsx +8 -0
  161. package/src/stories/Avatar.stories.tsx +10 -0
  162. package/src/stories/Badge.stories.tsx +14 -6
  163. package/src/stories/Blockquote.stories.tsx +6 -0
  164. package/src/stories/BottomNavigation.stories.tsx +4 -0
  165. package/src/stories/Breadcrumb.stories.tsx +3 -0
  166. package/src/stories/Burger.stories.tsx +1 -0
  167. package/src/stories/Button.stories.tsx +24 -0
  168. package/src/stories/ButtonGroup.stories.tsx +9 -0
  169. package/src/stories/Calendar.stories.tsx +3 -0
  170. package/src/stories/Canvas.stories.tsx +45 -0
  171. package/src/stories/Card.stories.tsx +4 -0
  172. package/src/stories/Carousel.stories.tsx +6 -0
  173. package/src/stories/Cascader.stories.tsx +4 -0
  174. package/src/stories/Chart.stories.tsx +46 -1
  175. package/src/stories/ChatBubble.stories.tsx +8 -2
  176. package/src/stories/ChatMarker.stories.tsx +1 -0
  177. package/src/stories/Checkbox.stories.tsx +40 -0
  178. package/src/stories/CheckboxCard.stories.tsx +8 -0
  179. package/src/stories/CheckboxGroup.stories.tsx +19 -0
  180. package/src/stories/Chip.stories.tsx +10 -19
  181. package/src/stories/CircularProgress.stories.tsx +13 -27
  182. package/src/stories/Clipboard.stories.tsx +6 -0
  183. package/src/stories/CloseButton.stories.tsx +6 -4
  184. package/src/stories/Code.stories.tsx +8 -1
  185. package/src/stories/Collapsible.stories.tsx +2 -0
  186. package/src/stories/ColorPicker.stories.tsx +46 -0
  187. package/src/stories/ColorSwatch.stories.tsx +1 -0
  188. package/src/stories/Combobox.stories.tsx +9 -0
  189. package/src/stories/Command.stories.tsx +2 -0
  190. package/src/stories/Container.stories.tsx +8 -0
  191. package/src/stories/ContextMenu.stories.tsx +9 -0
  192. package/src/stories/CopyButton.stories.tsx +12 -36
  193. package/src/stories/DataList.stories.tsx +8 -0
  194. package/src/stories/DataTable.stories.tsx +39 -0
  195. package/src/stories/DateField.stories.tsx +28 -0
  196. package/src/stories/DatePicker.stories.tsx +34 -0
  197. package/src/stories/DateRangePicker.stories.tsx +32 -0
  198. package/src/stories/Dialog.stories.tsx +8 -0
  199. package/src/stories/Drawer.stories.tsx +6 -0
  200. package/src/stories/DropdownMenu.stories.tsx +2 -0
  201. package/src/stories/Editable.stories.tsx +12 -0
  202. package/src/stories/EmptyState.stories.tsx +9 -0
  203. package/src/stories/FacetedFilter.stories.tsx +197 -0
  204. package/src/stories/Field.stories.tsx +7 -0
  205. package/src/stories/Fieldset.stories.tsx +8 -0
  206. package/src/stories/FileButton.stories.tsx +4 -0
  207. package/src/stories/FileUpload.stories.tsx +16 -17
  208. package/src/stories/FloatLabel.stories.tsx +3 -8
  209. package/src/stories/FloatingActionButton.stories.tsx +10 -0
  210. package/src/stories/FloatingIndicator.stories.tsx +4 -0
  211. package/src/stories/FloatingPanel.stories.tsx +6 -0
  212. package/src/stories/FocusTrap.stories.tsx +5 -0
  213. package/src/stories/FormatByte.stories.tsx +6 -0
  214. package/src/stories/FormatDate.stories.tsx +8 -0
  215. package/src/stories/FormatNumber.stories.tsx +9 -0
  216. package/src/stories/GaugeChart.stories.tsx +9 -3
  217. package/src/stories/Heatmap.stories.tsx +11 -0
  218. package/src/stories/Highlight.stories.tsx +6 -0
  219. package/src/stories/HoverCard.stories.tsx +4 -0
  220. package/src/stories/Image.stories.tsx +9 -0
  221. package/src/stories/Indicator.stories.tsx +19 -0
  222. package/src/stories/InlineEdit.stories.tsx +106 -0
  223. package/src/stories/Input.stories.tsx +7 -0
  224. package/src/stories/InputClearButton.stories.tsx +3 -0
  225. package/src/stories/InputGroup.stories.tsx +40 -0
  226. package/src/stories/Kbd.stories.tsx +7 -1
  227. package/src/stories/KeyboardShortcut.stories.tsx +2 -0
  228. package/src/stories/Label.stories.tsx +2 -0
  229. package/src/stories/Link.stories.tsx +9 -0
  230. package/src/stories/List.stories.tsx +8 -0
  231. package/src/stories/Listbox.stories.tsx +1 -0
  232. package/src/stories/LoadingDots.stories.tsx +5 -3
  233. package/src/stories/LoadingOverlay.stories.tsx +5 -1
  234. package/src/stories/Mark.stories.tsx +5 -0
  235. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  236. package/src/stories/Marquee.stories.tsx +4 -0
  237. package/src/stories/Masonry.stories.tsx +5 -0
  238. package/src/stories/Menubar.stories.tsx +3 -0
  239. package/src/stories/Meter.stories.tsx +11 -17
  240. package/src/stories/MonthPicker.stories.tsx +26 -1
  241. package/src/stories/MotionToggle.stories.tsx +1 -0
  242. package/src/stories/MultiSelect.stories.tsx +9 -0
  243. package/src/stories/NativeSelect.stories.tsx +1 -0
  244. package/src/stories/NavLink.stories.tsx +7 -0
  245. package/src/stories/NavigationMenu.stories.tsx +5 -0
  246. package/src/stories/NavigationRail.stories.tsx +10 -0
  247. package/src/stories/Notification.stories.tsx +13 -34
  248. package/src/stories/NumberInput.stories.tsx +33 -1
  249. package/src/stories/OtpInput.stories.tsx +110 -0
  250. package/src/stories/Overlay.stories.tsx +5 -1
  251. package/src/stories/Pagination.stories.tsx +8 -0
  252. package/src/stories/PasswordInput.stories.tsx +2 -0
  253. package/src/stories/PhoneInput.stories.tsx +127 -0
  254. package/src/stories/PinInput.stories.tsx +9 -2
  255. package/src/stories/Popover.stories.tsx +2 -0
  256. package/src/stories/Progress.stories.tsx +6 -1
  257. package/src/stories/Prose.stories.tsx +8 -0
  258. package/src/stories/QrCode.stories.tsx +2 -0
  259. package/src/stories/Questionnaire.stories.tsx +7 -0
  260. package/src/stories/RadioGroup.stories.tsx +40 -0
  261. package/src/stories/RatingGroup.stories.tsx +8 -4
  262. package/src/stories/Resizable.stories.tsx +4 -2
  263. package/src/stories/Result.stories.tsx +3 -0
  264. package/src/stories/Reveal.stories.tsx +2 -0
  265. package/src/stories/RollingNumber.stories.tsx +5 -0
  266. package/src/stories/ScrollArea.stories.tsx +3 -1
  267. package/src/stories/SearchInput.stories.tsx +10 -6
  268. package/src/stories/SegmentedControl.stories.tsx +11 -0
  269. package/src/stories/Select.stories.tsx +7 -0
  270. package/src/stories/Separator.stories.tsx +6 -0
  271. package/src/stories/Sheet.stories.tsx +5 -0
  272. package/src/stories/Sidebar.stories.tsx +40 -1
  273. package/src/stories/SimpleGrid.stories.tsx +5 -0
  274. package/src/stories/Skeleton.stories.tsx +8 -0
  275. package/src/stories/SkeletonTable.stories.tsx +6 -5
  276. package/src/stories/SkipLink.stories.tsx +3 -0
  277. package/src/stories/Slider.stories.tsx +2 -1
  278. package/src/stories/Sonner.stories.tsx +7 -0
  279. package/src/stories/Sparkline.stories.tsx +14 -1
  280. package/src/stories/Spinner.stories.tsx +20 -10
  281. package/src/stories/Spoiler.stories.tsx +5 -0
  282. package/src/stories/Squircle.stories.tsx +7 -0
  283. package/src/stories/Stack.stories.tsx +7 -0
  284. package/src/stories/StatusBadge.stories.tsx +12 -6
  285. package/src/stories/Stepper.stories.tsx +5 -0
  286. package/src/stories/Switch.stories.tsx +4 -0
  287. package/src/stories/Table.stories.tsx +10 -1
  288. package/src/stories/Tabs.stories.tsx +8 -0
  289. package/src/stories/Tag.stories.tsx +13 -5
  290. package/src/stories/TagsInput.stories.tsx +15 -0
  291. package/src/stories/Text.stories.tsx +12 -0
  292. package/src/stories/Textarea.stories.tsx +9 -0
  293. package/src/stories/ThemeIcon.stories.tsx +6 -3
  294. package/src/stories/TimePicker.stories.tsx +2 -0
  295. package/src/stories/Timeline.stories.tsx +12 -0
  296. package/src/stories/Timer.stories.tsx +30 -0
  297. package/src/stories/Toggle.stories.tsx +7 -5
  298. package/src/stories/ToggleGroup.stories.tsx +5 -0
  299. package/src/stories/ToggleTip.stories.tsx +4 -0
  300. package/src/stories/Toolbar.stories.tsx +6 -0
  301. package/src/stories/Tooltip.stories.tsx +3 -0
  302. package/src/stories/Tour.stories.tsx +3 -0
  303. package/src/stories/TransferList.stories.tsx +7 -0
  304. package/src/stories/TreeSelect.stories.tsx +4 -0
  305. package/src/stories/TreeView.stories.tsx +5 -0
  306. package/src/stories/TypingIndicator.stories.tsx +4 -0
  307. package/src/stories/VisuallyHidden.stories.tsx +3 -0
  308. package/src/stories/Watermark.stories.tsx +6 -0
  309. package/src/stories/WeekPicker.stories.tsx +25 -1
  310. package/src/stories/WordRotate.stories.tsx +5 -0
  311. package/src/stories/YearPicker.stories.tsx +26 -11
  312. package/src/stories/story-groups.json +22 -16
  313. package/src/styles.css +50 -2
  314. package/src/tokens.json +86 -58
@@ -1,5 +1,9 @@
1
1
  import { NextResponse } from "next/server";
2
+ import { lookup } from "node:dns/promises";
3
+ import { isIP } from "node:net";
2
4
  import { load, type CheerioAPI } from "cheerio";
5
+ import { refuseUnsafeWrite } from "./dev-write-guard";
6
+ import { sanitizeSvg } from "../lib/svg-sanitize";
3
7
 
4
8
  const FETCH_TIMEOUT_MS = 12_000;
5
9
  const USER_AGENT = "Mozilla/5.0 (compatible; BADS-Onboarding/1.0)";
@@ -40,39 +44,82 @@ export type ExtractResult = {
40
44
  warnings: string[];
41
45
  };
42
46
 
43
- // SSRF defense-in-depth: reject URLs that point at private, internal, or
44
- // loopback targets so a user-supplied URL can't be used to probe internal
45
- // services or the cloud metadata endpoint. This is hostname-literal checking
46
- // only (it inspects the string the user typed) and is NOT full DNS-rebinding
47
- // protection — a hostname that resolves to a private IP at fetch time still
48
- // gets through. Strip the brackets IPv6 hosts arrive wrapped in before testing.
47
+ // SSRF defence: refuse private, internal and loopback targets, whether typed, resolved by DNS, or reached by a
48
+ // redirect. Literal IPv4/IPv6 forms are parsed with node:net rather than matched by prefix.
49
49
  function isBlockedHost(hostname: string): boolean {
50
- const host = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "");
50
+ const host = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
51
51
  if (!host) return true;
52
52
 
53
53
  // localhost and internal-only TLD suffixes
54
- if (host === "localhost") return true;
55
- if (/\.local$/.test(host) || /\.internal$/.test(host)) return true;
54
+ if (host === "localhost" || host.endsWith(".localhost")) return true;
55
+ if (/\.(local|internal|localdomain|home\.arpa)$/.test(host)) return true;
56
56
 
57
- // IPv6 loopback, unique-local (fc00::/7 → fc/fd) and link-local (fe80::)
58
- if (host === "::1") return true;
59
- if (/^f[cd][0-9a-f]*:/.test(host)) return true;
60
- if (/^fe80:/.test(host)) return true;
61
-
62
- // IPv4 unspecified, loopback 127.0.0.0/8, and link-local 169.254.0.0/16
63
- // (covers the 169.254.169.254 cloud metadata IP)
64
- if (host === "0.0.0.0") return true;
65
- if (/^127\./.test(host)) return true;
66
- if (/^169\.254\./.test(host)) return true;
57
+ const family = isIP(host);
58
+ if (family === 6) return isBlockedIPv6(host);
59
+ if (family === 4) return isBlockedIPv4(host);
60
+ return false;
61
+ }
67
62
 
68
- // IPv4 private ranges: 10/8, 172.16-31/12, 192.168/16
69
- if (/^10\./.test(host)) return true;
70
- if (/^172\.(1[6-9]|2[0-9]|3[01])\./.test(host)) return true;
71
- if (/^192\.168\./.test(host)) return true;
63
+ function isBlockedIPv4(ip: string): boolean {
64
+ const [a, b] = ip.split(".").map(Number);
65
+ if (a === 0 || a === 10 || a === 127) return true; // this-network, private, loopback
66
+ if (a === 169 && b === 254) return true; // link-local, incl. the 169.254.169.254 metadata IP
67
+ if (a === 172 && b >= 16 && b <= 31) return true;
68
+ if (a === 192 && b === 168) return true;
69
+ if (a === 100 && b >= 64 && b <= 127) return true; // carrier-grade NAT, also used for internal clouds
70
+ if (a >= 224) return true; // multicast, reserved, broadcast
71
+ return false;
72
+ }
72
73
 
74
+ function isBlockedIPv6(ip: string): boolean {
75
+ if (ip === "::" || ip === "::1") return true;
76
+ if (/^f[cd]/.test(ip) || /^fe[89ab]/.test(ip)) return true; // unique-local fc00::/7, link-local fe80::/10
77
+ // IPv4-mapped (::ffff:a.b.c.d, or ::ffff:7f00:1 once the URL parser has normalized it) and other embeddings
78
+ // of an IPv4 address. Refuse them all rather than decode each form.
79
+ if (/^(0:){0,5}:?ffff:/.test(ip) || /^::ffff:/.test(ip) || /^64:ff9b:/.test(ip) || /^::\d+\.\d+/.test(ip)) return true;
73
80
  return false;
74
81
  }
75
82
 
83
+ // A public-looking name can resolve to a private address (an attacker-owned A record pointing at 127.0.0.1 or
84
+ // 169.254.169.254). Resolve first and refuse if ANY answer is private. A name that resolves between this check
85
+ // and the fetch (a rebinding race) is not covered; closing that needs a pinned-IP agent.
86
+ async function resolvesToPublicAddress(hostname: string): Promise<boolean> {
87
+ const host = hostname.replace(/^\[|\]$/g, "");
88
+ if (isIP(host)) return !isBlockedHost(host);
89
+ try {
90
+ const answers = await lookup(host, { all: true });
91
+ return answers.length > 0 && answers.every((a) => !isBlockedHost(a.address));
92
+ } catch {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ const MAX_REDIRECTS = 5;
98
+
99
+ // fetch() that checks every hop. The default redirect: "follow" re-requests whatever Location says, so a public
100
+ // page could 302 to http://169.254.169.254/ and the first-URL check would never see it. Stylesheet and logo URLs
101
+ // come from the fetched page, so they go through here too.
102
+ async function safeFetch(
103
+ url: string,
104
+ init: RequestInit,
105
+ ): Promise<{ res: Response; finalUrl: string }> {
106
+ let current = url;
107
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
108
+ const u = new URL(current);
109
+ if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("Only http(s) URLs can be fetched");
110
+ if (isBlockedHost(u.hostname) || !(await resolvesToPublicAddress(u.hostname))) {
111
+ throw new Error("That address points at a private or internal network");
112
+ }
113
+ const res = await fetch(current, { ...init, redirect: "manual" });
114
+ if (res.status >= 300 && res.status < 400 && res.headers.get("location")) {
115
+ current = new URL(res.headers.get("location") as string, current).toString();
116
+ continue;
117
+ }
118
+ return { res, finalUrl: current };
119
+ }
120
+ throw new Error("Too many redirects");
121
+ }
122
+
76
123
  function normalizeUrl(input: string): string | null {
77
124
  const trimmed = input.trim();
78
125
  if (!trimmed) return null;
@@ -91,20 +138,19 @@ async function fetchHtml(url: string): Promise<{ html: string; finalUrl: string
91
138
  const controller = new AbortController();
92
139
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
93
140
  try {
94
- const res = await fetch(url, {
141
+ const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
95
142
  headers: {
96
143
  "User-Agent": USER_AGENT,
97
144
  Accept: "text/html,application/xhtml+xml",
98
145
  "Accept-Language": "en-US,en;q=0.9",
99
146
  },
100
- redirect: "follow",
101
147
  signal: controller.signal,
102
148
  });
103
149
  if (!res.ok) {
104
150
  throw new Error(`Fetch failed: ${res.status} ${res.statusText}`);
105
151
  }
106
152
  const html = await res.text();
107
- return { html, finalUrl: res.url || url };
153
+ return { html, finalUrl: resolvedUrl };
108
154
  } finally {
109
155
  clearTimeout(timer);
110
156
  }
@@ -117,7 +163,7 @@ async function fetchStylesheet(url: string): Promise<string | null> {
117
163
  try {
118
164
  const controller = new AbortController();
119
165
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
120
- const res = await fetch(url, {
166
+ const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
121
167
  headers: { "User-Agent": USER_AGENT, Accept: "text/css,*/*;q=0.1" },
122
168
  signal: controller.signal,
123
169
  });
@@ -302,7 +348,7 @@ async function fetchSvg(url: string): Promise<string | null> {
302
348
  try {
303
349
  const controller = new AbortController();
304
350
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
305
- const res = await fetch(url, {
351
+ const { res, finalUrl: resolvedUrl } = await safeFetch(url, {
306
352
  headers: { "User-Agent": USER_AGENT },
307
353
  signal: controller.signal,
308
354
  });
@@ -324,7 +370,8 @@ async function extractLogo($: CheerioAPI, baseUrl: string): Promise<ExtractedLog
324
370
  if (headerSvg.length) {
325
371
  const html = $.html(headerSvg);
326
372
  if (html && html.length < 16 * 1024) {
327
- return { kind: "svg", svg: html };
373
+ const clean = sanitizeSvg(html);
374
+ if (clean.ok) return { kind: "svg", svg: clean.svg };
328
375
  }
329
376
  }
330
377
 
@@ -337,7 +384,8 @@ async function extractLogo($: CheerioAPI, baseUrl: string): Promise<ExtractedLog
337
384
  const abs = new URL(src, baseUrl).toString();
338
385
  if (abs.endsWith(".svg")) {
339
386
  const svg = await fetchSvg(abs);
340
- if (svg) return { kind: "svg", svg };
387
+ const clean = svg ? sanitizeSvg(svg) : null;
388
+ if (clean?.ok) return { kind: "svg", svg: clean.svg };
341
389
  }
342
390
  return { kind: "image", url: abs };
343
391
  } catch {}
@@ -403,6 +451,13 @@ function extractCopy($: CheerioAPI): {
403
451
  }
404
452
 
405
453
  export async function POST(request: Request) {
454
+ // Fetching an arbitrary URL from the server is only for the local onboarding wizard. On a deployed site it
455
+ // would be an open proxy.
456
+ if (process.env.NODE_ENV !== "development") {
457
+ return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
458
+ }
459
+ const refused = refuseUnsafeWrite(request);
460
+ if (refused) return refused;
406
461
  let payload: { url?: string };
407
462
  try {
408
463
  payload = (await request.json()) as { url?: string };
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { NextResponse } from "next/server";
4
+ import { refuseUnsafeWrite } from "./dev-write-guard";
4
5
 
5
6
  const ONBOARDING_PATH = path.join(process.cwd(), "onboarding-brief.json");
6
7
 
@@ -38,6 +39,8 @@ export async function POST(request: Request) {
38
39
  if (process.env.NODE_ENV !== "development") {
39
40
  return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
40
41
  }
42
+ const refused = refuseUnsafeWrite(request);
43
+ if (refused) return refused;
41
44
 
42
45
  let payload: SavePayload;
43
46
  try {
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { NextResponse } from "next/server";
6
+ import { refuseUnsafeWrite } from "./dev-write-guard";
6
7
 
7
8
  const execAsync = promisify(exec);
8
9
  const TOKENS_PATH = path.join(process.cwd(), "packages/core/src/tokens.json");
@@ -89,6 +90,8 @@ export async function POST(request: Request) {
89
90
  { status: 403 },
90
91
  );
91
92
  }
93
+ const refused = refuseUnsafeWrite(request);
94
+ if (refused) return refused;
92
95
 
93
96
  let payload: SavePayload;
94
97
  try {
@@ -59,7 +59,19 @@ export async function POST(req: NextRequest) {
59
59
  return redirect;
60
60
  }
61
61
 
62
+ // Only ever send the visitor to a path on this site. Checking the first characters is not enough: browsers
63
+ // read "/\\evil.com" and "/<tab>/evil.com" as "//evil.com". So resolve the value the way a browser would and
64
+ // accept it only if it stays on the same origin.
62
65
  function sanitizeNext(next: string): string {
63
- if (next.startsWith("/") && !next.startsWith("//")) return next;
64
- return "/";
66
+ if (!next.startsWith("/") || /[\\\u0000-\u001f]/.test(next)) return "/";
67
+ const base = "https://site.invalid";
68
+ try {
69
+ const u = new URL(next, base);
70
+ if (u.origin !== base) return "/";
71
+ const out = u.pathname + u.search + u.hash;
72
+ // URL collapses "/.//evil.com" to "//evil.com", which a browser reads as another site.
73
+ return out.startsWith("//") ? "/" : out;
74
+ } catch {
75
+ return "/";
76
+ }
65
77
  }
@@ -262,6 +262,12 @@ export default function RootLayout({
262
262
  if (typeof t.ratio === "number") ratio = t.ratio;
263
263
  } catch (e) {}
264
264
  }
265
+ // Enforce the 14px text-xs floor (WCAG 1.4.4) on the persisted
266
+ // value too. Mirrors applyScale() in use-global-type-scale.ts;
267
+ // without it base 18 / ratio 1.4 booted text-xs at ~9.18px
268
+ // until a slider moved. Lower ratio first, then raise base.
269
+ ratio = Math.max(1.05, Math.min(ratio, 1.4, Math.sqrt(base / 14)));
270
+ base = Math.min(22, Math.max(base, 14 * ratio * ratio));
265
271
  for (var name in STEPS) {
266
272
  var step = STEPS[name];
267
273
  var size = base * Math.pow(ratio, step);
@@ -0,0 +1,12 @@
1
+ "use client";
2
+
3
+ import { Canvas } from "../../../components/canvas/canvas";
4
+ import { SAMPLE_CANVAS, SAMPLE_SPEC, sampleResolveView } from "../../../components/canvas/sample";
5
+
6
+ export default function CanvasPreviewPage() {
7
+ return (
8
+ <main className="h-screen p-4">
9
+ <Canvas doc={SAMPLE_CANVAS} docs={{ "spec.md": SAMPLE_SPEC }} resolveView={sampleResolveView} />
10
+ </main>
11
+ );
12
+ }