lambder 1.0.144 → 1.0.146
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/Lambder.d.ts +11 -7
- package/dist/Lambder.js +18 -7
- package/dist/LambderMSW.js +2 -0
- package/dist/LambderResponseBuilder.js +12 -6
- package/dist/LambderSessionController.d.ts +7 -7
- package/dist/LambderSessionController.js +1 -1
- package/dist/LambderSessionManager.d.ts +2 -2
- package/dist/LambderSessionManager.js +2 -2
- package/dist/LambderUtils.js +12 -6
- package/examples/secure-session-example.ts +10 -10
- package/package.json +2 -1
- package/src/Lambder.ts +35 -19
- package/src/LambderMSW.ts +3 -0
- package/src/LambderResponseBuilder.ts +11 -6
- package/src/LambderSessionController.ts +9 -9
- package/src/LambderSessionManager.ts +4 -4
- package/src/LambderUtils.ts +11 -6
- package/tests/session.test.ts +1069 -0
|
@@ -2,12 +2,12 @@ import crypto from "crypto";
|
|
|
2
2
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
3
3
|
import { DynamoDBDocumentClient, QueryCommand, DeleteCommand, PutCommand, GetCommand } from "@aws-sdk/lib-dynamodb";
|
|
4
4
|
|
|
5
|
-
export type LambderSessionContext = {
|
|
5
|
+
export type LambderSessionContext<SessionData = any> = {
|
|
6
6
|
[x: string]: any;
|
|
7
7
|
sessionToken: string;
|
|
8
8
|
csrfToken: string;
|
|
9
9
|
sessionKey: string;
|
|
10
|
-
data:
|
|
10
|
+
data: SessionData;
|
|
11
11
|
createdAt: number;
|
|
12
12
|
expiresAt: number;
|
|
13
13
|
lastAccessedAt: number;
|
|
@@ -167,8 +167,8 @@ export default class LambderSessionManager{
|
|
|
167
167
|
if(this.enableSlidingExpiration){
|
|
168
168
|
session.lastAccessedAt = Math.floor(Date.now()/1000);
|
|
169
169
|
session.expiresAt = session.lastAccessedAt + session.ttlInSeconds;
|
|
170
|
-
//
|
|
171
|
-
this.ddbPutItem(session).catch(() => {});
|
|
170
|
+
// Wait for the update to ensure it persists before Lambda freezes
|
|
171
|
+
await this.ddbPutItem(session).catch(() => {});
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
return session;
|
package/src/LambderUtils.ts
CHANGED
|
@@ -21,10 +21,10 @@ export default class LambderUtils {
|
|
|
21
21
|
}
|
|
22
22
|
if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
|
|
23
23
|
const ejsPath = path.resolve(this.ejsPath);
|
|
24
|
-
const absolutePath = path.
|
|
24
|
+
const absolutePath = path.resolve(ejsPath, filePath);
|
|
25
25
|
console.log("readEjsFileSync", { filePath, ejsPath, absolutePath });
|
|
26
|
-
if(!absolutePath.
|
|
27
|
-
return String(fs.
|
|
26
|
+
if(!absolutePath.startsWith(ejsPath)){ return "forbidden-ejs-path"; }
|
|
27
|
+
return String(await fs.promises.readFile(absolutePath));
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
private async checkEjsFileExist(filePath: string){
|
|
@@ -36,10 +36,15 @@ export default class LambderUtils {
|
|
|
36
36
|
}
|
|
37
37
|
if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
|
|
38
38
|
const ejsPath = path.resolve(this.ejsPath);
|
|
39
|
-
const absolutePath = path.
|
|
39
|
+
const absolutePath = path.resolve(ejsPath, filePath);
|
|
40
40
|
console.log("checkEjsFileExist", { filePath, ejsPath, absolutePath });
|
|
41
|
-
if(!absolutePath.
|
|
42
|
-
|
|
41
|
+
if(!absolutePath.startsWith(ejsPath)){ return false; }
|
|
42
|
+
try {
|
|
43
|
+
const stat = await fs.promises.stat(absolutePath);
|
|
44
|
+
return stat.isFile();
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
43
48
|
};
|
|
44
49
|
|
|
45
50
|
async renderEjs(
|