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.
- package/index.js +14 -7
- 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
|
-
// 🛡️
|
|
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
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
// ==========================================
|
|
86
|
+
// 🛡️ THE FIX: Strict Header Priority (Bearer overrides Cookies)
|
|
87
|
+
// ==========================================
|
|
88
|
+
let token = null;
|
|
88
89
|
|
|
89
|
-
|
|
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 (
|
|
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
|
-
// 🛡️
|
|
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') {
|