Skip to content

Commit 78d88ba

Browse files
[TECH] Ajouter des logs spécifiques pour certains tokens problématiques (audience mismatch, revoked token) (PIX-16551)
#11411
2 parents 0497d18 + 2000d5d commit 78d88ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: api/lib/infrastructure/authentication.js

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { revokedUserAccessRepository } from '../../src/identity-access-managemen
55
import { getForwardedOrigin } from '../../src/identity-access-management/infrastructure/utils/network.js';
66
import { config } from '../../src/shared/config.js';
77
import { tokenService } from '../../src/shared/domain/services/token-service.js';
8+
import { monitoringTools } from '../../src/shared/infrastructure/monitoring-tools.js';
89

910
const { find } = lodash;
1011

@@ -88,11 +89,22 @@ async function validateUser(decodedAccessToken, { request, revokedUserAccessRepo
8889
if (config.featureToggles.isUserTokenAudConfinementEnabled && userId) {
8990
const revokedUserAccess = await revokedUserAccessRepository.findByUserId(userId);
9091
if (revokedUserAccess.isAccessTokenRevoked(decodedAccessToken)) {
92+
monitoringTools.logWarnWithCorrelationIds({
93+
message: 'Revoked user AccessToken usage',
94+
decodedAccessToken,
95+
});
96+
9197
return { isValid: false };
9298
}
9399

94100
const audience = getForwardedOrigin(request.headers);
95101
if (decodedAccessToken.aud !== audience) {
102+
monitoringTools.logWarnWithCorrelationIds({
103+
message: 'User AccessToken audience mismatch',
104+
audience,
105+
decodedAccessToken,
106+
});
107+
96108
return { isValid: false };
97109
}
98110
}

Diff for: api/src/identity-access-management/infrastructure/repositories/revoked-user-access.repository.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const revokedUserAccessLifespanMs = config.authentication.revokedUserAccessLifes
1414
* @param {string} params.userId - The ID of the user to revoke access for.
1515
* @param {Date} params.revokeUntil - The date until the user's access should be revoked.
1616
*/
17-
export const saveForUser = async function ({ userId, revokeUntil }) {
17+
const saveForUser = async function ({ userId, revokeUntil }) {
1818
if (!userId) {
1919
throw new UserIdIsRequiredError();
2020
}
@@ -34,7 +34,7 @@ export const saveForUser = async function ({ userId, revokeUntil }) {
3434
* Retrieves the revoked access for a user from the temporary storage.
3535
*
3636
* @param {string} userId - The ID of the user to retrieve the revocation date for.
37-
* @returns {RevokedUserAccess} - The revoked user access object.
37+
* @returns {Promise<RevokedUserAccess>} - The revoked user access object.
3838
*/
3939
const findByUserId = async function (userId) {
4040
const value = await revokedUserAccessTemporaryStorage.get(userId);

0 commit comments

Comments
 (0)