Skip to content

Commit

Permalink
feat: restrict access to categories (#3570)
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
mariojsnunes committed Jun 14, 2024
2 parents c2c6fa2 + 10b98d0 commit 0573975
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
12 changes: 8 additions & 4 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ service cloud.firestore {
return true;
}

function noWriteAccess() {
return false;
}

match /aggregations_rev20220126/{document=**} {
allow read: if isPublicReadable();
allow write: if isPublicWritable();
Expand All @@ -36,7 +40,7 @@ service cloud.firestore {

match /question_categories_rev20231130/{document=**} {
allow read: if isPublicReadable();
allow write: if isPublicWritable();
allow write: if noWriteAccess();
}

match /questions_rev20230926/{document=**} {
Expand All @@ -46,7 +50,7 @@ service cloud.firestore {

match /research_categories_rev20221224/{document=**} {
allow read: if isPublicReadable();
allow write: if isPublicWritable();
allow write: if noWriteAccess();
}

match /research_rev20201020/{document=**} {
Expand Down Expand Up @@ -84,12 +88,12 @@ service cloud.firestore {

match /v3_categories/{document=**} {
allow read: if isPublicReadable();
allow write: if isPublicWritable();
allow write: if noWriteAccess();
}

match /v3_tags/{document=**} {
allow read: if isPublicReadable();
allow write: if isPublicWritable();
allow write: if noWriteAccess();
}

match /v3_users/{userId} {
Expand Down
26 changes: 23 additions & 3 deletions packages/security-rules/tests/general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,11 @@ describe('community platform', () => {
const publicCollections = [
'aggregations_rev20220126',
'discussions_rev20231022',
'question_categories_rev20231130',
'questions_rev20230926',
'research_categories_rev20221224',
'research_rev20201020',
'user_notifications_rev20221209',
'v3_howtos',
'v3_mappins',
'v3_tags',
'v3_users',
]

Expand All @@ -133,4 +130,27 @@ describe('community platform', () => {
})
})
})

const readableCollections = [
'v3_categories',
'v3_tags',
'research_categories_rev20221224',
'question_categories_rev20231130',
]

readableCollections.forEach((collection) => {
describe(`${collection}`, () => {
it(`${collection} allows READ`, async () => {
await assertSucceeds(getDoc(doc(unauthedDb, collection, 'bar')))
})

it(`${collection} does not allow WRITE`, async () => {
await assertFails(
setDoc(doc(unauthedDb, collection, 'bar'), {
email: '',
}),
)
})
})
})
})

0 comments on commit 0573975

Please sign in to comment.