mirror of
https://github.com/privacy-scaling-explorations/p0tion.git
synced 2026-04-21 03:00:07 -04:00
Merge pull request #229 from privacy-scaling-explorations/fix/sybil
feat(sybil): add GH age check
This commit is contained in:
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -29,6 +29,8 @@ GITHUB_MINIMUM_FOLLOWERS="1"
|
||||
GITHUB_MINIMUM_FOLLOWING="5"
|
||||
## Minimum amount of public repos for the GitHub account
|
||||
GITHUB_MINIMUM_PUBLIC_REPOS="2"
|
||||
## Minimum age of the GitHub account (1 month default)
|
||||
GITHUB_MINIMUM_AGE="2592000000"
|
||||
## Personal access token for API rate limiting (no privileges required)
|
||||
GITHUB_ACCESS_TOKEN="YOUR-GITHUB-ACCESS-TOKEN"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user