Repository navigation
fix(presigned-url): resolve a visible file's bucket through the generated physical-name reader #1916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(presigned-url): resolve a visible file's bucket through the generated physical-name reader #1916
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
graphile/graphile-presigned-url-plugin/__tests__/bucket-physical-name.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { readBucketPhysicalName } from '../src/storage-module-cache'; | ||
| import type { StorageModuleConfig } from '../src/types'; | ||
|
|
||
| function storageConfig( | ||
| overrides: Partial<StorageModuleConfig> = {}, | ||
| ): StorageModuleConfig { | ||
| return { | ||
| id: '11111111-1111-1111-1111-111111111111', | ||
| bucketsQualifiedName: 'storage_public.app_buckets', | ||
| filesQualifiedName: 'storage_public.app_files', | ||
| schemaName: 'storage_public', | ||
| bucketsTableName: 'app_buckets', | ||
| filesTableName: 'app_files', | ||
| recorderQualifiedName: 'storage_private.app_files_record_file', | ||
| bucketPhysicalNameQualifiedName: 'storage_private.app_buckets_physical_name', | ||
| scope: 'app', | ||
| entityTableId: null, | ||
| entityQualifiedName: null, | ||
| endpoint: null, | ||
| publicUrlPrefix: null, | ||
| provider: 'minio', | ||
| region: 'us-east-1', | ||
| connectionOverrides: [], | ||
| allowedOrigins: null, | ||
| uploadUrlExpirySeconds: 900, | ||
| downloadUrlExpirySeconds: 3600, | ||
| defaultMaxFileSize: 1000, | ||
| maxFilenameLength: 1024, | ||
| cacheTtlSeconds: 300, | ||
| hasPathShares: false, | ||
| hasVersioning: false, | ||
| hasContentHash: false, | ||
| hasConfirmUpload: false, | ||
| maxBulkFiles: 100, | ||
| maxBulkTotalSize: 1000, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| const BUCKET_ID = '22222222-2222-2222-2222-222222222222'; | ||
|
|
||
| function client(rows: Array<Record<string, unknown>>) { | ||
| return { query: jest.fn().mockResolvedValue({ rows }) }; | ||
| } | ||
|
|
||
| describe('readBucketPhysicalName', () => { | ||
| it('reads the coordinate through the generated physical-name reader, not the bucket table', async () => { | ||
| const pgClient = client([{ physical_name: 'app-a1b2-public' }]); | ||
|
|
||
| await expect(readBucketPhysicalName(pgClient, storageConfig(), BUCKET_ID)).resolves.toBe('app-a1b2-public'); | ||
|
|
||
| expect(pgClient.query).toHaveBeenCalledTimes(1); | ||
| const [{ text, values }] = pgClient.query.mock.calls[0]; | ||
| expect(text).toBe('SELECT storage_private.app_buckets_physical_name($1) AS physical_name'); | ||
| expect(text).not.toContain('storage_public.app_buckets'); | ||
| expect(values).toEqual([BUCKET_ID]); | ||
| }); | ||
|
|
||
| it('returns null when no physical bucket was recorded', async () => { | ||
| const pgClient = client([{ physical_name: null }]); | ||
|
|
||
| await expect(readBucketPhysicalName(pgClient, storageConfig(), BUCKET_ID)).resolves.toBeNull(); | ||
| }); | ||
|
|
||
| it('throws when the storage module has no private schema to read from', async () => { | ||
| const pgClient = client([]); | ||
|
|
||
| await expect( | ||
| readBucketPhysicalName(pgClient, storageConfig({ bucketPhysicalNameQualifiedName: null }), BUCKET_ID), | ||
| ).rejects.toThrow('STORAGE_BUCKET_READER_MISSING'); | ||
| expect(pgClient.query).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 bug · high
Download resolver now throws where it previously returned null
The download resolver replaced a direct bucket-table read that degraded to
nullwithreadBucketPhysicalName, which throwsSTORAGE_BUCKET_READER_MISSINGwhen the module records noprivate_schema(graphile/graphile-presigned-url-plugin/src/download-url-field.ts:132-143; throw at storage-module-cache.ts:297-299). The Grafastlambdahas no error handling, so a missing reader function (legacy module predating the generated reader) or a nullprivate_schemasurfaces as a GraphQL field error instead of the previousdownloadUrl: null. The delete path has the same regression in milder form: the reader throw is swallowed by the generic catch atplugin.ts:570-573and logged as a transient S3 failure, silently skipping sync S3 cleanup. Legacy or reader-less storage modules go from working (or cleanly skipping) to hard errors and orphaned S3 objects.📋 Prompt for AI Agents
In graphile/graphile-presigned-url-plugin/src/storage-module-cache.ts around lines 292-305, change
readBucketPhysicalNameso that a nullconfig.bucketPhysicalNameQualifiedName(currently throwing STORAGE_BUCKET_READER_MISSING at line 297-298) and a missing/unexecutable reader function (SQLSTATE 42883) fall back to a directSELECT physical_name FROM ${config.bucketsQualifiedName} WHERE id = $1 LIMIT 1read under the caller's RLS, returning null when the row is absent — the pre-patch behavior of both download-url-field.ts:132-143 and plugin.ts:560. Optionally distinguish the reader-unavailable case in plugin.ts's catch (lines 570-573) with a distinct log so it is not misreported as a transient S3 failure.