Apple-Profil-Link: Token als Query-Parameter
Some checks failed
CI / test (push) Has been cancelled
CI / e2e (push) Has been cancelled

Fastify begrenzt Pfadparameter auf 100 Zeichen (FST_ERR_MAX_PARAM_LENGTH, 414);
das Token ist ~140 Zeichen lang.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude (KI) 2026-10-16 11:59:32 +02:00
parent 0f7cfc2024
commit 1bd76bb5ae

View file

@ -24,7 +24,7 @@ const PROFILE_TTL_SEC = 24 * 3600;
const profileSig = (body: string) => createHmac('sha256', config.secretKey).update(`mail-profile:${body}`).digest('base64url');
const profileLink = (resourceId: string, childId: string, protocol: string) => {
const body = Buffer.from(JSON.stringify({ r: resourceId, c: childId, p: protocol, x: Math.floor(Date.now() / 1000) + PROFILE_TTL_SEC })).toString('base64url');
return `${config.baseUrl}/api/mail-profile/${body}.${profileSig(body)}`;
return `${config.baseUrl}/api/mail-profile?t=${body}.${profileSig(body)}`; // Query statt Pfad: Fastify begrenzt Pfadparameter auf 100 Zeichen
};
function readProfileToken(token: string): { r: string; c: string; p: 'imap' | 'pop3' } | null {
const [body, sig] = token.split('.'); if (!body || !sig) return null;
@ -266,8 +266,8 @@ export const resourcesModule: KcModule = {
} catch (e) { return providerError(e); }
});
/** Öffentlich (Token statt Anmeldung): holt das Apple-Profil beim Anbieter und liefert es per https aus. */
app.get('/mail-profile/:token', { config: rl(30, '1 minute') }, async (req, reply) => {
const { token } = z.object({ token: z.string().min(10).max(600) }).parse(req.params);
app.get('/mail-profile', { config: rl(30, '1 minute') }, async (req, reply) => {
const { t: token } = z.object({ t: z.string().min(10).max(600) }).parse(req.query);
const t = readProfileToken(token); if (!t) throw new AppError(404, 'LINK_INVALID', 'Der Link ist ungültig oder abgelaufen. Bitte die Verbindungsdaten im Kundencenter neu öffnen.');
const r = await loadResource(t.r);
if (!r || !r.enabled || !childCaps(r).includes('children.read')) throw notFound();