pre release
This commit is contained in:
1 parent
66cd208b61
commit
89d85b4369
13 files changed
+532
-84
No files matched your search
+47
-2
@@ -1,5 +1,6 @@
|
||||
// Express alkalmazás konfiguráció
|
||||
import express from 'express';
|
||||
import helmet from 'helmet';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import { createRouter } from './routes/index.js';
|
||||
@@ -11,24 +12,68 @@ const app = express();
|
||||
// Nginx proxy mögött a valódi kliens IP-t az X-Forwarded-For fejlécből veszi
|
||||
app.set('trust proxy', 1);
|
||||
|
||||
// Express verzió fejléc elrejtése (ne áruljuk el a stacket)
|
||||
app.disable('x-powered-by');
|
||||
|
||||
// Biztonsági fejlécek (CSP, nosniff, frame védelem stb.)
|
||||
app.use(helmet({
|
||||
contentSecurityPolicy: {
|
||||
directives: {
|
||||
defaultSrc: ["'self'"],
|
||||
// A Tailwind build inline stílusokat is használhat
|
||||
styleSrc: ["'self'", "'unsafe-inline'"],
|
||||
scriptSrc: ["'self'"],
|
||||
// Socket.io WebSocket ugyanarról a hostról
|
||||
connectSrc: ["'self'"],
|
||||
imgSrc: ["'self'", 'data:'],
|
||||
objectSrc: ["'none'"],
|
||||
frameAncestors: ["'none'"],
|
||||
baseUri: ["'self'"]
|
||||
}
|
||||
},
|
||||
// A webhook API-t más domainről is hívhatják, ne blokkolja a COEP
|
||||
crossOriginEmbedderPolicy: false,
|
||||
crossOriginResourcePolicy: { policy: 'cross-origin' }
|
||||
}));
|
||||
|
||||
// JSON és form body parser (webhook payloadokhoz)
|
||||
app.use(express.json({ limit: '1mb' }));
|
||||
app.use(express.urlencoded({ extended: true, limit: '1mb' }));
|
||||
|
||||
// Nyers body maximum mérete DoS ellen (1MB) - a json/urlencoded parserrel egyezik
|
||||
const RAW_BODY_LIMIT = 1024 * 1024;
|
||||
|
||||
// Nyers body mentése más content-type esetén (pl. text/plain, application/xml)
|
||||
app.use((req, _res, next) => {
|
||||
app.use((req, res, next) => {
|
||||
const ct = req.headers['content-type'] || '';
|
||||
// Ha már parseolta az express (json/urlencoded), nem kell külön
|
||||
if (ct.includes('application/json') || ct.includes('application/x-www-form-urlencoded')) {
|
||||
return next();
|
||||
}
|
||||
let raw = '';
|
||||
let size = 0;
|
||||
let aborted = false;
|
||||
req.setEncoding('utf8');
|
||||
req.on('data', chunk => { raw += chunk; });
|
||||
req.on('data', chunk => {
|
||||
if (aborted) return;
|
||||
size += Buffer.byteLength(chunk);
|
||||
// Méretkorlát túllépése: elvágjuk a kapcsolatot, hogy ne fogyjon a memória
|
||||
if (size > RAW_BODY_LIMIT) {
|
||||
aborted = true;
|
||||
res.status(413).json({ error: 'A kérés törzse túl nagy (max 1MB).' });
|
||||
req.destroy();
|
||||
return;
|
||||
}
|
||||
raw += chunk;
|
||||
});
|
||||
req.on('end', () => {
|
||||
if (aborted) return;
|
||||
req.rawBody = raw;
|
||||
next();
|
||||
});
|
||||
req.on('error', () => {
|
||||
if (!aborted) next();
|
||||
});
|
||||
});
|
||||
|
||||
// Statikus fájlok kiszolgálása (Vite build output)
|
||||
|
||||
Reference in new issue
Block a user