@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.
- package/package.json +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +9 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +8 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +19 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +46 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +39 -0
- package/src/stories/DateField.stories.tsx +28 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +26 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +10 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +15 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +30 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +7 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- 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
|
|
44
|
-
//
|
|
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
|
|
54
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
55
|
+
if (/\.(local|internal|localdomain|home\.arpa)$/.test(host)) return true;
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
package/src/api/onboarding.ts
CHANGED
|
@@ -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 {
|
package/src/api/save-tokens.ts
CHANGED
|
@@ -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 {
|
package/src/api/site-auth.ts
CHANGED
|
@@ -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("/")
|
|
64
|
-
|
|
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
|
}
|
package/src/app/layout.tsx
CHANGED
|
@@ -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
|
+
}
|