Skip to content

v4 Signing Errors with exactly 7 day expiry #2169

@JohnGale87

Description

@JohnGale87

Environment details

  • OS: macOS 13.2.1
  • Node.js version: 16.19.0
  • npm version: 8.19.3
  • @google-cloud/storage version: 6.9.4

Steps to reproduce

const FILE_NAME = '<your-file-name>';
const BUCKET_NAME = '<your-bucket-name>';
const file = new Storage().bucket(BUCKET_NAME).file(FILE_NAME);
const ACCESSIBLE_AT = new Date().setMilliseconds(999).valueOf();
const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000;
const [url] = await file.getSignedUrl({
  version: 'v4',
  action: 'read',
  accessibleAt: ACCESSIBLE_AT,
  expires: ACCESSIBLE_AT + SEVEN_DAYS_IN_MS,
  virtualHostedStyle: true,
});

The above code will throw Error: Max allowed expiration is seven days (604800 seconds)..

I've debugged it and found what I believe is a bug in src.signer.URLSigner.parseExpires that uses Math.round instead of Math.floor.

src.signer.URLSigner.parseAccessibleAt already uses Math.floor and does not seem to suffer with the same issue.

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/nodejs-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions