mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { All, Controller, Param, Req, Res } from '@nestjs/common';
|
||||
import { EntityManager } from '@mikro-orm/core';
|
||||
import type { Request, Response } from 'express';
|
||||
import { UserSessions } from '../../db/entities/UserSessions.entity';
|
||||
import { Users } from '../../db/entities/Users.entity';
|
||||
import { extractToken, verifyJwtAndLoadUser } from '../auth-core/jwt-verify';
|
||||
import { Public } from '../auth-core/public.decorator';
|
||||
import { pluginsEnabled } from './kill-switch';
|
||||
import { PluginRuntimeService } from './plugin-runtime.service';
|
||||
import { Public } from '../auth-core/public.decorator';
|
||||
import { Users } from '../../db/entities/Users.entity';
|
||||
import { UserSessions } from '../../db/entities/UserSessions.entity';
|
||||
import { EntityManager } from '@mikro-orm/core';
|
||||
import { All, Controller, Param, Req, Res } from '@nestjs/common';
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
/**
|
||||
* Proxies a plugin's own HTTP routes at /api/plugins/:id/* (#plugins, M2).
|
||||
@@ -33,12 +34,24 @@ const SAFE_RESPONSE_HEADERS = new Set(['content-type', 'cache-control']);
|
||||
// so a forwarded header can never leak a TREK session or be replayed. Signature +
|
||||
// event headers from the common providers (GitHub/Stripe/Svix/GitLab/generic) pass.
|
||||
const SAFE_INBOUND_HEADERS = new Set([
|
||||
'content-type', 'user-agent', 'x-request-id', 'x-idempotency-key',
|
||||
'x-hub-signature', 'x-hub-signature-256', 'x-github-event', 'x-github-delivery',
|
||||
'content-type',
|
||||
'user-agent',
|
||||
'x-request-id',
|
||||
'x-idempotency-key',
|
||||
'x-hub-signature',
|
||||
'x-hub-signature-256',
|
||||
'x-github-event',
|
||||
'x-github-delivery',
|
||||
'stripe-signature',
|
||||
'svix-id', 'svix-timestamp', 'svix-signature',
|
||||
'x-gitlab-event', 'x-gitlab-token',
|
||||
'x-signature', 'x-signature-256', 'x-webhook-signature', 'x-event-type',
|
||||
'svix-id',
|
||||
'svix-timestamp',
|
||||
'svix-signature',
|
||||
'x-gitlab-event',
|
||||
'x-gitlab-token',
|
||||
'x-signature',
|
||||
'x-signature-256',
|
||||
'x-webhook-signature',
|
||||
'x-event-type',
|
||||
]);
|
||||
|
||||
function pickInboundHeaders(raw: Record<string, unknown> | undefined): Record<string, string> {
|
||||
@@ -103,7 +116,9 @@ export class PluginsProxyController {
|
||||
let user: { id: number; username: string; role?: 'admin' | 'user' } | null = null;
|
||||
if (route.auth) {
|
||||
const token = extractToken(req);
|
||||
const loaded = token ? await verifyJwtAndLoadUser(token, this.em.getRepository(Users), this.em.getRepository(UserSessions)) : null;
|
||||
const loaded = token
|
||||
? await verifyJwtAndLoadUser(token, this.em.getRepository(Users), this.em.getRepository(UserSessions))
|
||||
: null;
|
||||
if (!loaded) {
|
||||
res.status(401).json({ error: 'Access token required', code: 'AUTH_REQUIRED' });
|
||||
return;
|
||||
@@ -126,7 +141,8 @@ export class PluginsProxyController {
|
||||
// so a non-UTF-8 signed body survives) — the plugin decodes and verifies a
|
||||
// provider's HMAC over the exact payload; the parsed JSON can't be
|
||||
// re-serialised identically.
|
||||
rawBodyBase64: route.auth === false ? ((req as { rawBody?: Buffer }).rawBody?.toString('base64') ?? null) : undefined,
|
||||
rawBodyBase64:
|
||||
route.auth === false ? ((req as { rawBody?: Buffer }).rawBody?.toString('base64') ?? null) : undefined,
|
||||
// Only auth:false routes (webhooks) get inbound headers, and only the
|
||||
// allowlisted, credential-free subset — an authenticated route never
|
||||
// needs them and must not see even the safe ones.
|
||||
|
||||
Reference in New Issue
Block a user