Files
paperlessmanager/paperless-backend/src/auth/jwt-optionen.ts
T
bjoernpoettkerandClaude Opus 5.5 c28475f71f fix(security): JWT-Audience gegen OIDC_CLIENT_ID prüfen
Bisher prüfte das Backend nur Issuer und Signatur. Ein Access-Token, das
derselbe Authentik-Provider für eine andere Anwendung ausgestellt hat,
wurde ebenfalls akzeptiert.

- JwtStrategy verlangt aud == OIDC_CLIENT_ID (jwt-optionen.ts, getestet
  mit echten RS256-Tokens). Ohne OIDC_CLIENT_ID bleibt die Prüfung aus,
  mit Warnung beim Start.
- docker-compose.yml übergibt OIDC_CLIENT_ID jetzt ans Backend, Standard:
  dieselbe Client-ID wie das Frontend (VITE_OIDC_CLIENT_ID).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:46:57 +01:00

28 lines
795 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Algorithm } from 'jsonwebtoken';
export interface JwtPruefOptionen {
issuer: string;
/** Client-ID dieser Anwendung; ohne sie wird `aud` nicht geprüft. */
audience?: string;
algorithms: Algorithm[];
jwksUri: string;
}
/**
* Prüfoptionen für Access-Tokens von Authentik. Ohne Audience-Prüfung würde
* jedes Token desselben Issuers akzeptiert – also auch eines, das Authentik
* für eine andere Anwendung mit demselben Provider ausgestellt hat.
*/
export function jwtPruefOptionen(
issuer: string,
clientId: string | undefined,
): JwtPruefOptionen {
const basis = issuer.endsWith('/') ? issuer.slice(0, -1) : issuer;
return {
issuer,
...(clientId ? { audience: clientId } : {}),
algorithms: ['RS256'],
jwksUri: `${basis}/jwks/`,
};
}