init
This commit is contained in:
@@ -10,7 +10,6 @@ import { authMiddleware } from './middleware/auth';
|
||||
import { csrfMiddleware } from './middleware/csrf';
|
||||
import { globalLimiter, mutateLimiter, sensitiveLimiter, mnemonicRevealLimiter } from './middleware/rate-limit';
|
||||
import { errorHandler } from './middleware/error-handler';
|
||||
import { generateCsrfToken } from './services/csrf.service';
|
||||
import walletRoutes from './routes/wallet.routes';
|
||||
import relayProxyRoutes from './routes/relay-proxy.routes';
|
||||
import jumperProxyRoutes from './routes/jumper-proxy.routes';
|
||||
@@ -67,30 +66,6 @@ app.get('/api/health', async (_req, res) => {
|
||||
// ── Глобальный rate limit на /api/* — ДО docs чтобы не было unauthenticated DoS на swagger.json
|
||||
app.use('/api', globalLimiter);
|
||||
|
||||
app.get('/api/csrf', (_req, res) => {
|
||||
if (!env.vault.csrfPath) {
|
||||
res.json({ success: true, data: { enabled: false, csrfToken: null } });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { token, maxAgeSec } = generateCsrfToken();
|
||||
const crossSiteCookie = !corsIsWildcard && env.cors.allowCredentials;
|
||||
res.cookie('csrf_token', token, {
|
||||
httpOnly: false,
|
||||
secure: crossSiteCookie,
|
||||
sameSite: crossSiteCookie ? 'none' : 'lax',
|
||||
maxAge: maxAgeSec * 1000,
|
||||
path: '/',
|
||||
});
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
res.setHeader('X-CSRF-Token', token);
|
||||
res.json({ success: true, data: { enabled: true, csrfToken: token, maxAgeSec } });
|
||||
} catch (err: any) {
|
||||
res.status(503).json({ success: false, error: err.message || 'CSRF token unavailable' });
|
||||
}
|
||||
});
|
||||
|
||||
// H1 — Swagger gated. В production требуется basic-auth ИЛИ NODE_ENV != production.
|
||||
// JSON endpoint ОБЯЗАТЕЛЬНО до app.use('/api/docs', ...) — иначе swagger-ui-express
|
||||
// перехватывает все /api/docs/* и возвращает HTML вместо JSON.
|
||||
|
||||
Reference in New Issue
Block a user