@adobe/helix-html-pipeline 3.4.6 → 3.5.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.5.0](https://github.com/adobe/helix-html-pipeline/compare/v3.4.6...v3.5.0) (2022-10-26)
2
+
3
+
4
+ ### Features
5
+
6
+ * respect x-forwarded-proto in auth ([#171](https://github.com/adobe/helix-html-pipeline/issues/171)) ([cae61e1](https://github.com/adobe/helix-html-pipeline/commit/cae61e15f16903bc298c4dd5a4a6f7b1379e5ae5))
7
+
1
8
  ## [3.4.6](https://github.com/adobe/helix-html-pipeline/compare/v3.4.5...v3.4.6) (2022-10-22)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "3.4.6",
3
+ "version": "3.5.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -48,7 +48,7 @@
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.0",
51
+ "jose": "4.10.3",
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",
@@ -81,7 +81,7 @@
81
81
  "@semantic-release/git": "10.0.1",
82
82
  "@semantic-release/npm": "9.0.1",
83
83
  "c8": "7.12.0",
84
- "eslint": "8.25.0",
84
+ "eslint": "8.26.0",
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",
@@ -91,7 +91,7 @@
91
91
  "jsdom": "20.0.1",
92
92
  "junit-report-builder": "3.0.1",
93
93
  "lint-staged": "13.0.3",
94
- "mocha": "10.0.0",
94
+ "mocha": "10.1.0",
95
95
  "mocha-multi-reporters": "1.5.1",
96
96
  "remark-gfm": "3.0.1",
97
97
  "semantic-release": "19.0.5"
package/src/utils/auth.js CHANGED
@@ -79,9 +79,9 @@ export async function decodeIdToken(state, idp, idToken, lenient = false) {
79
79
  *
80
80
  * @param {PipelineState} state
81
81
  * @param {PipelineRequest} req
82
- * @return {string}
82
+ * @returns {{proto: (*|string), host: string}} the request host and protocol.
83
83
  */
84
- function getRequestHost(state, req) {
84
+ function getRequestHostAndProto(state, req) {
85
85
  // determine the location of 'this' document based on the xfh header. so that logins to
86
86
  // .page stay on .page. etc. but fallback to the config.host if non set
87
87
  let host = req.headers.get('x-forwarded-host');
@@ -91,8 +91,12 @@ function getRequestHost(state, req) {
91
91
  if (!host) {
92
92
  host = state.config.host;
93
93
  }
94
- state.log.info(`request host is: ${host}`);
95
- return host;
94
+ const proto = req.headers.get('x-forwarded-proto') || 'https';
95
+ state.log.info(`request host is: ${host} (${proto})`);
96
+ return {
97
+ host,
98
+ proto,
99
+ };
96
100
  }
97
101
 
98
102
  /**
@@ -181,7 +185,7 @@ export class AuthInfo {
181
185
 
182
186
  // determine the location of 'this' document based on the xfh header. so that logins to
183
187
  // .page stay on .page. etc. but fallback to the config.host if non set
184
- const host = getRequestHost(state, req);
188
+ const { host, proto } = getRequestHostAndProto(state, req);
185
189
  if (!host) {
186
190
  log.error('[auth] unable to create login redirect: no xfh or config.host.');
187
191
  res.status = 401;
@@ -199,6 +203,7 @@ export class AuthInfo {
199
203
  // this is our own login redirect, i.e. the current document
200
204
  requestPath: state.info.path,
201
205
  requestHost: host,
206
+ requestProto: proto,
202
207
  }).encode();
203
208
 
204
209
  url.searchParams.append('client_id', clientId);
@@ -239,9 +244,9 @@ export class AuthInfo {
239
244
 
240
245
  // ensure that the request is made to the target host
241
246
  if (req.params.state?.requestHost) {
242
- const host = getRequestHost(state, req);
247
+ const { host } = getRequestHostAndProto(state, req);
243
248
  if (host !== req.params.state.requestHost) {
244
- const url = new URL(`https://${req.params.state.requestHost}/.auth`);
249
+ const url = new URL(`${req.params.state.requestProto}://${req.params.state.requestHost}/.auth`);
245
250
  url.searchParams.append('state', req.params.rawState);
246
251
  url.searchParams.append('code', req.params.code);
247
252
  const location = state.createExternalLocation(url.href);