@defra/lis-hubs-infra-access 0.32.0 → 0.33.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/package.json
CHANGED
|
@@ -212,13 +212,11 @@ function createLogoutController({
|
|
|
212
212
|
*
|
|
213
213
|
* @param {object} options - Cookie configuration options.
|
|
214
214
|
* @param {number} options.ttlSeconds - Time to live in seconds for the cookie.
|
|
215
|
-
* @param {boolean} options.isSecure - Whether the cookie should be secure (HTTPS only).
|
|
216
215
|
* @returns {object} Cookie options compatible with Hapi server state configuration.
|
|
217
216
|
*/
|
|
218
|
-
export function createHubCookieOptions({ ttlSeconds
|
|
217
|
+
export function createHubCookieOptions({ ttlSeconds }) {
|
|
219
218
|
return getHubJwtCookieOptions({
|
|
220
|
-
ttlSeconds
|
|
221
|
-
isSecure
|
|
219
|
+
ttlSeconds
|
|
222
220
|
})
|
|
223
221
|
}
|
|
224
222
|
|
|
@@ -13,15 +13,17 @@ function getHubJwtSecret(secret) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {{ ttlSeconds: number
|
|
16
|
+
* @param {{ ttlSeconds: number }} options
|
|
17
17
|
* @returns {object}
|
|
18
18
|
*/
|
|
19
|
-
export function getHubJwtCookieOptions({ ttlSeconds
|
|
19
|
+
export function getHubJwtCookieOptions({ ttlSeconds }) {
|
|
20
20
|
return {
|
|
21
21
|
encoding: 'none',
|
|
22
22
|
ttl: ttlSeconds * MILLISECONDS_PER_SECOND,
|
|
23
23
|
isHttpOnly: true,
|
|
24
|
-
|
|
24
|
+
// Secure is a fixed invariant: the browser always reaches the app over
|
|
25
|
+
// HTTPS (Caddy locally, the CDP edge deployed).
|
|
26
|
+
isSecure: true,
|
|
25
27
|
isSameSite: 'Lax',
|
|
26
28
|
clearInvalid: true,
|
|
27
29
|
path: '/'
|
|
@@ -15,26 +15,30 @@ function normalizeForwardedPrefix(prefix) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
+
* Reduces a requested return URL to a safe, same-origin path. Anything that
|
|
19
|
+
* is not an absolute path on the current origin - absolute URLs, and the
|
|
20
|
+
* protocol-relative "//host" and backslash "/\host" variants that browsers
|
|
21
|
+
* resolve off-site - collapses to "/".
|
|
18
22
|
* @param {string} value
|
|
19
23
|
* @returns {string}
|
|
20
24
|
*/
|
|
21
25
|
export function sanitizeReturnUrl(value) {
|
|
22
|
-
if (!value) {
|
|
26
|
+
if (typeof value !== 'string' || !value.startsWith('/')) {
|
|
23
27
|
return '/'
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
if (value.startsWith('/') && !value.startsWith('//')) {
|
|
27
|
-
return value
|
|
28
|
-
}
|
|
29
|
-
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// Resolve against a throwaway origin; the WHATWG parser normalises
|
|
32
|
+
// backslashes exactly as browsers do, so any off-site target changes the
|
|
33
|
+
// origin and is rejected.
|
|
34
|
+
const base = 'https://x.invalid'
|
|
35
|
+
const { origin, pathname, search, hash } = new URL(value, base)
|
|
36
|
+
|
|
37
|
+
if (origin === base) {
|
|
38
|
+
return `${pathname}${search}${hash}`
|
|
35
39
|
}
|
|
36
40
|
} catch {
|
|
37
|
-
|
|
41
|
+
// Not parseable - fall through to the safe default.
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
return '/'
|