-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnext-app.ts
58 lines (51 loc) · 1.61 KB
/
next-app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { createServer } from 'http';
import { parse } from 'url';
import next from 'next';
import path from 'path';
import crypto from 'crypto';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
// Beyaz liste: İzin verilen dosyalar ve yollar
const whitelistFiles = [
'server.ts',
'data.ts',
'package.json',
'tsconfig.json',
'components.json',
'.swcrc',
'next.config.ts',
'vite.config.ts',
'middleware.ts',
'./src/**/*.{js,ts,jsx,tsx}'
];
// Fonksiyon: Parametreleri şifreleme (SHA-384, SHA-256, SHA-512)
function encryptParam(param: string): string {
const sha384Hash = crypto.createHash('sha384').update(param).digest('hex');
const sha256Hash = crypto.createHash('sha256').update(sha384Hash).digest('hex');
const sha512Hash = crypto.createHash('sha512').update(sha256Hash).digest('hex');
return sha512Hash;
}
// Beyaz liste kontrol fonksiyonu
function isWhitelisted(pathname: string): boolean {
const normalizedPath = path.normalize(pathname);
return whitelistFiles.some((pattern) => normalizedPath.startsWith(pattern));
}
app.prepare().then(() => {
createServer(async (req, res) => {
const parsedUrl = parse(req.url!, true);
const { pathname } = parsedUrl;
if (!isWhitelisted(pathname!)) {
res.statusCode = 403; // Erişim engellendi
res.end('Forbidden: İzin verilmeyen dosya isteği.');
return;
}
await handle(req, res, parsedUrl);
}).listen(3001, (err?: Error) => {
if (err) {
console.error(err);
return;
}
console.log('Server is running on port 3001.');
});
});