#14659·nocodb

Bug: presigned URL cache key includes the rounded expiry, so signed URLs are re-signed every 10 minutes

Author: aleximperCreated Sep 26, 2026Updated Sep 28, 2026

Please confirm that the bug report does not already exist

  • I searched open and closed issues for presigned, expireAt, roundExpiry and signed url cache and found nothing covering this.

Summary

PresignedUrl.getSignedUrl() puts the (rounded) expiry timestamp inside the cache key. Because roundExpiry() buckets the expiry into 10-minute slots, the key for the same file changes every 10 minutes, so the cached signed URL is never reused across slots even though it is still valid for a long time (2 h by default).

The expiry is already validated independently of the key, on the cached value, a few lines below — so including it in the key is redundant.

Where

packages/nocodb/src/models/PresignedUrl.ts (current default branch):

typescript
function roundExpiry(date) {
  const msInTenMinutes = 10 * 60 * 1000;
  return new Date(Math.ceil(date.getTime() / msInTenMinutes) * msInTenMinutes);
}
typescript
const expireAt = roundExpiry(
  new Date(new Date().getTime() + expireSeconds * 1000),
);

const pathParameters: { [key: string]: string } = {
  expireAt: expireAt.toISOString(),     // <-- ends up in the cache key
};
...
// append query params to the cache path
const cachePath = `${path}?${new URLSearchParams(pathParameters).toString()}`;

const url = await NocoCache.get(
  'root',
  `${CacheScope.PRESIGNED_URL}:path:${slash(cachePath)}`,
  CacheGetType.TYPE_OBJECT,
);

if (url) {
  // if present, check if the expiry date is greater than now
  if (new Date(url.expires_at).getTime() > new Date().getTime()) {
    return url.url;                     // <-- freshness already guaranteed here
  } else {
    await this.delete({ path: url.path, url: url.url });
  }
}

The if (url) block already discards anything past expires_at, so a cache entry can never be served stale regardless of what the key contains.

Effect

With the default NC_ATTACHMENT_EXPIRE_SECONDS (2 h), a URL signed at T stays valid for ~2 h but its cache key is only looked up during the 10-minute slot in which it was created. Every new slot signs everything again.

Measured on a self-hosted instance (Postgres metadata, Redis cache), on a grid view of ~1,300 records with 43 attachment fields:

First page load at the start of a new 10-minute slot ~4.9 s
Same request once the slot is warm ~0.5 s
Share of accumulated presignedUrl:* keys still matching the current slot ~0.04 %

So roughly 99.9 % of the entries in the presigned-URL cache are dead weight in Redis, and the first user to open a large attachment-heavy view after each slot boundary pays for re-signing every attachment. RSA-2048 signing measured at ~1,520 signatures/s/core here, which is what turns into those seconds.

We are currently working around it with an external cron that pre-warms the views a few seconds after each slot boundary. That should not be necessary.

Proposed fix

Keep expireAt where it is needed — as a signing parameter — but drop it from the string used to build the cache key:

typescript
// parameters that affect the signature
const pathParameters: { [key: string]: string } = {
  expireAt: expireAt.toISOString(),
  ...
};

// parameters that identify the *resource* for caching purposes
const { expireAt: _ignored, ...cacheParameters } = pathParameters;
const cachePath = `${path}?${new URLSearchParams(cacheParameters).toString()}`;

ResponseContentDisposition / ResponseContentType / ResponseContentEncoding should stay in the key, since they do change which URL is correct for a given request.

With that change the cached URL is reused for its whole validity window, and the existing expires_at check below keeps handling expiry — including the this.delete() path when it has passed.

One detail worth deciding: with the key no longer varying, an entry will be served until it actually expires, so a viewer can receive a URL with only a few seconds of life left. If that matters, the check could be tightened to a margin (e.g. expires_at - now > 60 s) rather than reintroducing the timestamp into the key.

Environment

  • PackageVersion: 2026.08.2 (code re-checked against the current default branch, unchanged)
  • RootDB: pg
  • Cache: Redis
  • Docker: true
  • Storage adapter: GCS