@adobe/helix-html-pipeline 3.5.0 → 3.6.1

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,17 @@
1
+ ## [3.6.1](https://github.com/adobe/helix-html-pipeline/compare/v3.6.0...v3.6.1) (2022-10-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * don't rewrite production urls ([#175](https://github.com/adobe/helix-html-pipeline/issues/175)) ([815c154](https://github.com/adobe/helix-html-pipeline/commit/815c1545bc3e6f960ea320dc775e0edcf2bc414c)), closes [#165](https://github.com/adobe/helix-html-pipeline/issues/165)
7
+
8
+ # [3.6.0](https://github.com/adobe/helix-html-pipeline/compare/v3.5.0...v3.6.0) (2022-10-27)
9
+
10
+
11
+ ### Features
12
+
13
+ * also support x-fwd-scheme ([#172](https://github.com/adobe/helix-html-pipeline/issues/172)) ([845a5a0](https://github.com/adobe/helix-html-pipeline/commit/845a5a0dada33a3950ffed4f7d6a52090fa6de9a))
14
+
1
15
  # [3.5.0](https://github.com/adobe/helix-html-pipeline/compare/v3.4.6...v3.5.0) (2022-10-26)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -42,13 +42,13 @@
42
42
  "@adobe/helix-markdown-support": "5.0.10",
43
43
  "@adobe/helix-shared-utils": "2.1.0",
44
44
  "cookie": "0.5.0",
45
- "github-slugger": "1.4.0",
45
+ "github-slugger": "1.5.0",
46
46
  "hast-util-raw": "7.2.2",
47
47
  "hast-util-select": "5.0.2",
48
48
  "hast-util-to-html": "8.0.3",
49
49
  "hast-util-to-string": "2.0.0",
50
50
  "hastscript": "7.1.0",
51
- "jose": "4.10.3",
51
+ "jose": "4.10.4",
52
52
  "mdast-util-gfm-footnote": "1.0.1",
53
53
  "mdast-util-gfm-strikethrough": "1.0.1",
54
54
  "mdast-util-gfm-table": "1.0.6",
@@ -85,7 +85,7 @@
85
85
  "eslint-import-resolver-exports": "1.0.0-beta.3",
86
86
  "eslint-plugin-header": "3.1.1",
87
87
  "eslint-plugin-import": "2.26.0",
88
- "esmock": "2.0.6",
88
+ "esmock": "2.0.7",
89
89
  "husky": "8.0.1",
90
90
  "js-yaml": "4.1.0",
91
91
  "jsdom": "20.0.1",
@@ -175,19 +175,6 @@ export function getAbsoluteUrl(state, url) {
175
175
  return resolveUrl(`https://${state.config.host}/`, url);
176
176
  }
177
177
 
178
- /**
179
- * Checks if the given `str` matches any of the given regs or if `regs` is empty.
180
- * @param {RegExp[]} regs
181
- * @param {string} str
182
- * @returns {boolean} {@code true} if `regs` is empty or if `str` matches any of them.
183
- */
184
- function matchAny(regs, str) {
185
- if (!regs || regs.length === 0) {
186
- return true;
187
- }
188
- return regs.findIndex((r) => r.test(str)) >= 0;
189
- }
190
-
191
178
  /**
192
179
  * Rewrites the media, helix or external url. Returns the original if not rewritten.
193
180
  * @param {PipelineState} state
@@ -198,9 +185,7 @@ export function rewriteUrl(state, url) {
198
185
  if (!url || !url.startsWith('https://')) {
199
186
  return url;
200
187
  }
201
- const {
202
- host, pathname, search, hash,
203
- } = new URL(url);
188
+ const { pathname, search, hash } = new URL(url);
204
189
 
205
190
  if (AZURE_BLOB_REGEXP.test(url)) {
206
191
  const filename = pathname.split('/').pop();
@@ -221,12 +206,5 @@ export function rewriteUrl(state, url) {
221
206
  return `${pathname}${search}${hash}`;
222
207
  }
223
208
 
224
- if (host === state.config?.host && matchAny(state.config.routes, pathname)) {
225
- if (hash && pathname === state.info?.path) {
226
- return hash;
227
- }
228
- return `${pathname}${search}${hash}`;
229
- }
230
-
231
209
  return url;
232
210
  }
@@ -11,21 +11,21 @@
11
11
  */
12
12
  import { parse, serialize } from 'cookie';
13
13
 
14
- export function clearAuthCookie() {
14
+ export function clearAuthCookie(secure) {
15
15
  return serialize('hlx-auth-token', '', {
16
16
  path: '/',
17
17
  httpOnly: true,
18
- secure: true,
18
+ secure,
19
19
  expires: new Date(0),
20
20
  sameSite: 'lax',
21
21
  });
22
22
  }
23
23
 
24
- export function setAuthCookie(idToken) {
24
+ export function setAuthCookie(idToken, secure) {
25
25
  return serialize('hlx-auth-token', idToken, {
26
26
  path: '/',
27
27
  httpOnly: true,
28
- secure: true,
28
+ secure,
29
29
  sameSite: 'lax',
30
30
  });
31
31
  }
package/src/utils/auth.js CHANGED
@@ -91,7 +91,8 @@ function getRequestHostAndProto(state, req) {
91
91
  if (!host) {
92
92
  host = state.config.host;
93
93
  }
94
- const proto = req.headers.get('x-forwarded-proto') || 'https';
94
+ // fastly overrides the x-forwarded-proto, so we use x-forwarded-scheme
95
+ const proto = req.headers.get('x-forwarded-scheme') || req.headers.get('x-forwarded-proto') || 'https';
95
96
  state.log.info(`request host is: ${host} (${proto})`);
96
97
  return {
97
98
  host,
@@ -218,7 +219,7 @@ export class AuthInfo {
218
219
  res.status = 302;
219
220
  res.body = '';
220
221
  res.headers.set('location', url.href);
221
- res.headers.set('set-cookie', clearAuthCookie());
222
+ res.headers.set('set-cookie', clearAuthCookie(proto === 'https'));
222
223
  res.headers.set('cache-control', 'no-store, private, must-revalidate');
223
224
  res.error = 'moved';
224
225
  }
@@ -299,12 +300,12 @@ export class AuthInfo {
299
300
  // ctx.attributes.authInfo?.withCookieInvalid(false);
300
301
 
301
302
  const location = state.createExternalLocation(req.params.state.requestPath || '/');
302
- log.info('[auth] redirecting to home page with id_token cookie', location);
303
+ log.info('[auth] redirecting to original page with hlx-auth-token cookie: ', location);
303
304
  res.status = 302;
304
305
  res.body = `please go to <a href="${location}">${location}</a>`;
305
306
  res.headers.set('location', location);
306
307
  res.headers.set('content-tye', 'text/plain');
307
- res.headers.set('set-cookie', setAuthCookie(idToken));
308
+ res.headers.set('set-cookie', setAuthCookie(idToken, req.params.state.requestProto === 'https'));
308
309
  res.headers.set('cache-control', 'no-store, private, must-revalidate');
309
310
  res.error = 'moved';
310
311
  }