Skip to content

Commit

Permalink
feat(sybil): add GH age check
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Nov 2, 2023
1 parent 8bb9489 commit bcb670c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/actions/src/helpers/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const getGitHubStats = async (user: string): Promise<any> => {
following: jsonData.following,
followers: jsonData.followers,
publicRepos: jsonData.public_repos,
avatarUrl: jsonData.avatar_url
avatarUrl: jsonData.avatar_url,
age: jsonData.created_at
}

return data
Expand All @@ -38,19 +39,21 @@ export const githubReputation = async (
userLogin: string,
minimumAmountOfFollowing: number,
minimumAmountOfFollowers: number,
minimumAmountOfPublicRepos: number
minimumAmountOfPublicRepos: number,
minimumAge: number
): Promise<any> => {
if (!process.env.GITHUB_ACCESS_TOKEN)
throw new Error(
"The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again."
)

const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin)
const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin)

if (
following < minimumAmountOfFollowing ||
publicRepos < minimumAmountOfPublicRepos ||
followers < minimumAmountOfFollowers
followers < minimumAmountOfFollowers ||
new Date(age) > new Date(Date.now() - minimumAge)
)
return {
reputable: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/functions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const registerAuthUser = functions
user.providerData[0].uid,
vars.minimumFollowing,
vars.minimumFollowers,
vars.minimumPublicRepos
vars.minimumPublicRepos,
vars.minimumAge
)
if (!reputable) {
// Delete user
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ export const getGitHubVariables = (): any => {
if (
!process.env.GITHUB_MINIMUM_FOLLOWERS ||
!process.env.GITHUB_MINIMUM_FOLLOWING ||
!process.env.GITHUB_MINIMUM_PUBLIC_REPOS
!process.env.GITHUB_MINIMUM_PUBLIC_REPOS ||
!process.env.GITHUB_MINIMUM_AGE
)
logAndThrowError(COMMON_ERRORS.CM_WRONG_CONFIGURATION)

return {
minimumFollowers: Number(process.env.GITHUB_MINIMUM_FOLLOWERS),
minimumFollowing: Number(process.env.GITHUB_MINIMUM_FOLLOWING),
minimumPublicRepos: Number(process.env.GITHUB_MINIMUM_PUBLIC_REPOS)
minimumPublicRepos: Number(process.env.GITHUB_MINIMUM_PUBLIC_REPOS),
minimumAge: Number(process.env.GITHUB_MINIMUM_AGE)
}
}

Expand Down

0 comments on commit bcb670c

Please sign in to comment.