CodexBloom - Programming Q&A Platform

GCP Cloud Storage signed URLs not expiring as expected when using Node.js

👀 Views: 193 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-08
google-cloud-storage signed-urls node.js JavaScript

After trying multiple solutions online, I still can't figure this out... I can't seem to get I'm upgrading from an older version and I'm trying to generate signed URLs for accessing files in a GCP Cloud Storage bucket using the `@google-cloud/storage` library in Node.js, but I'm facing an issue where the signed URLs seem to not expire as expected. I configured the expiration time to be 1 hour, but when I test the generated URL after 2 hours, it still works, which is contrary to my expectation. Here's how I'm generating the signed URL: ```javascript const { Storage } = require('@google-cloud/storage'); const storage = new Storage(); const bucketName = 'my-bucket'; const fileName = 'example.txt'; const options = { version: 'v4', action: 'read', expires: Date.now() + 60 * 60 * 1000, // 1 hour in milliseconds }; async function generateSignedUrl() { const [url] = await storage .bucket(bucketName) .file(fileName) .getSignedUrl(options); console.log(`Generated signed URL: ${url}`); } generateSignedUrl(); ``` I also verified that the file permission is set correctly and that the signed URL generation is successful. The URL looks something like this: ``` https://storage.googleapis.com/my-bucket/example.txt?GoogleAccessId=...&Expires=...&Signature=... ``` To troubleshoot, I've tried: 1. Regenerating the signed URL with different expiration times (like 10 minutes and 30 minutes) but the behavior remains the same. 2. Checking the bucket's IAM permissions, which seem fine as my service account has `Storage Object Viewer` role. 3. Looking at the documentation for any potential configuration issues but haven't found anything relevant. Is there a caching mechanism or any other setting that could be causing these signed URLs not to expire properly? Any insights would be greatly appreciated! Any pointers in the right direction? What's the best practice here? Is there a simpler solution I'm overlooking? I've been using Javascript for about a year now.