Skip to content

Commit 825094c

Browse files
committed
feat: Don't allow negative values for expiresIn
1 parent fe46a0c commit 825094c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ unless the `client` options is provided to override them.
2121
☣️ Legacy reap behaviors use DynamoDB [`scan`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/scancommand.html)
2222
functionality that can incur significant costs. Should instead enable [DynamoDB TTL](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html)
2323
and select the `expires` field. TODO should we just remove it since we're already making a breaking change?
24-
- `expiresIn` Optional set the number of seconds for DynamoDB TTL. Defaults to the cookie's maxAge.
24+
- `expiresIn` Optional set the number of seconds for DynamoDB TTL. Defaults to the cookie's maxAge. Must be a positive integer.
2525

2626
## Usage
2727

lib/connect-dynamodb.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,20 @@ module.exports = function (connect) {
6868
if (this.reapInterval > 0) {
6969
this._reap = setInterval(this.reap.bind(this), this.reapInterval);
7070
}
71-
this.expiresIn = null == options.expiresIn ? 0 : options.expiresIn
71+
if (options.expiresIn) {
72+
if (!Number.isInteger(options.expiresIn)) {
73+
console.warn("`expiresIn` must be an integer. Reverting to default behaviour");
74+
this.expiresIn = 0;
75+
}
76+
else if (options.expiresIn < 0) {
77+
console.warn("Negative `expiresIn` values are not supported. Reverting to default behaviour");
78+
this.expiresIn = 0;
79+
} else {
80+
this.expiresIn = options.expiresIn;
81+
}
82+
} else {
83+
this.expiresIn = 0;
84+
}
7285
}
7386

7487
/*

test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ describe("DynamoDBStore", () => {
7979
})
8080
.finally(done);
8181
});
82-
<<<<<<< Updated upstream
83-
=======
8482

8583
it("should store a valid expiresIn", () => {
8684
const store = new DynamoDBStore({
@@ -98,14 +96,16 @@ describe("DynamoDBStore", () => {
9896
store.expiresIn.should.equal(0);
9997
});
10098

99+
it("should revert expiresIn to 0 when set to a negative integer", () => {
100+
});
101+
101102
it("should revert expiresIn to 0 when set to a negative integer", () => {
102103
const store = new DynamoDBStore({
103104
table: "sessions-test",
104105
expiresIn: -10
105106
});
106107
store.expiresIn.should.equal(0);
107108
});
108-
>>>>>>> Stashed changes
109109
});
110110

111111
describe("Initializing", () => {

0 commit comments

Comments
 (0)