aip-master-node-sumit 1.0.9 → 1.0.11

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/index.js +14 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -10,7 +10,7 @@ const getSafeMasterUrl = (url) => {
10
10
  return clean;
11
11
  };
12
12
 
13
- // 🛡️ THE FIX: Bulletproof Native Cookie Parser (Handles JWT padding '=')
13
+ // 🛡️ Bulletproof Native Cookie Parser (Handles JWT padding '=')
14
14
  const parseRawCookies = (cookieHeader) => {
15
15
  if (!cookieHeader) return {};
16
16
 
@@ -82,14 +82,21 @@ const aipGuard = (options = { requireLogin: true }) => {
82
82
  return res.status(413).json({ error: "AIP Infrastructure Shield: Payload Too Large." });
83
83
  }
84
84
 
85
- // 🛡️ THE FIX: Smart Cookie Extraction & Removed Vulnerable Query Tokens
86
- const cookies = req.cookies || parseRawCookies(req.headers.cookie);
87
- let token = cookies.aip_session;
85
+ // ==========================================
86
+ // 🛡️ THE FIX: Strict Header Priority (Bearer overrides Cookies)
87
+ // ==========================================
88
+ let token = null;
88
89
 
89
- if (!token && req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) {
90
+ // 1. Check Explicit Headers FIRST
91
+ if (req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) {
90
92
  token = req.headers.authorization.split(' ')[1];
91
- } else if (!token && req.headers['x-aip-token']) {
93
+ } else if (req.headers['x-aip-token']) {
92
94
  token = req.headers['x-aip-token'];
95
+ }
96
+ // 2. Fallback to browser cookies ONLY if no explicit headers exist
97
+ else {
98
+ const cookies = req.cookies || parseRawCookies(req.headers.cookie);
99
+ token = cookies.aip_session;
93
100
  }
94
101
 
95
102
  // ==========================================
@@ -110,7 +117,7 @@ const aipGuard = (options = { requireLogin: true }) => {
110
117
 
111
118
  req.user = authRes.data.user;
112
119
 
113
- // 🛡️ THE FIX: Native Node.js Fallback for Set-Cookie (Framework Agnostic)
120
+ // 🛡️ Native Node.js Fallback for Set-Cookie (Framework Agnostic)
114
121
  const isProd = process.env.NODE_ENV === 'production';
115
122
 
116
123
  if (typeof res.cookie === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aip-master-node-sumit",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Enterprise-grade WAF and IAM security middleware for Node.js.",
5
5
  "main": "index.js",
6
6
  "scripts": {