Skip to content

Commit 1e15b11

Browse files
committed
fix: prevent creating new buckets with the name 'public'
1 parent 07a7244 commit 1e15b11

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/storage/storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export class Storage {
9393

9494
mustBeValidBucketName(data.name)
9595

96+
if (data.name.toLowerCase() === 'public') {
97+
throw ERRORS.InvalidBucketName(data.name)
98+
}
99+
96100
const bucketData: Parameters<Database['createBucket']>[0] = data
97101

98102
if (typeof data.fileSizeLimit === 'number' || typeof data.fileSizeLimit === 'string') {

src/test/bucket.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ describe('testing POST bucket', () => {
235235
expect(response.statusCode).toBe(400)
236236
})
237237

238+
test('user is not able to create a bucket with the name "public"', async () => {
239+
const response = await appInstance.inject({
240+
method: 'POST',
241+
url: `/bucket`,
242+
headers: {
243+
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
244+
},
245+
payload: {
246+
name: 'pUbLiC',
247+
},
248+
})
249+
250+
expect(response.statusCode).toBe(400)
251+
const { statusCode, error } = await response.json()
252+
expect(statusCode).toBe('400')
253+
expect(error).toBe('Invalid Input')
254+
})
255+
238256
test('user is not able to create a bucket with the leading and trailing spaces', async () => {
239257
const response = await appInstance.inject({
240258
method: 'POST',

src/test/s3-protocol.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ describe('S3 Protocol', () => {
111111
expect(Location).toBeTruthy()
112112
})
113113

114+
it('cannot create a bucket named "public"', async () => {
115+
const createBucketRequest = new CreateBucketCommand({
116+
Bucket: 'public',
117+
})
118+
119+
await expect(client.send(createBucketRequest)).rejects.toThrow('Bucket name invalid')
120+
})
121+
114122
it('can get bucket versioning', async () => {
115123
const bucket = await createBucket(client)
116124
const bucketVersioningCommand = new GetBucketVersioningCommand({

0 commit comments

Comments
 (0)