Skip to content

Commit

Permalink
use passport score as strict requirement for session start
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed May 1, 2024
1 parent fed6a77 commit 8e5df1f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 40 deletions.
2 changes: 1 addition & 1 deletion faucet-client/src/common/FaucetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface IPassportModuleConfig {
manualVerification: boolean;
stampScoring: {[stamp: string]: number};
boostFactor: {[score: number]: number};
overrideScores: [number, number];
overrideScores: [number, number, number];
guestRefresh: number | boolean;
}

Expand Down
87 changes: 49 additions & 38 deletions faucet-client/src/components/frontpage/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ export class FrontPage extends React.PureComponent<IFrontPageProps, IFrontPageSt
try {
let sessionInfo = await this.props.faucetContext.faucetApi.startSession(inputData);
if(sessionInfo.status === "failed") {
if(sessionInfo.failedCode == "IPINFO_RESTRICTION" && this.props.faucetConfig.modules["passport"] && this.props.faucetConfig.modules["passport"].guestRefresh !== false && sessionInfo.failedData["ipflags"]) {
let canStartWithScore = false;
let requiredScore = 0;
let ipflags: string[] = [];
let canStartWithScore = false;
let requiredScore = 0;
let ipflags: string[] = [];

if(sessionInfo.failedCode == "IPINFO_RESTRICTION" && this.props.faucetConfig.modules["passport"] && this.props.faucetConfig.modules["passport"].guestRefresh !== false && sessionInfo.failedData["ipflags"]) {
canStartWithScore = true;
if(sessionInfo.failedData["ipflags"][0] && this.props.faucetConfig.modules["passport"].overrideScores[0] > 0) {
canStartWithScore = true;
ipflags.push("hosting");
Expand All @@ -121,43 +122,53 @@ export class FrontPage extends React.PureComponent<IFrontPageProps, IFrontPageSt
if(this.props.faucetConfig.modules["passport"].overrideScores[1] > requiredScore)
requiredScore = this.props.faucetConfig.modules["passport"].overrideScores[1];
}
}
else if(sessionInfo.failedCode == "PASSPORT_SCORE" && this.props.faucetConfig.modules["passport"] && this.props.faucetConfig.modules["passport"].guestRefresh !== false) {
requiredScore = this.props.faucetConfig.modules["passport"].overrideScores[2];
canStartWithScore = true;
}

if(canStartWithScore) {
// special case, the session is denied as the users IP is flagged as hosting/proxy range.
// however, the faucet allows skipping this check for passport trusted wallets
// show a dialog that shows the score & allows refreshing the passport to meet the requirement


this.props.faucetContext.showDialog({
title: "Could not start session",
size: "lg",
body: (
<div className='passport-dialog error-dialog'>
<PassportInfo
pageContext={this.props.faucetContext}
faucetConfig={this.props.faucetConfig}
targetAddr={sessionInfo.failedData["address"]}
refreshFn={(passportScore) => {

}}
>
<div>
<div className='alert alert-danger'>The faucet denied starting a session because your IP Address is marked as {ipflags.join(" and ")} range.</div>
<div className="boost-descr">
However, you can verify your unique identity using <a href="https://passport.gitcoin.co/#/dashboard" target="_blank">Gitcoin Passport</a>.
</div>
<div className="boost-descr2">
Ensure your provided address achieves a minimum score of {requiredScore} to bypass the IP check and initiate a session.
</div>
</div>
</PassportInfo>
</div>
),
closeButton: { caption: "Close" },
});
if(canStartWithScore) {
// special case, the session is denied as the users IP is flagged as hosting/proxy range.
// however, the faucet allows skipping this check for passport trusted wallets
// show a dialog that shows the score & allows refreshing the passport to meet the requirement

throw null; // throw without dialog
let errMsg: string;
if(ipflags.length > 0) {
errMsg = "The faucet denied starting a session because your IP Address is marked as " + ipflags.join(" and ") + " range.";
} else {
errMsg = "The faucet denied starting a session because your wallet does not meet the minimum passport score.";
}

this.props.faucetContext.showDialog({
title: "Could not start session",
size: "lg",
body: (
<div className='passport-dialog error-dialog'>
<PassportInfo
pageContext={this.props.faucetContext}
faucetConfig={this.props.faucetConfig}
targetAddr={sessionInfo.failedData["address"]}
refreshFn={(passportScore) => {

}}
>
<div>
<div className='alert alert-danger'>{errMsg}</div>
<div className="boost-descr">
You can verify your unique identity and increase your score using <a href="https://passport.gitcoin.co/#/dashboard" target="_blank">Gitcoin Passport</a>.
</div>
<div className="boost-descr2">
Ensure your provided address achieves a minimum score of {requiredScore} to initiate a session.
</div>
</div>
</PassportInfo>
</div>
),
closeButton: { caption: "Close" },
});

throw null; // throw without dialog
}

throw (sessionInfo.failedCode ? "[" + sessionInfo.failedCode + "] " : "") + sessionInfo.failedReason;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/passport/PassportConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IPassportConfig extends IBaseModuleConfig {
stampDeduplicationTime: number;
stampScoring: {[stamp: string]: number};
boostFactor: {[score: number]: number};
requireMinScore: number;
skipProxyCheckScore: number;
skipHostingCheckScore: number;
allowGuestRefresh: boolean;
Expand All @@ -25,6 +26,7 @@ export const defaultConfig: IPassportConfig = {
stampDeduplicationTime: 86400 * 3,
stampScoring: {},
boostFactor: {},
requireMinScore: 0,
skipProxyCheckScore: 0,
skipHostingCheckScore: 0,
allowGuestRefresh: false,
Expand Down
10 changes: 9 additions & 1 deletion src/modules/passport/PassportModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IncomingMessage } from 'http';
import { SessionManager } from '../../session/SessionManager.js';
import { PassportDB } from './PassportDB.js';
import { FaucetDatabase } from '../../db/FaucetDatabase.js';
import { FaucetError } from '../../common/FaucetError.js';

export class PassportModule extends BaseModule<IPassportConfig> {
protected readonly moduleDefaultConfig = defaultConfig;
Expand All @@ -29,7 +30,7 @@ export class PassportModule extends BaseModule<IPassportConfig> {
manualVerification: (this.moduleConfig.trustedIssuers && this.moduleConfig.trustedIssuers.length > 0),
stampScoring: this.moduleConfig.stampScoring,
boostFactor: this.moduleConfig.boostFactor,
overrideScores: [ this.moduleConfig.skipHostingCheckScore, this.moduleConfig.skipProxyCheckScore ],
overrideScores: [ this.moduleConfig.skipHostingCheckScore, this.moduleConfig.skipProxyCheckScore, this.moduleConfig.requireMinScore ],
guestRefresh: this.moduleConfig.allowGuestRefresh ? (this.moduleConfig.guestRefreshCooldown > 0 ? this.moduleConfig.guestRefreshCooldown : this.moduleConfig.refreshCooldown) : false,
};
}
Expand Down Expand Up @@ -86,6 +87,13 @@ export class PassportModule extends BaseModule<IPassportConfig> {
if(this.moduleConfig.skipProxyCheckScore > 0 && score.score >= this.moduleConfig.skipProxyCheckScore) {
session.setSessionData("ipinfo.override_proxy", false);
}
if(this.moduleConfig.requireMinScore > 0 && score.score < this.moduleConfig.requireMinScore) {
let err = new FaucetError("PASSPORT_SCORE", "You need a passport score of at least " + this.moduleConfig.requireMinScore + " to use this faucet.");
err.data = {
"address": session.getTargetAddr(),
};
throw err;
}
}

private async processSessionInfo(session: FaucetSession, moduleState: any): Promise<void> {
Expand Down

0 comments on commit 8e5df1f

Please sign in to comment.