Repository navigation
fix(presigned-url): a bucket cache hit re-reads the bucket id under the caller's RLS - #2007
Open
theothersideofgod wants to merge 2 commits into
Open
theothersideofgod wants to merge 2 commits into
theothersideofgod wants to merge 2 commits into
Conversation
An unapproved user who asks for a bucket another user already loaded gets the cached row, and the file INSERT then fails with the bucket's id in the error. These tests fail until the cache hit re-reads the id under RLS. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The bucket cache returned a row loaded by one caller to every caller of the database, on the assumption that all members see all buckets. An unapproved user sees none, so a hit leaked the bucket's existence and id. A hit now reads the id with the caller's RLS and returns the cached config only when it matches. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Review complete. No issues found — approved ✅. This PR tightens the shared bucket-config cache in the presigned-URL plugin: even on a cache hit, the storage module now re-reads the bucket id under the caller's RLS settings and only serves the cached config when the freshly visible row id matches the cached entry, evicting and reloading otherwise.
Reviewer note: two low-severity observations (cache-hit path bypasses Reviewed commit: df536ec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A user who may not see a bucket must get the same answer from
uploadAppFilewhether or not someone else used that bucket a moment ago.getBucketConfigcaches a bucket's config per database, storage module, key and owner, not per caller. Only a cache miss read the row under the request role's RLS. A hit returned the cached row to anyone. The cache's comment gave the reason: "since AuthzEntityMembership grants all org members access to all org buckets ... bypassing RLS on cache hits is safe". That holds only for callers who are members. A signed-up user who is not approved sees no bucket at all. If such a user names a bucket that another user already loaded into the cache, they get its config. The files INSERT is then refused by RLS with an error that carries the bucket's id.Entry point E1 (GraphQL API), role
authenticated. Anyone who can sign up on the tenant can do it. The request isuploadAppFile(input: { bucketKey: "default", ... }). Impact is low: the caller learns that the bucket exists and its id. Nothing is written and no file data is exposed.Rules touched: R9, R13
Before / after
Live, on a local
fun up(GraphQL imageconstructive:9b764d6, whosegraphile-presigned-url-pluginsource is identical to main). The user is erin, freshly signed up and not approved (appMemberships.isApproved = false,appBucketsreturns 0 rows). The owner is alice. The cache was cold because the server had just restarted.bucketKey: "default", cold cacheBUCKET_NOT_FOUNDBUCKET_NOT_FOUNDbucketKey: "default"bucketKey: "default", after aliceParent not found: 01a1d5ba-b597-…(the bucket's real id)BUCKET_NOT_FOUNDBUCKET_NOT_FOUNDBUCKET_NOT_FOUNDFor "after", only the built
dist/storage-module-cache.js(CJS and ESM) was layered onto the pinned image.graphql-publicwas pointed at that image and then set back to the pinned one.Unit:
s3-signer.integration.test.tswas not run here. It needs a RustFS on its default endpoint. This diff does not touch it.The change
On a hit,
getBucketConfigfirst runsSELECT id FROM <buckets> WHERE <the same key / owner / database filter> LIMIT 1on the caller's client, so the request role's RLS applies. It then:nullwhen the caller sees no row (BUCKET_NOT_FOUND/DATABASE_ACCESS_DENIED, as on a cold cache);readAndCache).The miss query is unchanged. Its two SELECT variants now share the
where/valuesthe hit check uses. The column list is identical in every case, becausehasOwnerimpliesisEntityScoped.This is the approach of the cache-hit block in draft #1655 (exact id re-read on every hit; "cached data never substitutes for row authorization"). This PR is that one piece on current main. It leaves out #1655's build-scoped caches and ambiguity checks.
Is this how it was meant to work
No. Three sources:
bucketKeyalready refuses this caller before any bucket is read. On 2026-11-13, an unapproved user'suploadAppFilewith nobucketKeyreturnedSTORAGE_SCOPE_MEMBERSHIP_REQUIRED(resolve_default_bucketrequires the scope membership first).How it came about:
The existing tests (
bucket-config-cache.test.ts) use one fake client for every call. No test asked as a second caller.Behavior changes
uploadAppFile/ bulk upload, caller cannot see the bucket, bucket cached by someone elseParent not found: <bucket id>BUCKET_NOT_FOUND(orDATABASE_ACCESS_DENIEDwhendatabaseIdis given)SELECT idunder RLSNo error text, GraphQL description or README changes. The doc comments on the cache and
getBucketConfignow describe the hit check.Rule point:
storage-module-invalidation.test.ts("clears bucket metadata and fences an in-flight bucket read", 770f892) counted 3 queries, which pinned "a hit makes no query". It now counts 4 and asserts that the call after the clear is a full read. Its fence andtoBe(fresh)assertions are unchanged. Theserves a reconciled bucket from the cachetest asserted one read. It now asserts the observable part: config changed in the table is not seen until the TTL ends.Considered
clearBucketCache.BUCKET_NOT_FOUNDat the INSERT failure. This hides the message and still hands the caller config it may not read.Recommended: this PR's id check, because it is the design in #1655 (so that stack rebases onto it unchanged) and it keeps the exported API. Removing the cache is the smaller code. It is the better choice if #1655 is not going to land.
Not done here: on entity-scoped planes (org buckets), a non-member naming
ownerIdof an org whose bucket is cached takes the same hit path. The fix covers it, because the hit check carriesowner_id. I did not drive it live: the test tenant has only an app-scope storage module.Generated with Devin