Skip to content

Commit

Permalink
Increase default expire time (#30)
Browse files Browse the repository at this point in the history
This commit increases the default expire time from 30 seconds to 30 minutes in order to prevent `Access Denied` errors due to expired links from possible clockdrift.
  • Loading branch information
Thomas Fankhauser authored and jasonsims committed Dec 7, 2016
1 parent c2e8a4a commit a8d5579
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ npm install aws-cloudfront-sign
* `@return {Object} cookies` - Signed AWS cookies

### Options
* `expireTime` (**Optional** - Default: 30s) - The time when the URL should
expire. Accepted values are
* number - Time in milliseconds (`new Date().getTime() + 30000`)
* `expireTime` (**Optional** - Default: 1800 sec == 30 min) - The time when the URL should expire. Accepted values are
* number - Time in milliseconds (`new Date().getTime() + 1800000`)
* moment - Valid [momentjs][moment_docs] object (`moment().add(1, 'day')`)
* Date - Javascript Date object (`new Date(2016, 0, 1)`)
* `ipRange` (**Optional**) - IP address range allowed to make GET requests
Expand Down Expand Up @@ -85,6 +84,7 @@ npm install aws-cloudfront-sign

## Examples
### Creating a signed URL
By default the URL will expire after half an hour.
```js
var cf = require('aws-cloudfront-sign')
var options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
Expand Down
6 changes: 3 additions & 3 deletions lib/cloudfrontUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function normalizeBase64(str) {
* http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html
*
* @deprecated
* @param {String}: Base64 encoded signature string
*/
function normalizeSignature(sig) {
console.log(
Expand All @@ -137,8 +137,8 @@ function normalizeSignature(sig) {
* @returns {Object} AWS policy object
*/
function _createPolicy(cfUrl, expireTime, ipRange) {
// If an expiration time isn't set, default to 30 seconds.
var defaultExpireTime = Math.round(Date.now() + 30000);
// If an expiration time isn't set, default to 30 minutes.
var defaultExpireTime = Math.round(Date.now() + 1800000);
expireTime = expireTime || defaultExpireTime;

return new CannedPolicy(cfUrl, expireTime, ipRange);
Expand Down
4 changes: 2 additions & 2 deletions test/lib/cloudfrontUtil.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ describe('CloudfrontUtil', function() {
done();
});

it('should default `expireTime` to 30 seconds', function(done) {
it('should default `expireTime` to 30 minutes (1800 seconds)', function(done) {
var params = _.extend({}, defaultParams);
var result = CloudfrontUtil.getSignedUrl('http://foo.com', params);
var parsedResult = url.parse(result, true);

expect(parsedResult.query.Expires).to.equal('30');
expect(parsedResult.query.Expires).to.equal('1800');
done();
});

Expand Down

0 comments on commit a8d5579

Please sign in to comment.