-
Notifications
You must be signed in to change notification settings - Fork 139
fix: prevent DOS when checking an unknown repo #1095
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
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.
LGTM! 👍🏼
I looked around the mongo
handlers and it seems there aren't any other similar bugs.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1095 +/- ##
==========================================
- Coverage 77.40% 75.58% -1.83%
==========================================
Files 55 57 +2
Lines 2293 2392 +99
Branches 258 271 +13
==========================================
+ Hits 1775 1808 +33
- Misses 488 554 +66
Partials 30 30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
} | ||
resolve(repo.users.canPush.includes(user) || repo.users.canAuthorise.includes(user)); |
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.
resolve(repo.users.canPush.includes(user) || repo.users.canAuthorise.includes(user)); | |
resolve(repo.users?.canPush.includes(user) || repo.users?.canAuthorise.includes(user)); |
The DB clients should make sure that the users element exists (although I think I had to make sure that was happening in #1043, after stumbling over a case where it did not). Doesn't hurt to be defensive here.
@@ -79,19 +79,19 @@ export const deleteRepo = async (name: string) => { | |||
export const isUserPushAllowed = async (name: string, user: string) => { | |||
name = name.toLowerCase(); | |||
user = user.toLowerCase(); | |||
console.log(`checking if user ${user} can push to ${name}`); |
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.
Note that #1043 moves this functions into src/db/index.ts so that it is not duplicated between the clients.
@@ -0,0 +1,52 @@ | |||
const chai = require('chai'); |
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.
Summary
This PR fixes a potential denial-of-service (DoS) vulnerability:
When pushing to an unknown repository, the MongoDB implementation throws a TypeError due to attempting to access properties on a null object:
Root Cause
The file-based database implementation correctly checks for the existence of a repository before accessing its fields. However, the MongoDB implementation does not.
Specifically,
checkUserPushPermission
callsisUserPushAllowed
, which assumes the repository exists. If the repository is not found, accessing its properties throws a TypeError and stops the service.Fix
This PR addresses the issue by:
Adding a guard clause in the MongoDB implementation of
isUserPushAllowed
to handle missing repositories safely.Adds a unit test to verify behaviour when the repository does not exist.