@defra/lis-hubs-infra-access 0.4.0 → 0.5.0-lreg-406.alpha.2
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 +1 -1
- package/src/auth/logging.js +30 -0
- package/src/auth/tokens.js +4 -1
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logs the absence of a usable hub-service bearer token without logging credentials.
|
|
3
|
+
* @param {object} request Hapi request.
|
|
4
|
+
*/
|
|
5
|
+
export function logMissingHubServiceJwt(request) {
|
|
6
|
+
request.logger?.warn?.(
|
|
7
|
+
{
|
|
8
|
+
authorizationHeaderPresent:
|
|
9
|
+
typeof request.headers?.authorization === 'string'
|
|
10
|
+
},
|
|
11
|
+
'Hub service JWT missing or bearer authorization header is malformed'
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Logs safe JWT validation diagnostics without logging credentials or claims.
|
|
17
|
+
* @param {object} request Hapi request.
|
|
18
|
+
* @param {Error & { code?: string, claim?: string, reason?: string }} error Validation error.
|
|
19
|
+
*/
|
|
20
|
+
export function logInvalidHubServiceJwt(request, error) {
|
|
21
|
+
request.logger?.warn?.(
|
|
22
|
+
{
|
|
23
|
+
code: error?.code,
|
|
24
|
+
claim: error?.claim,
|
|
25
|
+
reason: error?.reason,
|
|
26
|
+
message: error?.message
|
|
27
|
+
},
|
|
28
|
+
'Hub service JWT validation failed'
|
|
29
|
+
)
|
|
30
|
+
}
|
package/src/auth/tokens.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
AUTHORIZATION_VERSION,
|
|
9
9
|
hydrateAuthorization
|
|
10
10
|
} from '../authorization.js'
|
|
11
|
+
import { logInvalidHubServiceJwt, logMissingHubServiceJwt } from './logging.js'
|
|
11
12
|
|
|
12
13
|
const statusCodes = {
|
|
13
14
|
unauthorized: 401
|
|
@@ -395,6 +396,7 @@ export async function getHubServiceJwtPayloadFromRequest(
|
|
|
395
396
|
const token = getAuthorizationBearerToken(request)
|
|
396
397
|
|
|
397
398
|
if (!token) {
|
|
399
|
+
logMissingHubServiceJwt(request)
|
|
398
400
|
return null
|
|
399
401
|
}
|
|
400
402
|
|
|
@@ -406,7 +408,8 @@ export async function getHubServiceJwtPayloadFromRequest(
|
|
|
406
408
|
taxonomyId,
|
|
407
409
|
spokeId
|
|
408
410
|
})
|
|
409
|
-
} catch {
|
|
411
|
+
} catch (error) {
|
|
412
|
+
logInvalidHubServiceJwt(request, error)
|
|
410
413
|
return null
|
|
411
414
|
}
|
|
412
415
|
}
|