strapi-plugin-magic-sessionmanager 4.2.8 → 4.2.9
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/dist/server/index.js +57 -66
- package/dist/server/index.mjs +57 -66
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -179,7 +179,7 @@ function encryptToken$2(token) {
|
|
|
179
179
|
throw new Error("Failed to encrypt token");
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
function decryptToken$
|
|
182
|
+
function decryptToken$3(encryptedToken) {
|
|
183
183
|
if (!encryptedToken) return null;
|
|
184
184
|
try {
|
|
185
185
|
const key = getEncryptionKey();
|
|
@@ -206,15 +206,20 @@ function generateSessionId$1(userId) {
|
|
|
206
206
|
const userHash = crypto$1.createHash("sha256").update(userId.toString()).digest("hex").substring(0, 8);
|
|
207
207
|
return `sess_${timestamp}_${userHash}_${randomBytes}`;
|
|
208
208
|
}
|
|
209
|
+
function hashToken$3(token) {
|
|
210
|
+
if (!token) return null;
|
|
211
|
+
return crypto$1.createHash("sha256").update(token).digest("hex");
|
|
212
|
+
}
|
|
209
213
|
var encryption = {
|
|
210
214
|
encryptToken: encryptToken$2,
|
|
211
|
-
decryptToken: decryptToken$
|
|
212
|
-
generateSessionId: generateSessionId$1
|
|
215
|
+
decryptToken: decryptToken$3,
|
|
216
|
+
generateSessionId: generateSessionId$1,
|
|
217
|
+
hashToken: hashToken$3
|
|
213
218
|
};
|
|
214
219
|
const SESSION_UID$3 = "plugin::magic-sessionmanager.session";
|
|
215
|
-
const {
|
|
220
|
+
const { hashToken: hashToken$2 } = encryption;
|
|
216
221
|
const lastTouchCache = /* @__PURE__ */ new Map();
|
|
217
|
-
var lastSeen = ({ strapi: strapi2
|
|
222
|
+
var lastSeen = ({ strapi: strapi2 }) => {
|
|
218
223
|
return async (ctx, next) => {
|
|
219
224
|
const currentToken = ctx.request.headers.authorization?.replace("Bearer ", "");
|
|
220
225
|
if (!currentToken) {
|
|
@@ -227,58 +232,26 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
|
|
|
227
232
|
return;
|
|
228
233
|
}
|
|
229
234
|
let matchingSession = null;
|
|
230
|
-
let userId = null;
|
|
231
235
|
try {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (!activeSessions || activeSessions.length === 0) {
|
|
241
|
-
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] User ${userId} has no active sessions`);
|
|
242
|
-
return ctx.unauthorized("All sessions have been terminated. Please login again.");
|
|
243
|
-
}
|
|
244
|
-
for (const session2 of activeSessions) {
|
|
245
|
-
if (!session2.token) continue;
|
|
246
|
-
try {
|
|
247
|
-
const decrypted = decryptToken$3(session2.token);
|
|
248
|
-
if (decrypted === currentToken) {
|
|
249
|
-
matchingSession = session2;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
} catch (err) {
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!matchingSession) {
|
|
256
|
-
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] Session for user ${userId} has been terminated`);
|
|
257
|
-
return ctx.unauthorized("This session has been terminated. Please login again.");
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
const allActiveSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
261
|
-
filters: { isActive: true },
|
|
262
|
-
populate: { user: { fields: ["documentId"] } },
|
|
263
|
-
limit: 500
|
|
264
|
-
// Reasonable limit for performance
|
|
265
|
-
});
|
|
266
|
-
for (const session2 of allActiveSessions) {
|
|
267
|
-
if (!session2.token) continue;
|
|
268
|
-
try {
|
|
269
|
-
const decrypted = decryptToken$3(session2.token);
|
|
270
|
-
if (decrypted === currentToken) {
|
|
271
|
-
matchingSession = session2;
|
|
272
|
-
userId = session2.user?.documentId;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
} catch (err) {
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
236
|
+
const currentTokenHash = hashToken$2(currentToken);
|
|
237
|
+
matchingSession = await strapi2.documents(SESSION_UID$3).findFirst({
|
|
238
|
+
filters: {
|
|
239
|
+
tokenHash: currentTokenHash,
|
|
240
|
+
isActive: true
|
|
241
|
+
},
|
|
242
|
+
populate: { user: { fields: ["documentId"] } }
|
|
243
|
+
});
|
|
279
244
|
if (matchingSession) {
|
|
280
245
|
ctx.state.sessionId = matchingSession.documentId;
|
|
281
246
|
ctx.state.currentSession = matchingSession;
|
|
247
|
+
if (matchingSession.user?.documentId) {
|
|
248
|
+
ctx.state.sessionUserId = matchingSession.user.documentId;
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
if (ctx.state.user && ctx.state.user.documentId) {
|
|
252
|
+
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] Session terminated for user ${ctx.state.user.documentId}`);
|
|
253
|
+
return ctx.unauthorized("This session has been terminated. Please login again.");
|
|
254
|
+
}
|
|
282
255
|
}
|
|
283
256
|
} catch (err) {
|
|
284
257
|
strapi2.log.debug("[magic-sessionmanager] Error checking session:", err.message);
|
|
@@ -305,7 +278,7 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
|
|
|
305
278
|
};
|
|
306
279
|
};
|
|
307
280
|
const getClientIp = getClientIp_1;
|
|
308
|
-
const { encryptToken: encryptToken$1, decryptToken: decryptToken$2 } = encryption;
|
|
281
|
+
const { encryptToken: encryptToken$1, decryptToken: decryptToken$2, hashToken: hashToken$1 } = encryption;
|
|
309
282
|
const { createLogger: createLogger$3 } = logger;
|
|
310
283
|
const SESSION_UID$2 = "plugin::magic-sessionmanager.session";
|
|
311
284
|
const USER_UID$2 = "plugin::users-permissions.user";
|
|
@@ -589,11 +562,15 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
589
562
|
if (matchingSession) {
|
|
590
563
|
const encryptedToken = newAccessToken ? encryptToken$1(newAccessToken) : matchingSession.token;
|
|
591
564
|
const encryptedRefreshToken = newRefreshToken ? encryptToken$1(newRefreshToken) : matchingSession.refreshToken;
|
|
565
|
+
const newTokenHash = newAccessToken ? hashToken$1(newAccessToken) : matchingSession.tokenHash;
|
|
566
|
+
const newRefreshTokenHash = newRefreshToken ? hashToken$1(newRefreshToken) : matchingSession.refreshTokenHash;
|
|
592
567
|
await strapi2.documents(SESSION_UID$2).update({
|
|
593
568
|
documentId: matchingSession.documentId,
|
|
594
569
|
data: {
|
|
595
570
|
token: encryptedToken,
|
|
571
|
+
tokenHash: newTokenHash,
|
|
596
572
|
refreshToken: encryptedRefreshToken,
|
|
573
|
+
refreshTokenHash: newRefreshTokenHash,
|
|
597
574
|
lastActive: /* @__PURE__ */ new Date()
|
|
598
575
|
}
|
|
599
576
|
});
|
|
@@ -607,7 +584,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
607
584
|
});
|
|
608
585
|
log.info("[SUCCESS] Refresh Token interceptor middleware mounted");
|
|
609
586
|
strapi2.server.use(
|
|
610
|
-
lastSeen({ strapi: strapi2
|
|
587
|
+
lastSeen({ strapi: strapi2 })
|
|
611
588
|
);
|
|
612
589
|
log.info("[SUCCESS] LastSeen middleware mounted");
|
|
613
590
|
await ensureContentApiPermissions(strapi2, log);
|
|
@@ -743,10 +720,18 @@ const attributes = {
|
|
|
743
720
|
type: "text",
|
|
744
721
|
"private": true
|
|
745
722
|
},
|
|
723
|
+
tokenHash: {
|
|
724
|
+
type: "string",
|
|
725
|
+
configurable: false
|
|
726
|
+
},
|
|
746
727
|
refreshToken: {
|
|
747
728
|
type: "text",
|
|
748
729
|
"private": true
|
|
749
730
|
},
|
|
731
|
+
refreshTokenHash: {
|
|
732
|
+
type: "string",
|
|
733
|
+
configurable: false
|
|
734
|
+
},
|
|
750
735
|
loginTime: {
|
|
751
736
|
type: "datetime",
|
|
752
737
|
required: true
|
|
@@ -1778,7 +1763,7 @@ var controllers$1 = {
|
|
|
1778
1763
|
license,
|
|
1779
1764
|
settings
|
|
1780
1765
|
};
|
|
1781
|
-
const { encryptToken, decryptToken, generateSessionId } = encryption;
|
|
1766
|
+
const { encryptToken, decryptToken, generateSessionId, hashToken } = encryption;
|
|
1782
1767
|
const { createLogger: createLogger$1 } = logger;
|
|
1783
1768
|
const SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
1784
1769
|
const USER_UID = "plugin::users-permissions.user";
|
|
@@ -1796,6 +1781,8 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1796
1781
|
const sessionId = generateSessionId(userId);
|
|
1797
1782
|
const encryptedToken = token ? encryptToken(token) : null;
|
|
1798
1783
|
const encryptedRefreshToken = refreshToken ? encryptToken(refreshToken) : null;
|
|
1784
|
+
const tokenHashValue = token ? hashToken(token) : null;
|
|
1785
|
+
const refreshTokenHashValue = refreshToken ? hashToken(refreshToken) : null;
|
|
1799
1786
|
const session2 = await strapi2.documents(SESSION_UID).create({
|
|
1800
1787
|
data: {
|
|
1801
1788
|
user: userId,
|
|
@@ -1806,11 +1793,15 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1806
1793
|
lastActive: now,
|
|
1807
1794
|
isActive: true,
|
|
1808
1795
|
token: encryptedToken,
|
|
1809
|
-
//
|
|
1796
|
+
// Encrypted Access Token
|
|
1797
|
+
tokenHash: tokenHashValue,
|
|
1798
|
+
// SHA-256 hash for fast lookup
|
|
1810
1799
|
refreshToken: encryptedRefreshToken,
|
|
1811
|
-
//
|
|
1800
|
+
// Encrypted Refresh Token
|
|
1801
|
+
refreshTokenHash: refreshTokenHashValue,
|
|
1802
|
+
// SHA-256 hash for fast lookup
|
|
1812
1803
|
sessionId
|
|
1813
|
-
//
|
|
1804
|
+
// Unique identifier
|
|
1814
1805
|
}
|
|
1815
1806
|
});
|
|
1816
1807
|
log.info(`[SUCCESS] Session ${session2.documentId} (${sessionId}) created for user ${userId}`);
|
|
@@ -1888,9 +1879,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1888
1879
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1889
1880
|
const timeSinceActive = now - lastActiveTime;
|
|
1890
1881
|
const isTrulyActive = session2.isActive && timeSinceActive < inactivityTimeout;
|
|
1891
|
-
const { token, ...
|
|
1882
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1892
1883
|
return {
|
|
1893
|
-
...
|
|
1884
|
+
...safeSession,
|
|
1894
1885
|
isTrulyActive,
|
|
1895
1886
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1896
1887
|
};
|
|
@@ -1919,9 +1910,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1919
1910
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1920
1911
|
const timeSinceActive = now - lastActiveTime;
|
|
1921
1912
|
const isTrulyActive = timeSinceActive < inactivityTimeout;
|
|
1922
|
-
const { token, ...
|
|
1913
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1923
1914
|
return {
|
|
1924
|
-
...
|
|
1915
|
+
...safeSession,
|
|
1925
1916
|
isTrulyActive,
|
|
1926
1917
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1927
1918
|
};
|
|
@@ -1958,9 +1949,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1958
1949
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1959
1950
|
const timeSinceActive = now - lastActiveTime;
|
|
1960
1951
|
const isTrulyActive = session2.isActive && timeSinceActive < inactivityTimeout;
|
|
1961
|
-
const { token, ...
|
|
1952
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1962
1953
|
return {
|
|
1963
|
-
...
|
|
1954
|
+
...safeSession,
|
|
1964
1955
|
isTrulyActive,
|
|
1965
1956
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1966
1957
|
};
|
|
@@ -2077,7 +2068,7 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
2077
2068
|
}
|
|
2078
2069
|
};
|
|
2079
2070
|
};
|
|
2080
|
-
const version = "4.2.
|
|
2071
|
+
const version = "4.2.8";
|
|
2081
2072
|
const require$$2 = {
|
|
2082
2073
|
version
|
|
2083
2074
|
};
|
package/dist/server/index.mjs
CHANGED
|
@@ -175,7 +175,7 @@ function encryptToken$2(token) {
|
|
|
175
175
|
throw new Error("Failed to encrypt token");
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
function decryptToken$
|
|
178
|
+
function decryptToken$3(encryptedToken) {
|
|
179
179
|
if (!encryptedToken) return null;
|
|
180
180
|
try {
|
|
181
181
|
const key = getEncryptionKey();
|
|
@@ -202,15 +202,20 @@ function generateSessionId$1(userId) {
|
|
|
202
202
|
const userHash = crypto$1.createHash("sha256").update(userId.toString()).digest("hex").substring(0, 8);
|
|
203
203
|
return `sess_${timestamp}_${userHash}_${randomBytes}`;
|
|
204
204
|
}
|
|
205
|
+
function hashToken$3(token) {
|
|
206
|
+
if (!token) return null;
|
|
207
|
+
return crypto$1.createHash("sha256").update(token).digest("hex");
|
|
208
|
+
}
|
|
205
209
|
var encryption = {
|
|
206
210
|
encryptToken: encryptToken$2,
|
|
207
|
-
decryptToken: decryptToken$
|
|
208
|
-
generateSessionId: generateSessionId$1
|
|
211
|
+
decryptToken: decryptToken$3,
|
|
212
|
+
generateSessionId: generateSessionId$1,
|
|
213
|
+
hashToken: hashToken$3
|
|
209
214
|
};
|
|
210
215
|
const SESSION_UID$3 = "plugin::magic-sessionmanager.session";
|
|
211
|
-
const {
|
|
216
|
+
const { hashToken: hashToken$2 } = encryption;
|
|
212
217
|
const lastTouchCache = /* @__PURE__ */ new Map();
|
|
213
|
-
var lastSeen = ({ strapi: strapi2
|
|
218
|
+
var lastSeen = ({ strapi: strapi2 }) => {
|
|
214
219
|
return async (ctx, next) => {
|
|
215
220
|
const currentToken = ctx.request.headers.authorization?.replace("Bearer ", "");
|
|
216
221
|
if (!currentToken) {
|
|
@@ -223,58 +228,26 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
|
|
|
223
228
|
return;
|
|
224
229
|
}
|
|
225
230
|
let matchingSession = null;
|
|
226
|
-
let userId = null;
|
|
227
231
|
try {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (!activeSessions || activeSessions.length === 0) {
|
|
237
|
-
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] User ${userId} has no active sessions`);
|
|
238
|
-
return ctx.unauthorized("All sessions have been terminated. Please login again.");
|
|
239
|
-
}
|
|
240
|
-
for (const session2 of activeSessions) {
|
|
241
|
-
if (!session2.token) continue;
|
|
242
|
-
try {
|
|
243
|
-
const decrypted = decryptToken$3(session2.token);
|
|
244
|
-
if (decrypted === currentToken) {
|
|
245
|
-
matchingSession = session2;
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
} catch (err) {
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (!matchingSession) {
|
|
252
|
-
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] Session for user ${userId} has been terminated`);
|
|
253
|
-
return ctx.unauthorized("This session has been terminated. Please login again.");
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
const allActiveSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
257
|
-
filters: { isActive: true },
|
|
258
|
-
populate: { user: { fields: ["documentId"] } },
|
|
259
|
-
limit: 500
|
|
260
|
-
// Reasonable limit for performance
|
|
261
|
-
});
|
|
262
|
-
for (const session2 of allActiveSessions) {
|
|
263
|
-
if (!session2.token) continue;
|
|
264
|
-
try {
|
|
265
|
-
const decrypted = decryptToken$3(session2.token);
|
|
266
|
-
if (decrypted === currentToken) {
|
|
267
|
-
matchingSession = session2;
|
|
268
|
-
userId = session2.user?.documentId;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
} catch (err) {
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
232
|
+
const currentTokenHash = hashToken$2(currentToken);
|
|
233
|
+
matchingSession = await strapi2.documents(SESSION_UID$3).findFirst({
|
|
234
|
+
filters: {
|
|
235
|
+
tokenHash: currentTokenHash,
|
|
236
|
+
isActive: true
|
|
237
|
+
},
|
|
238
|
+
populate: { user: { fields: ["documentId"] } }
|
|
239
|
+
});
|
|
275
240
|
if (matchingSession) {
|
|
276
241
|
ctx.state.sessionId = matchingSession.documentId;
|
|
277
242
|
ctx.state.currentSession = matchingSession;
|
|
243
|
+
if (matchingSession.user?.documentId) {
|
|
244
|
+
ctx.state.sessionUserId = matchingSession.user.documentId;
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
if (ctx.state.user && ctx.state.user.documentId) {
|
|
248
|
+
strapi2.log.info(`[magic-sessionmanager] [BLOCKED] Session terminated for user ${ctx.state.user.documentId}`);
|
|
249
|
+
return ctx.unauthorized("This session has been terminated. Please login again.");
|
|
250
|
+
}
|
|
278
251
|
}
|
|
279
252
|
} catch (err) {
|
|
280
253
|
strapi2.log.debug("[magic-sessionmanager] Error checking session:", err.message);
|
|
@@ -301,7 +274,7 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
|
|
|
301
274
|
};
|
|
302
275
|
};
|
|
303
276
|
const getClientIp = getClientIp_1;
|
|
304
|
-
const { encryptToken: encryptToken$1, decryptToken: decryptToken$2 } = encryption;
|
|
277
|
+
const { encryptToken: encryptToken$1, decryptToken: decryptToken$2, hashToken: hashToken$1 } = encryption;
|
|
305
278
|
const { createLogger: createLogger$3 } = logger;
|
|
306
279
|
const SESSION_UID$2 = "plugin::magic-sessionmanager.session";
|
|
307
280
|
const USER_UID$2 = "plugin::users-permissions.user";
|
|
@@ -585,11 +558,15 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
585
558
|
if (matchingSession) {
|
|
586
559
|
const encryptedToken = newAccessToken ? encryptToken$1(newAccessToken) : matchingSession.token;
|
|
587
560
|
const encryptedRefreshToken = newRefreshToken ? encryptToken$1(newRefreshToken) : matchingSession.refreshToken;
|
|
561
|
+
const newTokenHash = newAccessToken ? hashToken$1(newAccessToken) : matchingSession.tokenHash;
|
|
562
|
+
const newRefreshTokenHash = newRefreshToken ? hashToken$1(newRefreshToken) : matchingSession.refreshTokenHash;
|
|
588
563
|
await strapi2.documents(SESSION_UID$2).update({
|
|
589
564
|
documentId: matchingSession.documentId,
|
|
590
565
|
data: {
|
|
591
566
|
token: encryptedToken,
|
|
567
|
+
tokenHash: newTokenHash,
|
|
592
568
|
refreshToken: encryptedRefreshToken,
|
|
569
|
+
refreshTokenHash: newRefreshTokenHash,
|
|
593
570
|
lastActive: /* @__PURE__ */ new Date()
|
|
594
571
|
}
|
|
595
572
|
});
|
|
@@ -603,7 +580,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
603
580
|
});
|
|
604
581
|
log.info("[SUCCESS] Refresh Token interceptor middleware mounted");
|
|
605
582
|
strapi2.server.use(
|
|
606
|
-
lastSeen({ strapi: strapi2
|
|
583
|
+
lastSeen({ strapi: strapi2 })
|
|
607
584
|
);
|
|
608
585
|
log.info("[SUCCESS] LastSeen middleware mounted");
|
|
609
586
|
await ensureContentApiPermissions(strapi2, log);
|
|
@@ -739,10 +716,18 @@ const attributes = {
|
|
|
739
716
|
type: "text",
|
|
740
717
|
"private": true
|
|
741
718
|
},
|
|
719
|
+
tokenHash: {
|
|
720
|
+
type: "string",
|
|
721
|
+
configurable: false
|
|
722
|
+
},
|
|
742
723
|
refreshToken: {
|
|
743
724
|
type: "text",
|
|
744
725
|
"private": true
|
|
745
726
|
},
|
|
727
|
+
refreshTokenHash: {
|
|
728
|
+
type: "string",
|
|
729
|
+
configurable: false
|
|
730
|
+
},
|
|
746
731
|
loginTime: {
|
|
747
732
|
type: "datetime",
|
|
748
733
|
required: true
|
|
@@ -1774,7 +1759,7 @@ var controllers$1 = {
|
|
|
1774
1759
|
license,
|
|
1775
1760
|
settings
|
|
1776
1761
|
};
|
|
1777
|
-
const { encryptToken, decryptToken, generateSessionId } = encryption;
|
|
1762
|
+
const { encryptToken, decryptToken, generateSessionId, hashToken } = encryption;
|
|
1778
1763
|
const { createLogger: createLogger$1 } = logger;
|
|
1779
1764
|
const SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
1780
1765
|
const USER_UID = "plugin::users-permissions.user";
|
|
@@ -1792,6 +1777,8 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1792
1777
|
const sessionId = generateSessionId(userId);
|
|
1793
1778
|
const encryptedToken = token ? encryptToken(token) : null;
|
|
1794
1779
|
const encryptedRefreshToken = refreshToken ? encryptToken(refreshToken) : null;
|
|
1780
|
+
const tokenHashValue = token ? hashToken(token) : null;
|
|
1781
|
+
const refreshTokenHashValue = refreshToken ? hashToken(refreshToken) : null;
|
|
1795
1782
|
const session2 = await strapi2.documents(SESSION_UID).create({
|
|
1796
1783
|
data: {
|
|
1797
1784
|
user: userId,
|
|
@@ -1802,11 +1789,15 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1802
1789
|
lastActive: now,
|
|
1803
1790
|
isActive: true,
|
|
1804
1791
|
token: encryptedToken,
|
|
1805
|
-
//
|
|
1792
|
+
// Encrypted Access Token
|
|
1793
|
+
tokenHash: tokenHashValue,
|
|
1794
|
+
// SHA-256 hash for fast lookup
|
|
1806
1795
|
refreshToken: encryptedRefreshToken,
|
|
1807
|
-
//
|
|
1796
|
+
// Encrypted Refresh Token
|
|
1797
|
+
refreshTokenHash: refreshTokenHashValue,
|
|
1798
|
+
// SHA-256 hash for fast lookup
|
|
1808
1799
|
sessionId
|
|
1809
|
-
//
|
|
1800
|
+
// Unique identifier
|
|
1810
1801
|
}
|
|
1811
1802
|
});
|
|
1812
1803
|
log.info(`[SUCCESS] Session ${session2.documentId} (${sessionId}) created for user ${userId}`);
|
|
@@ -1884,9 +1875,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1884
1875
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1885
1876
|
const timeSinceActive = now - lastActiveTime;
|
|
1886
1877
|
const isTrulyActive = session2.isActive && timeSinceActive < inactivityTimeout;
|
|
1887
|
-
const { token, ...
|
|
1878
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1888
1879
|
return {
|
|
1889
|
-
...
|
|
1880
|
+
...safeSession,
|
|
1890
1881
|
isTrulyActive,
|
|
1891
1882
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1892
1883
|
};
|
|
@@ -1915,9 +1906,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1915
1906
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1916
1907
|
const timeSinceActive = now - lastActiveTime;
|
|
1917
1908
|
const isTrulyActive = timeSinceActive < inactivityTimeout;
|
|
1918
|
-
const { token, ...
|
|
1909
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1919
1910
|
return {
|
|
1920
|
-
...
|
|
1911
|
+
...safeSession,
|
|
1921
1912
|
isTrulyActive,
|
|
1922
1913
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1923
1914
|
};
|
|
@@ -1954,9 +1945,9 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
1954
1945
|
const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
|
|
1955
1946
|
const timeSinceActive = now - lastActiveTime;
|
|
1956
1947
|
const isTrulyActive = session2.isActive && timeSinceActive < inactivityTimeout;
|
|
1957
|
-
const { token, ...
|
|
1948
|
+
const { token, tokenHash, refreshToken, refreshTokenHash, ...safeSession } = session2;
|
|
1958
1949
|
return {
|
|
1959
|
-
...
|
|
1950
|
+
...safeSession,
|
|
1960
1951
|
isTrulyActive,
|
|
1961
1952
|
minutesSinceActive: Math.floor(timeSinceActive / 1e3 / 60)
|
|
1962
1953
|
};
|
|
@@ -2073,7 +2064,7 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
2073
2064
|
}
|
|
2074
2065
|
};
|
|
2075
2066
|
};
|
|
2076
|
-
const version = "4.2.
|
|
2067
|
+
const version = "4.2.8";
|
|
2077
2068
|
const require$$2 = {
|
|
2078
2069
|
version
|
|
2079
2070
|
};
|
package/package.json
CHANGED