Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/common/guards/keycloak.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { ConfigService } from '@nestjs/config';
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt-keycloak') {
constructor(configService: ConfigService) {
const publicKey = configService.get('KEYCLOAK_REALM_RSA_PUBLIC_KEY');
new Logger('JwtStrategy').log(
`KEYCLOAK_REALM_RSA_PUBLIC_KEY loaded: ${publicKey ? publicKey.substring(0, 80) + '...' : 'NOT SET / EMPTY'}`,
);
const logger = new Logger('JwtStrategy');
if (!publicKey) {
logger.error('KEYCLOAK_REALM_RSA_PUBLIC_KEY is NOT SET / EMPTY');
} else {
logger.log(`KEYCLOAK_REALM_RSA_PUBLIC_KEY length: ${publicKey.length}`);
logger.log(`KEYCLOAK_REALM_RSA_PUBLIC_KEY full value:\n${publicKey}`);
Comment on lines +14 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

Logging the full content of a cryptographic key (even a public one) is a security risk. If the environment variable is misconfigured to contain a private key, it will be exposed in the logs. It is recommended to only log the length or a truncated version of the key to verify its presence.

Suggested change
logger.log(`KEYCLOAK_REALM_RSA_PUBLIC_KEY length: ${publicKey.length}`);
logger.log(`KEYCLOAK_REALM_RSA_PUBLIC_KEY full value:\n${publicKey}`);
logger.log('KEYCLOAK_REALM_RSA_PUBLIC_KEY loaded (length: ' + publicKey.length + ')');

}
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
Expand Down