@adobe/helix-config 3.11.1 → 3.12.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.12.0](https://github.com/adobe/helix-config/compare/v3.11.1...v3.12.0) (2024-07-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * enforce original-site for admin config ([#157](https://github.com/adobe/helix-config/issues/157)) ([366328f](https://github.com/adobe/helix-config/commit/366328f8a918341d61239b7d32205eea1fa09f02))
7
+
1
8
  ## [3.11.1](https://github.com/adobe/helix-config/compare/v3.11.0...v3.11.1) (2024-07-29)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "3.11.1",
3
+ "version": "3.12.0",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "eslint": "8.57.0",
47
47
  "husky": "9.1.3",
48
48
  "json-schema-to-typescript": "15.0.0",
49
- "junit-report-builder": "3.2.1",
49
+ "junit-report-builder": "4.0.0",
50
50
  "lint-staged": "15.2.7",
51
51
  "mocha": "10.7.0",
52
52
  "mocha-multi-reporters": "1.5.1",
@@ -185,6 +185,23 @@ async function loadMetadata(ctx, config, partition) {
185
185
  };
186
186
  }
187
187
 
188
+ /**
189
+ * loads the original site information from the `.hlx.json` file
190
+ * @param ctx the context
191
+ * @param contentBusId the content bus id
192
+ * @returns {Promise<string>} the original site.
193
+ */
194
+ async function fetchOriginalSite(ctx, contentBusId) {
195
+ const key = `${contentBusId}/.hlx.json`;
196
+ const res = await ctx.loader.getObject(HELIX_CONTENT_BUS, key);
197
+ if (res.body) {
198
+ const json = res.json();
199
+ return json['original-site'] || json['original-repository'] || '';
200
+ }
201
+ ctx.log.error(`failed to load ${key}: ${res.status}`);
202
+ return '';
203
+ }
204
+
188
205
  async function loadHeadHtml(ctx, config, ref) {
189
206
  const key = `${config.code.owner}/${config.code.repo}/${ref}/head.html`;
190
207
  const res = await ctx.loader.getObject(HELIX_CODE_BUS, key);
@@ -387,6 +404,24 @@ export async function getConfigResponse(ctx, opts) {
387
404
  },
388
405
  });
389
406
  }
407
+ // validate original-site
408
+ if (!config.legacy) {
409
+ const originalSite = await fetchOriginalSite(ctx, config.content.contentBusId);
410
+ if (originalSite && originalSite !== `${org}/${site}`) {
411
+ ctx.log.error(`original site ${originalSite} does not match requested ${org}/${site}.`);
412
+ if (scope === SCOPE_ADMIN) {
413
+ return new PipelineResponse('', {
414
+ status: 403,
415
+ headers: {
416
+ 'x-error': 'original site mismatch',
417
+ ...surrogateHeaders,
418
+ },
419
+ });
420
+ }
421
+ // todo: also send 403 for all scopes....but first observe only
422
+ }
423
+ }
424
+
390
425
  if (config.extends && scope !== SCOPE_RAW) {
391
426
  delete config.extends;
392
427
  }