@hubspot/cms-dev-server 1.2.84 → 1.2.86

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.
@@ -10,7 +10,7 @@ import {
10
10
  import { createRequire } from "module";
11
11
  import { default as react } from "@vitejs/plugin-react";
12
12
 
13
- // ../cms-js-internal/dist/types-C8bPIEz4.js
13
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
14
14
  import path from "path";
15
15
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
16
16
  import { join } from "path/posix";
@@ -199,6 +199,50 @@ function noncePlaceholderPlugin() {
199
199
  }
200
200
  };
201
201
  }
202
+ var MAX_EXTRA_DECODE_PASSES = 3;
203
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
204
+ function isPathTraversal(url2) {
205
+ if (!url2)
206
+ return false;
207
+ let decodedUrl;
208
+ try {
209
+ decodedUrl = decodeURI(url2);
210
+ } catch {
211
+ return true;
212
+ }
213
+ let [pathname] = decodedUrl.split(/[?#]/);
214
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
215
+ if (hasTraversalSegment(pathname))
216
+ return true;
217
+ let nextPathname;
218
+ try {
219
+ nextPathname = decodeURIComponent(pathname);
220
+ } catch {
221
+ return false;
222
+ }
223
+ if (nextPathname === pathname)
224
+ return false;
225
+ pathname = nextPathname;
226
+ }
227
+ return hasTraversalSegment(pathname);
228
+ }
229
+ function pathTraversalGuardMiddleware(req, res, next) {
230
+ if (isPathTraversal(req.url)) {
231
+ res.statusCode = 403;
232
+ res.end();
233
+ return;
234
+ }
235
+ next();
236
+ }
237
+ function pathTraversalGuardPlugin() {
238
+ return {
239
+ name: "cms-path-traversal-guard",
240
+ apply: "serve",
241
+ configureServer(server) {
242
+ server.middlewares.use(pathTraversalGuardMiddleware);
243
+ }
244
+ };
245
+ }
202
246
  var traverse = _traverse.default;
203
247
  var {
204
248
  createServerRenderContextV2: createServerRenderContextV22,
@@ -373,6 +417,7 @@ async function forEachModule(projectRoot, moduleName, run) {
373
417
  dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
374
418
  },
375
419
  plugins: [
420
+ pathTraversalGuardPlugin(),
376
421
  react({
377
422
  babel: {
378
423
  plugins: [
@@ -10,7 +10,7 @@ import { createServer as createViteServer } from "vite";
10
10
  import { createRequire } from "module";
11
11
  import { default as react } from "@vitejs/plugin-react";
12
12
 
13
- // ../cms-js-internal/dist/types-C8bPIEz4.js
13
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
14
14
  import path from "path";
15
15
  var viteRoot;
16
16
  var viteCommand;
@@ -113,6 +113,50 @@ function noncePlaceholderPlugin() {
113
113
  }
114
114
  };
115
115
  }
116
+ var MAX_EXTRA_DECODE_PASSES = 3;
117
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
118
+ function isPathTraversal(url2) {
119
+ if (!url2)
120
+ return false;
121
+ let decodedUrl;
122
+ try {
123
+ decodedUrl = decodeURI(url2);
124
+ } catch {
125
+ return true;
126
+ }
127
+ let [pathname] = decodedUrl.split(/[?#]/);
128
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
129
+ if (hasTraversalSegment(pathname))
130
+ return true;
131
+ let nextPathname;
132
+ try {
133
+ nextPathname = decodeURIComponent(pathname);
134
+ } catch {
135
+ return false;
136
+ }
137
+ if (nextPathname === pathname)
138
+ return false;
139
+ pathname = nextPathname;
140
+ }
141
+ return hasTraversalSegment(pathname);
142
+ }
143
+ function pathTraversalGuardMiddleware(req, res, next) {
144
+ if (isPathTraversal(req.url)) {
145
+ res.statusCode = 403;
146
+ res.end();
147
+ return;
148
+ }
149
+ next();
150
+ }
151
+ function pathTraversalGuardPlugin() {
152
+ return {
153
+ name: "cms-path-traversal-guard",
154
+ apply: "serve",
155
+ configureServer(server) {
156
+ server.middlewares.use(pathTraversalGuardMiddleware);
157
+ }
158
+ };
159
+ }
116
160
  var traverse = _traverse.default;
117
161
  var CMS_MODULE_COMPONENT_NAME = "Module";
118
162
  var DND_AREA_COMPONENT_NAME = "DndArea";
@@ -645,6 +689,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
645
689
  root: webRoot,
646
690
  ...ssrAndOptimizeDep,
647
691
  plugins: [
692
+ pathTraversalGuardPlugin(),
648
693
  hsStaticAssetPlugin(),
649
694
  jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
650
695
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { createServer as createViteServer } from "vite";
3
3
  import { createRequire } from "module";
4
4
  import { default as react } from "@vitejs/plugin-react";
5
5
 
6
- // ../cms-js-internal/dist/types-C8bPIEz4.js
6
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
7
7
  import path from "path";
8
8
  import { createHash } from "crypto";
9
9
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -585,6 +585,50 @@ function noncePlaceholderPlugin() {
585
585
  }
586
586
  };
587
587
  }
588
+ var MAX_EXTRA_DECODE_PASSES = 3;
589
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
590
+ function isPathTraversal(url3) {
591
+ if (!url3)
592
+ return false;
593
+ let decodedUrl;
594
+ try {
595
+ decodedUrl = decodeURI(url3);
596
+ } catch {
597
+ return true;
598
+ }
599
+ let [pathname] = decodedUrl.split(/[?#]/);
600
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
601
+ if (hasTraversalSegment(pathname))
602
+ return true;
603
+ let nextPathname;
604
+ try {
605
+ nextPathname = decodeURIComponent(pathname);
606
+ } catch {
607
+ return false;
608
+ }
609
+ if (nextPathname === pathname)
610
+ return false;
611
+ pathname = nextPathname;
612
+ }
613
+ return hasTraversalSegment(pathname);
614
+ }
615
+ function pathTraversalGuardMiddleware(req, res, next) {
616
+ if (isPathTraversal(req.url)) {
617
+ res.statusCode = 403;
618
+ res.end();
619
+ return;
620
+ }
621
+ next();
622
+ }
623
+ function pathTraversalGuardPlugin() {
624
+ return {
625
+ name: "cms-path-traversal-guard",
626
+ apply: "serve",
627
+ configureServer(server) {
628
+ server.middlewares.use(pathTraversalGuardMiddleware);
629
+ }
630
+ };
631
+ }
588
632
  var traverse = _traverse.default;
589
633
  var CMS_MODULE_COMPONENT_NAME = "Module";
590
634
  var DND_AREA_COMPONENT_NAME = "DndArea";
@@ -1217,6 +1261,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
1217
1261
  root: webRoot,
1218
1262
  ...ssrAndOptimizeDep,
1219
1263
  plugins: [
1264
+ pathTraversalGuardPlugin(),
1220
1265
  hsStaticAssetPlugin(),
1221
1266
  jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
1222
1267
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
@@ -1659,7 +1704,7 @@ function trackUsage(action) {
1659
1704
  eventName: EVENT_NAME,
1660
1705
  action,
1661
1706
  nodeVersion: getNodeVersionData(),
1662
- version: "1.2.84",
1707
+ version: "1.2.86",
1663
1708
  os: getPlatform()
1664
1709
  };
1665
1710
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -2090,6 +2135,9 @@ import { createEmptyServerRenderContext } from "@hubspot/cms-components";
2090
2135
 
2091
2136
  // src/proxyPage/constants.ts
2092
2137
  var VALID_PROXY_DOMAIN_SUFFIXES = ["localhost", "hslocal.net"];
2138
+ var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
2139
+ (domain) => `storybook.${domain}`
2140
+ );
2093
2141
 
2094
2142
  // src/proxyPage/utils.ts
2095
2143
  var getSubDomainFromValidLocalDomain = (hostname) => {
@@ -5392,9 +5440,6 @@ var appServerRouteHandler_default = appServerRouteHandler;
5392
5440
  // src/routes/createDevServerRoutes.ts
5393
5441
  import path16 from "path";
5394
5442
  var isProd2 = true;
5395
- var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
5396
- (domain) => `storybook.${domain}`
5397
- );
5398
5443
  var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
5399
5444
  const devServerApp = Router2();
5400
5445
  const { appViteServer, appWebRoot } = appLocals || {};
@@ -5410,7 +5455,7 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
5410
5455
  (__pathname, req) => STORYBOOK_DOMAINS.includes(req.hostname),
5411
5456
  {
5412
5457
  logLevel: "warn",
5413
- target: `http://localhost:${storybookPort}`
5458
+ target: `http://127.0.0.1:${storybookPort}`
5414
5459
  }
5415
5460
  )
5416
5461
  );
@@ -5605,6 +5650,7 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
5605
5650
  include: ["react", "react-dom", "react-dom/client"]
5606
5651
  },
5607
5652
  plugins: [
5653
+ pathTraversalGuardPlugin(),
5608
5654
  (() => {
5609
5655
  const require2 = createRequire2(import.meta.url);
5610
5656
  return react2({
@@ -6370,6 +6416,8 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
6370
6416
  "dev",
6371
6417
  "-p",
6372
6418
  STORYBOOK_PORT.toString(),
6419
+ "--host",
6420
+ DEV_SERVER_HOST,
6373
6421
  "-c",
6374
6422
  configPath,
6375
6423
  "--quiet",
@@ -6382,7 +6430,8 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
6382
6430
  portalId: authedPortalId.toString(),
6383
6431
  hsEnv: authedEnv,
6384
6432
  hublet: authedHublet,
6385
- WEB_ROOT: path19.join(webRoot, "components")
6433
+ WEB_ROOT: path19.join(webRoot, "components"),
6434
+ STORYBOOK_ALLOWED_HOSTS: STORYBOOK_DOMAINS.join(",")
6386
6435
  },
6387
6436
  stdio: "inherit"
6388
6437
  }
@@ -1,4 +1,4 @@
1
- // ../cms-js-internal/dist/types-C8bPIEz4.js
1
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
2
2
  import path from "path";
3
3
  import { createHash } from "crypto";
4
4
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -395,7 +395,6 @@ function getBaseAssetUrlFromBuild(buildDir) {
395
395
  return getBuildInfo(buildDir).baseAssetUrl;
396
396
  }
397
397
  var GATES = [
398
- "CMS:JSRenderer:RemoveMockClientEntryPlugin",
399
398
  "CMS:JSRenderer:AnalyzeCmsModules",
400
399
  "CMS:JSRenderer:StripNullBytes"
401
400
  ];
@@ -738,6 +737,50 @@ function noncePlaceholderPlugin() {
738
737
  }
739
738
  };
740
739
  }
740
+ var MAX_EXTRA_DECODE_PASSES = 3;
741
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
742
+ function isPathTraversal(url) {
743
+ if (!url)
744
+ return false;
745
+ let decodedUrl;
746
+ try {
747
+ decodedUrl = decodeURI(url);
748
+ } catch {
749
+ return true;
750
+ }
751
+ let [pathname] = decodedUrl.split(/[?#]/);
752
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
753
+ if (hasTraversalSegment(pathname))
754
+ return true;
755
+ let nextPathname;
756
+ try {
757
+ nextPathname = decodeURIComponent(pathname);
758
+ } catch {
759
+ return false;
760
+ }
761
+ if (nextPathname === pathname)
762
+ return false;
763
+ pathname = nextPathname;
764
+ }
765
+ return hasTraversalSegment(pathname);
766
+ }
767
+ function pathTraversalGuardMiddleware(req, res, next) {
768
+ if (isPathTraversal(req.url)) {
769
+ res.statusCode = 403;
770
+ res.end();
771
+ return;
772
+ }
773
+ next();
774
+ }
775
+ function pathTraversalGuardPlugin() {
776
+ return {
777
+ name: "cms-path-traversal-guard",
778
+ apply: "serve",
779
+ configureServer(server) {
780
+ server.middlewares.use(pathTraversalGuardMiddleware);
781
+ }
782
+ };
783
+ }
741
784
  var traverse = _traverse.default;
742
785
  var CMS_MODULE_COMPONENT_NAME = "Module";
743
786
  var DND_AREA_COMPONENT_NAME = "DndArea";
@@ -1300,12 +1343,15 @@ export {
1300
1343
  includesHublDataReference,
1301
1344
  isFullHeightPreviewEnabled,
1302
1345
  isLocalUiDisabled,
1346
+ isPathTraversal,
1303
1347
  isStorybookStory,
1304
1348
  isStylesheetAsset,
1305
1349
  isUngatedFor,
1306
1350
  jsonStringifyAndEscapeForInlineJS,
1307
1351
  namespaceModulePropsShape,
1308
1352
  noncePlaceholderPlugin,
1353
+ pathTraversalGuardMiddleware,
1354
+ pathTraversalGuardPlugin,
1309
1355
  removeComponentExtension,
1310
1356
  removeIndexFromPath,
1311
1357
  removeIndexOrTrailingJsFromPath,
package/dist/run.js CHANGED
@@ -896,7 +896,7 @@ function packagePath(metaUrl, projectPath) {
896
896
  );
897
897
  }
898
898
 
899
- // ../cms-js-internal/dist/types-C8bPIEz4.js
899
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
900
900
  import path4 from "path";
901
901
  import { createHash } from "crypto";
902
902
  import fs3, { readFileSync, existsSync as existsSync2, readdirSync, lstatSync } from "fs";
@@ -1478,6 +1478,50 @@ function noncePlaceholderPlugin() {
1478
1478
  }
1479
1479
  };
1480
1480
  }
1481
+ var MAX_EXTRA_DECODE_PASSES = 3;
1482
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
1483
+ function isPathTraversal(url3) {
1484
+ if (!url3)
1485
+ return false;
1486
+ let decodedUrl;
1487
+ try {
1488
+ decodedUrl = decodeURI(url3);
1489
+ } catch {
1490
+ return true;
1491
+ }
1492
+ let [pathname] = decodedUrl.split(/[?#]/);
1493
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
1494
+ if (hasTraversalSegment(pathname))
1495
+ return true;
1496
+ let nextPathname;
1497
+ try {
1498
+ nextPathname = decodeURIComponent(pathname);
1499
+ } catch {
1500
+ return false;
1501
+ }
1502
+ if (nextPathname === pathname)
1503
+ return false;
1504
+ pathname = nextPathname;
1505
+ }
1506
+ return hasTraversalSegment(pathname);
1507
+ }
1508
+ function pathTraversalGuardMiddleware(req, res, next) {
1509
+ if (isPathTraversal(req.url)) {
1510
+ res.statusCode = 403;
1511
+ res.end();
1512
+ return;
1513
+ }
1514
+ next();
1515
+ }
1516
+ function pathTraversalGuardPlugin() {
1517
+ return {
1518
+ name: "cms-path-traversal-guard",
1519
+ apply: "serve",
1520
+ configureServer(server) {
1521
+ server.middlewares.use(pathTraversalGuardMiddleware);
1522
+ }
1523
+ };
1524
+ }
1481
1525
  var traverse = _traverse.default;
1482
1526
  var CMS_MODULE_COMPONENT_NAME = "Module";
1483
1527
  var DND_AREA_COMPONENT_NAME = "DndArea";
@@ -2258,7 +2302,7 @@ function trackUsage(action) {
2258
2302
  eventName: EVENT_NAME,
2259
2303
  action,
2260
2304
  nodeVersion: getNodeVersionData(),
2261
- version: "1.2.84",
2305
+ version: "1.2.86",
2262
2306
  os: getPlatform()
2263
2307
  };
2264
2308
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -2689,6 +2733,9 @@ import { createEmptyServerRenderContext } from "@hubspot/cms-components";
2689
2733
 
2690
2734
  // src/proxyPage/constants.ts
2691
2735
  var VALID_PROXY_DOMAIN_SUFFIXES = ["localhost", "hslocal.net"];
2736
+ var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
2737
+ (domain2) => `storybook.${domain2}`
2738
+ );
2692
2739
 
2693
2740
  // src/proxyPage/utils.ts
2694
2741
  var getSubDomainFromValidLocalDomain = (hostname) => {
@@ -6002,6 +6049,7 @@ Custom origin: ${process.env.VITE_ORIGIN}
6002
6049
  root: webRoot2,
6003
6050
  ...ssrAndOptimizeDep,
6004
6051
  plugins: [
6052
+ pathTraversalGuardPlugin(),
6005
6053
  hsStaticAssetPlugin(),
6006
6054
  jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
6007
6055
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
@@ -6216,9 +6264,6 @@ var appServerRouteHandler_default = appServerRouteHandler;
6216
6264
  // src/routes/createDevServerRoutes.ts
6217
6265
  import path18 from "path";
6218
6266
  var isProd2 = true;
6219
- var STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(
6220
- (domain2) => `storybook.${domain2}`
6221
- );
6222
6267
  var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
6223
6268
  const devServerApp = Router2();
6224
6269
  const { appViteServer, appWebRoot } = appLocals || {};
@@ -6234,7 +6279,7 @@ var createDevServerRoutes = async (viteServer, appLocals, storybookPort) => {
6234
6279
  (__pathname, req) => STORYBOOK_DOMAINS.includes(req.hostname),
6235
6280
  {
6236
6281
  logLevel: "warn",
6237
- target: `http://localhost:${storybookPort}`
6282
+ target: `http://127.0.0.1:${storybookPort}`
6238
6283
  }
6239
6284
  )
6240
6285
  );
@@ -6429,6 +6474,7 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
6429
6474
  include: ["react", "react-dom", "react-dom/client"]
6430
6475
  },
6431
6476
  plugins: [
6477
+ pathTraversalGuardPlugin(),
6432
6478
  (() => {
6433
6479
  const require2 = createRequire2(import.meta.url);
6434
6480
  return react2({
@@ -7039,6 +7085,8 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
7039
7085
  "dev",
7040
7086
  "-p",
7041
7087
  STORYBOOK_PORT.toString(),
7088
+ "--host",
7089
+ DEV_SERVER_HOST,
7042
7090
  "-c",
7043
7091
  configPath,
7044
7092
  "--quiet",
@@ -7051,7 +7099,8 @@ HubSpot CMS dev server running at ${protocol}://hslocal.net:${PORT}${extraServer
7051
7099
  portalId: authedPortalId.toString(),
7052
7100
  hsEnv: authedEnv,
7053
7101
  hublet: authedHublet,
7054
- WEB_ROOT: path20.join(webRoot2, "components")
7102
+ WEB_ROOT: path20.join(webRoot2, "components"),
7103
+ STORYBOOK_ALLOWED_HOSTS: STORYBOOK_DOMAINS.join(",")
7055
7104
  },
7056
7105
  stdio: "inherit"
7057
7106
  }
@@ -1,7 +1,7 @@
1
1
  // src/storybook/moduleStory.tsx
2
2
  import { useEffect } from "react";
3
3
 
4
- // ../cms-js-internal/dist/types-C8bPIEz4.js
4
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
5
5
  function namespaceModulePropsShape(props) {
6
6
  const {
7
7
  dataQueryResult,
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // ../cms-js-internal/dist/types-C8bPIEz4.js
11
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
12
12
  import path from "path";
13
13
  import { createHash } from "crypto";
14
14
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
@@ -392,8 +392,8 @@ function isStylesheetAsset(staticAsset) {
392
392
  return staticAsset.type === "stylesheet";
393
393
  }
394
394
  var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, TEMPLATE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, removeIndexFromPath, removeIndexOrTrailingJsFromPath, HEALTHCHECKS_ENABLED_DEFAULT, HEALTHCHECKS_STRICT_DEFAULT, BUILD_INFO_PATH, GATES, ENABLED_FEATURES_GATE_MAP, findAllComponentsIn;
395
- var init_types_C8bPIEz4 = __esm({
396
- "../cms-js-internal/dist/types-C8bPIEz4.js"() {
395
+ var init_types_BWI07Ixv = __esm({
396
+ "../cms-js-internal/dist/types-BWI07Ixv.js"() {
397
397
  COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
398
398
  ENTRY_POINTS_PATH = "components/partials/";
399
399
  MODULE_FOLDER_PATH = "components/modules/";
@@ -510,7 +510,6 @@ ${groupEnd}</script>
510
510
  HEALTHCHECKS_STRICT_DEFAULT = false;
511
511
  BUILD_INFO_PATH = "/build-info.json";
512
512
  GATES = [
513
- "CMS:JSRenderer:RemoveMockClientEntryPlugin",
514
513
  "CMS:JSRenderer:AnalyzeCmsModules",
515
514
  "CMS:JSRenderer:StripNullBytes"
516
515
  ];
@@ -595,12 +594,15 @@ __export(dist_exports, {
595
594
  includesHublDataReference: () => includesHublDataReference,
596
595
  isFullHeightPreviewEnabled: () => isFullHeightPreviewEnabled,
597
596
  isLocalUiDisabled: () => isLocalUiDisabled,
597
+ isPathTraversal: () => isPathTraversal,
598
598
  isStorybookStory: () => isStorybookStory,
599
599
  isStylesheetAsset: () => isStylesheetAsset,
600
600
  isUngatedFor: () => isUngatedFor,
601
601
  jsonStringifyAndEscapeForInlineJS: () => jsonStringifyAndEscapeForInlineJS,
602
602
  namespaceModulePropsShape: () => namespaceModulePropsShape,
603
603
  noncePlaceholderPlugin: () => noncePlaceholderPlugin,
604
+ pathTraversalGuardMiddleware: () => pathTraversalGuardMiddleware,
605
+ pathTraversalGuardPlugin: () => pathTraversalGuardPlugin,
604
606
  removeComponentExtension: () => removeComponentExtension,
605
607
  removeIndexFromPath: () => removeIndexFromPath,
606
608
  removeIndexOrTrailingJsFromPath: () => removeIndexOrTrailingJsFromPath,
@@ -711,6 +713,48 @@ function noncePlaceholderPlugin() {
711
713
  }
712
714
  };
713
715
  }
716
+ function isPathTraversal(url) {
717
+ if (!url)
718
+ return false;
719
+ let decodedUrl;
720
+ try {
721
+ decodedUrl = decodeURI(url);
722
+ } catch {
723
+ return true;
724
+ }
725
+ let [pathname] = decodedUrl.split(/[?#]/);
726
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
727
+ if (hasTraversalSegment(pathname))
728
+ return true;
729
+ let nextPathname;
730
+ try {
731
+ nextPathname = decodeURIComponent(pathname);
732
+ } catch {
733
+ return false;
734
+ }
735
+ if (nextPathname === pathname)
736
+ return false;
737
+ pathname = nextPathname;
738
+ }
739
+ return hasTraversalSegment(pathname);
740
+ }
741
+ function pathTraversalGuardMiddleware(req, res, next) {
742
+ if (isPathTraversal(req.url)) {
743
+ res.statusCode = 403;
744
+ res.end();
745
+ return;
746
+ }
747
+ next();
748
+ }
749
+ function pathTraversalGuardPlugin() {
750
+ return {
751
+ name: "cms-path-traversal-guard",
752
+ apply: "serve",
753
+ configureServer(server) {
754
+ server.middlewares.use(pathTraversalGuardMiddleware);
755
+ }
756
+ };
757
+ }
714
758
  function findCmsModules(buildContentDescriptors = {}) {
715
759
  let config;
716
760
  return {
@@ -1179,11 +1223,11 @@ function GlobalPartialSlot(props) {
1179
1223
  }
1180
1224
  );
1181
1225
  }
1182
- var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, traverse, CMS_MODULE_COMPONENT_NAME, DND_AREA_COMPONENT_NAME, PLUGIN_NAME, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
1226
+ var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, MAX_EXTRA_DECODE_PASSES, hasTraversalSegment, traverse, CMS_MODULE_COMPONENT_NAME, DND_AREA_COMPONENT_NAME, PLUGIN_NAME, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
1183
1227
  var init_dist = __esm({
1184
1228
  "../cms-js-internal/dist/index.js"() {
1185
- init_types_C8bPIEz4();
1186
- init_types_C8bPIEz4();
1229
+ init_types_BWI07Ixv();
1230
+ init_types_BWI07Ixv();
1187
1231
  ({ setProperty, getProperty, hasProperty } = dotProp);
1188
1232
  serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
1189
1233
  const islandsArrayToSerialize = tweakedIslandsArray.map(
@@ -1287,6 +1331,8 @@ ${indentString}`);
1287
1331
  prettyPrint
1288
1332
  )}`;
1289
1333
  };
1334
+ MAX_EXTRA_DECODE_PASSES = 3;
1335
+ hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
1290
1336
  traverse = _traverse.default;
1291
1337
  CMS_MODULE_COMPONENT_NAME = "Module";
1292
1338
  DND_AREA_COMPONENT_NAME = "DndArea";
@@ -1354,6 +1400,7 @@ import { default as react } from "@vitejs/plugin-react";
1354
1400
  var webRoot = process.env.WEB_ROOT;
1355
1401
  var storyPath = path2.resolve(process.cwd(), webRoot, "**/*.stories.*");
1356
1402
  var jsRenderingGates = process.env.GATES ? process.env.GATES.split(",") : [];
1403
+ var allowedHosts = process.env.STORYBOOK_ALLOWED_HOSTS ? process.env.STORYBOOK_ALLOWED_HOSTS.split(",") : [];
1357
1404
  var main_default = {
1358
1405
  addons: ["@storybook/addon-essentials"],
1359
1406
  framework: "@storybook/react-vite",
@@ -1382,6 +1429,9 @@ var main_default = {
1382
1429
  viteFinal: async (config) => {
1383
1430
  const { resolveIslandPlugin: resolveIslandPlugin2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
1384
1431
  const viteConfig = {
1432
+ server: {
1433
+ allowedHosts
1434
+ },
1385
1435
  define: {
1386
1436
  global: "globalThis",
1387
1437
  "process.env": "{}",
@@ -1411,6 +1461,7 @@ var main_default = {
1411
1461
  postcss: webRoot
1412
1462
  },
1413
1463
  plugins: [
1464
+ pathTraversalGuardPlugin(),
1414
1465
  // Provide Node.js globals for browser environment
1415
1466
  {
1416
1467
  name: "provide-nodejs-globals",
@@ -10,7 +10,7 @@ import {
10
10
  import { createRequire } from "module";
11
11
  import { default as react } from "@vitejs/plugin-react";
12
12
 
13
- // ../cms-js-internal/dist/types-C8bPIEz4.js
13
+ // ../cms-js-internal/dist/types-BWI07Ixv.js
14
14
  import path from "path";
15
15
  import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
16
16
  import { join } from "path/posix";
@@ -199,6 +199,50 @@ function noncePlaceholderPlugin() {
199
199
  }
200
200
  };
201
201
  }
202
+ var MAX_EXTRA_DECODE_PASSES = 3;
203
+ var hasTraversalSegment = (pathname) => pathname.split(/[/\\]/).includes("..");
204
+ function isPathTraversal(url2) {
205
+ if (!url2)
206
+ return false;
207
+ let decodedUrl;
208
+ try {
209
+ decodedUrl = decodeURI(url2);
210
+ } catch {
211
+ return true;
212
+ }
213
+ let [pathname] = decodedUrl.split(/[?#]/);
214
+ for (let pass = 0; pass < MAX_EXTRA_DECODE_PASSES; pass++) {
215
+ if (hasTraversalSegment(pathname))
216
+ return true;
217
+ let nextPathname;
218
+ try {
219
+ nextPathname = decodeURIComponent(pathname);
220
+ } catch {
221
+ return false;
222
+ }
223
+ if (nextPathname === pathname)
224
+ return false;
225
+ pathname = nextPathname;
226
+ }
227
+ return hasTraversalSegment(pathname);
228
+ }
229
+ function pathTraversalGuardMiddleware(req, res, next) {
230
+ if (isPathTraversal(req.url)) {
231
+ res.statusCode = 403;
232
+ res.end();
233
+ return;
234
+ }
235
+ next();
236
+ }
237
+ function pathTraversalGuardPlugin() {
238
+ return {
239
+ name: "cms-path-traversal-guard",
240
+ apply: "serve",
241
+ configureServer(server) {
242
+ server.middlewares.use(pathTraversalGuardMiddleware);
243
+ }
244
+ };
245
+ }
202
246
  var traverse = _traverse.default;
203
247
  var {
204
248
  createServerRenderContextV2: createServerRenderContextV22,
@@ -750,6 +794,7 @@ async function forEachModule(projectRoot, moduleName, run) {
750
794
  dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
751
795
  },
752
796
  plugins: [
797
+ pathTraversalGuardPlugin(),
753
798
  react({
754
799
  babel: {
755
800
  plugins: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.2.84",
3
+ "version": "1.2.86",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
31
  "@babel/types": "^7.25.2",
32
- "@hubspot/cms-components": "^1.2.84",
32
+ "@hubspot/cms-components": "^1.2.86",
33
33
  "@hubspot/local-dev-lib": "5.15.0",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -60,7 +60,7 @@
60
60
  "cors": "^2.8.5",
61
61
  "debug": "^4.3.4",
62
62
  "dot-prop": "^9.0.0",
63
- "express": "^4.17.3",
63
+ "express": "^4.22.3",
64
64
  "findup-sync": "5.0.0",
65
65
  "html-escaper": "^3.0.3",
66
66
  "http-proxy-middleware": "^2.0.6",
@@ -0,0 +1,8 @@
1
+ export declare function debugAuthContext(
2
+ authedPortalId: number,
3
+ cookieValue: string
4
+ ): Promise<void>;
5
+ export declare function compareUrls(
6
+ originalUrl: string,
7
+ signedUrl: string
8
+ ): void;
@@ -0,0 +1,2 @@
1
+ export declare function getLocalComponentsPath(): string;
2
+ export declare function shouldUseLocalComponents(): boolean;
@@ -0,0 +1,18 @@
1
+ import { ViteDevServer } from 'vite';
2
+ /**
3
+ * Processes HTML to find remote assets and replace with Vite-managed URLs
4
+ */
5
+ export declare function processRemoteAssets(
6
+ html: string,
7
+ viteServer: ViteDevServer
8
+ ): Promise<string>;
9
+ /**
10
+ * Vite plugin to handle remote assets
11
+ */
12
+ export declare function remoteAssetsPlugin(): {
13
+ name: string;
14
+ apply: 'serve';
15
+ configResolved(config: any): void;
16
+ resolveId(id: string): string;
17
+ load(id: string): Promise<string>;
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function hubspotStaticAssetsPlugin(): Plugin;
@@ -0,0 +1,10 @@
1
+ import { ViteDevServer, Plugin } from 'vite';
2
+ /**
3
+ * Create a self-contained plugin with proper caching
4
+ */
5
+ export declare function remoteAssetsPlugin(): Plugin & {
6
+ processRemoteAssets: (
7
+ html: string,
8
+ viteServer: ViteDevServer
9
+ ) => Promise<string>;
10
+ };
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Plugin that provides URL signing capabilities
4
+ * Uses internal signing mechanisms when available, with fallback for public environments
5
+ */
6
+ export default function requestSigningPlugin(): Plugin;
@@ -1 +1,2 @@
1
1
  export declare const VALID_PROXY_DOMAIN_SUFFIXES: string[];
2
+ export declare const STORYBOOK_DOMAINS: string[];
@@ -0,0 +1,13 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare function handleGetModulePages(
3
+ req: Request,
4
+ res: Response,
5
+ next: NextFunction
6
+ ): Promise<Response<any, Record<string, any>>>;
7
+ export declare function handleOpenFile(
8
+ req: Request,
9
+ res: Response,
10
+ next: NextFunction
11
+ ): Response<any, Record<string, any>>;
12
+ export declare function createAppServerRoutes(): import('express-serve-static-core').Router;
13
+ export default createAppServerRoutes;
@@ -0,0 +1,7 @@
1
+ import { Request, Response } from 'express';
2
+ declare const homeRouteHandler: (
3
+ request: Request,
4
+ response: Response,
5
+ next: Function
6
+ ) => Promise<void>;
7
+ export default homeRouteHandler;