@adobe/helix-html-pipeline 3.0.0 → 3.0.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 +7 -0
- package/package.json +1 -1
- package/src/forms-pipe.js +5 -0
- package/src/json-pipe.js +2 -0
- package/src/steps/authenticate.js +8 -3
- package/src/utils/auth.js +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.0.1](https://github.com/adobe/helix-html-pipeline/compare/v3.0.0...v3.0.1) (2022-06-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* handle xfh properly and protect forms and json pipeline ([#83](https://github.com/adobe/helix-html-pipeline/issues/83)) ([9c13419](https://github.com/adobe/helix-html-pipeline/commit/9c1341987549fbc721a7d1bce12fe537a6f8c5ba))
|
|
7
|
+
|
|
1
8
|
# [3.0.0](https://github.com/adobe/helix-html-pipeline/compare/v2.1.2...v3.0.0) (2022-06-14)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/forms-pipe.js
CHANGED
|
@@ -13,6 +13,7 @@ import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
|
|
|
13
13
|
import { PipelineResponse } from './PipelineResponse.js';
|
|
14
14
|
import fetchConfigAll from './steps/fetch-config-all.js';
|
|
15
15
|
import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
|
|
16
|
+
import { authenticate } from './steps/authenticate.js';
|
|
16
17
|
|
|
17
18
|
function error(log, msg, status, response) {
|
|
18
19
|
log.error(msg);
|
|
@@ -96,6 +97,10 @@ export async function formsPipe(state, request) {
|
|
|
96
97
|
},
|
|
97
98
|
});
|
|
98
99
|
await fetchConfigAll(state, request, response);
|
|
100
|
+
await authenticate(state, request, response);
|
|
101
|
+
if (response.error) {
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
99
104
|
await setCustomResponseHeaders(state, request, response);
|
|
100
105
|
|
|
101
106
|
const {
|
package/src/json-pipe.js
CHANGED
|
@@ -14,6 +14,7 @@ import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
|
|
|
14
14
|
import { PipelineResponse } from './PipelineResponse.js';
|
|
15
15
|
import jsonFilter from './utils/json-filter.js';
|
|
16
16
|
import { extractLastModified, updateLastModified } from './utils/last-modified.js';
|
|
17
|
+
import { authenticate } from './steps/authenticate.js';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Runs the default pipeline and returns the response.
|
|
@@ -80,6 +81,7 @@ export async function jsonPipe(state, req) {
|
|
|
80
81
|
|
|
81
82
|
// Load config-all and set response headers
|
|
82
83
|
await fetchConfigAll(state, req, response);
|
|
84
|
+
await authenticate(state, req, response);
|
|
83
85
|
await setCustomResponseHeaders(state, req, response);
|
|
84
86
|
|
|
85
87
|
return response;
|
|
@@ -37,7 +37,7 @@ export function isAllowed(email = '', allows = []) {
|
|
|
37
37
|
*/
|
|
38
38
|
export async function authenticate(state, req, res) {
|
|
39
39
|
// get auth info
|
|
40
|
-
const authInfo = await getAuthInfo(state, req
|
|
40
|
+
const authInfo = await getAuthInfo(state, req);
|
|
41
41
|
|
|
42
42
|
// check if `.auth` route to validate and exchange token
|
|
43
43
|
if (state.info.path === '/.auth') {
|
|
@@ -52,12 +52,17 @@ export async function authenticate(state, req, res) {
|
|
|
52
52
|
|
|
53
53
|
// if not authenticated, redirect to login screen
|
|
54
54
|
if (!authInfo.authenticated) {
|
|
55
|
+
// send 401 for plain requests
|
|
56
|
+
if (state.info.selector || state.type !== 'html') {
|
|
57
|
+
state.log.warn('[auth] unauthorized. redirect to login only for extension less html.');
|
|
58
|
+
res.status = 401;
|
|
59
|
+
res.error = 'unauthorized.';
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
55
62
|
authInfo.redirectToLogin(state, req, res);
|
|
56
63
|
return;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
// console.log(authInfo.profile);
|
|
60
|
-
|
|
61
66
|
// check profile is allowed
|
|
62
67
|
const { allow } = state.config.access;
|
|
63
68
|
const allows = Array.isArray(allow) ? allow : [allow];
|
package/src/utils/auth.js
CHANGED
|
@@ -150,7 +150,19 @@ export class AuthInfo {
|
|
|
150
150
|
|
|
151
151
|
// determine the location of 'this' document based on the xfh header. so that logins to
|
|
152
152
|
// .page stay on .page. etc. but fallback to the config.host if non set
|
|
153
|
-
|
|
153
|
+
let host = req.headers.get('x-forwarded-host');
|
|
154
|
+
if (host) {
|
|
155
|
+
host = host.split(',')[0].trim();
|
|
156
|
+
}
|
|
157
|
+
if (!host) {
|
|
158
|
+
host = state.config.host;
|
|
159
|
+
}
|
|
160
|
+
if (!host) {
|
|
161
|
+
log.error('[auth] unable to create login redirect: no xfh or config.host.');
|
|
162
|
+
res.status = 401;
|
|
163
|
+
res.error = 'no host information.';
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
154
166
|
|
|
155
167
|
const url = new URL(idp.discovery.authorization_endpoint);
|
|
156
168
|
|