csrf-shield 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app.js +8 -3
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -9,9 +9,7 @@ module.exports = function(options = {}) {
9
9
  // IP'yi en hızlı şekilde alma fonksiyonu
10
10
  // Proxy güvenliği için 'trust proxy' ayarının express'te yapılı olduğunu varsayıyoruz.
11
11
  function getIP(req) {
12
- return req.headers['x-forwarded-for'] ||
13
- req.socket.remoteAddress ||
14
- '';
12
+ return req.headers['cf-connecting-ip'] || req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.socket.remoteAddress || '';
15
13
  }
16
14
 
17
15
  return {
@@ -81,6 +79,13 @@ module.exports = function(options = {}) {
81
79
  const expectedBuf = Buffer.from(expectedSignature);
82
80
 
83
81
  if (signatureBuf.length !== expectedBuf.length || !crypto.timingSafeEqual(signatureBuf, expectedBuf)) {
82
+ console.log('CSRF token mismatch:', {
83
+ received: receivedSignature,
84
+ expected: expectedSignature,
85
+ ip: ip,
86
+ ua: ua
87
+ });
88
+
84
89
  return res.status(403).json({ status: false, message: 'CSRF_TOKEN_INVALID' });
85
90
  }
86
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "csrf-shield",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "CSRF protection middleware for Express.js applications.",
5
5
  "main": "app.js",
6
6
  "scripts": {