Skip to content

Commit c703835

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

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-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: 0 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({
@@ -105,7 +103,6 @@ describe("DynamoDBStore", () => {
105103
});
106104
store.expiresIn.should.equal(0);
107105
});
108-
>>>>>>> Stashed changes
109106
});
110107

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

0 commit comments

Comments
 (0)