Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/quiet-rabbits-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@prosopo/procaptcha-frictionless": patch
"@prosopo/types-database": patch
"@prosopo/provider": patch
"@prosopo/types": patch
"@prosopo/api": patch
---

Adding invisible mode to session data

6 changes: 5 additions & 1 deletion packages/api/src/api/ProviderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
type DecisionMachineLanguage,
type DecisionMachineRuntime,
type DecisionMachineScope,
type GetFrictionlessCaptchaChallengeRequestBodyOutput,
type GetFrictionlessCaptchaResponse,
type GetPowCaptchaChallengeRequestBodyType,
type GetPowCaptchaResponse,
type IUserSettings,
type ImageVerificationResponse,
type ModeEnum,
type PowCaptchaSolutionResponse,
type ProcaptchaToken,
type Provider,
Expand Down Expand Up @@ -207,12 +209,14 @@ export default class ProviderApi
headHash: string,
dapp: string,
user: string,
mode?: ModeEnum,
): Promise<GetFrictionlessCaptchaResponse> {
const body = {
const body: GetFrictionlessCaptchaChallengeRequestBodyOutput = {
[ApiParams.token]: token,
[ApiParams.headHash]: headHash,
[ApiParams.dapp]: dapp,
[ApiParams.user]: user,
...(mode && { [ApiParams.mode]: mode }),
};
return this.post(ClientApiPaths.GetFrictionlessCaptchaChallenge, body, {
headers: {
Expand Down
1 change: 1 addition & 0 deletions packages/procaptcha-frictionless/src/customDetectBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const customDetectBot: BotDetectionFunction = async (
detectionResult.encryptHeadHash,
config.account.address,
userAccount.account.address,
config.mode,
),
10000, // 10 second timeout
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CaptchaType,
ContextType,
GetFrictionlessCaptchaChallengeRequestBody,
ModeEnum,
} from "@prosopo/types";
import type { ScoreComponents } from "@prosopo/types";
import type { ProviderEnvironment } from "@prosopo/types-env";
Expand Down Expand Up @@ -76,9 +77,11 @@ export default (
});

const tasks = new Tasks(env, req.logger);
const { token, headHash, dapp, user } =
const { token, headHash, dapp, user, mode } =
GetFrictionlessCaptchaChallengeRequestBody.parse(req.body);
const normalizedIp = normalizeRequestIp(req.ip, req.logger);
const sessionMode =
mode === ModeEnum.invisible ? ModeEnum.invisible : undefined;

req.logger.info(() => ({
msg: "Frictionless handler entry",
Expand All @@ -91,6 +94,7 @@ export default (
ja4: req.ja4,
path: req.path,
method: req.method,
...(sessionMode && { mode: sessionMode }),
},
}));

Expand All @@ -116,6 +120,7 @@ export default (
iFrame: false,
decryptedHeadHash: "",
siteKey: dapp,
mode: sessionMode,
}),
);
}
Expand Down Expand Up @@ -284,6 +289,7 @@ export default (
siteKey: dapp,
countryCode,
headers: flatHeaders,
mode: sessionMode,
});

// Check if the IP address is blocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type ContextType,
type GetFrictionlessCaptchaResponse,
type KeyringPair,
type ModeEnum,
type ProsopoConfigOutput,
type RequestHeaders,
type ScoreComponents,
Expand Down Expand Up @@ -97,6 +98,7 @@ export class FrictionlessManager extends CaptchaManager {
geolocation: params.geolocation,
countryCode: params.countryCode,
headers: params.headers,
mode: params.mode,
};
}

Expand Down Expand Up @@ -131,6 +133,7 @@ export class FrictionlessManager extends CaptchaManager {
deleted?: boolean,
countryCode?: string,
headers?: RequestHeaders,
mode?: ModeEnum,
): Promise<Session> {
const sessionRecord: Session = {
sessionId: `${getSessionIDPrefix(this.config.host)}-${uuidv4()}`,
Expand All @@ -142,6 +145,7 @@ export class FrictionlessManager extends CaptchaManager {
providerSelectEntropy,
ipAddress,
captchaType,
mode,
solvedImagesCount,
powDifficulty,
userSitekeyIpHash,
Expand Down Expand Up @@ -224,6 +228,7 @@ export class FrictionlessManager extends CaptchaManager {
undefined,
effectiveParams.countryCode,
effectiveParams.headers,
effectiveParams.mode,
);

return {
Expand Down Expand Up @@ -271,6 +276,7 @@ export class FrictionlessManager extends CaptchaManager {
undefined,
effectiveParams.countryCode,
effectiveParams.headers,
effectiveParams.mode,
);
return {
[ApiParams.captchaType]: CaptchaType.pow,
Expand Down Expand Up @@ -317,6 +323,7 @@ export class FrictionlessManager extends CaptchaManager {
true,
effectiveParams.countryCode,
effectiveParams.headers,
effectiveParams.mode,
);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/types-database/src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
DecisionMachineScope,
type DetectorKey,
IpAddressType,
ModeEnum,
type PendingImageCaptchaRequest,
type PoWCaptchaStored,
type Session,
Expand Down Expand Up @@ -370,6 +371,7 @@ export const SessionRecordSchema = new Schema<SessionRecord>({
providerSelectEntropy: { type: Number, required: true },
ipAddress: CompositeIpAddressRecordSchemaObj,
captchaType: { type: String, enum: CaptchaType, required: true },
mode: { type: String, enum: ModeEnum, required: false },
solvedImagesCount: { type: Number, required: false },
powDifficulty: { type: Number, required: false },
storedAtTimestamp: { type: Date, required: false, expires: ONE_DAY },
Expand All @@ -382,8 +384,8 @@ export const SessionRecordSchema = new Schema<SessionRecord>({
siteKey: { type: String, required: false },
reason: { type: String, required: false },
blocked: { type: Boolean, required: false },
geolocation: { type: String, required: false },
countryCode: { type: String, required: false },
geolocation: { type: String, required: false },
headers: { type: Object, required: false },
result: {
type: new Schema(
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/api/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ export enum ApiParams {
decisionMachineCaptchaType = "decisionMachineCaptchaType",
salt = "salt",
email = "email",
mode = "mode",
}
2 changes: 2 additions & 0 deletions packages/types/src/provider/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
DecisionMachineCaptchaTypeSchema,
} from "../client/captchaType/captchaType.js";
import { ClientSettingsSchema, Tier } from "../client/index.js";
import { ModeEnum } from "../config/config.js";
import {
DEFAULT_IMAGE_MAX_VERIFIED_TIME_CACHED,
DEFAULT_POW_CAPTCHA_VERIFIED_TIMEOUT,
Expand Down Expand Up @@ -403,6 +404,7 @@ export const GetFrictionlessCaptchaChallengeRequestBody = object({
[ApiParams.token]: string(),
[ApiParams.user]: string(),
[ApiParams.headHash]: string(),
[ApiParams.mode]: nativeEnum(ModeEnum).optional(),
});

export type GetFrictionlessCaptchaChallengeRequestBodyOutput = output<
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/provider/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import type { IPInfoResponse } from "../api/ipapi.js";
import { CaptchaType } from "../client/index.js";
import type { ContextType } from "../client/settings.js";
import { ModeEnum } from "../config/config.js";
import {
type CaptchaResult,
type CaptchaSolution,
Expand Down Expand Up @@ -250,6 +251,7 @@ export const SessionSchema = object({
providerSelectEntropy: number(),
ipAddress: CompositeIpAddressSchema,
captchaType: nativeEnum(CaptchaType),
mode: nativeEnum(ModeEnum).optional(),
solvedImagesCount: number().optional(),
powDifficulty: number().optional(),
storedAtTimestamp: date().optional(),
Expand Down Expand Up @@ -285,6 +287,7 @@ export type Session = {
providerSelectEntropy: number;
ipAddress: CompositeIpAddress;
captchaType: CaptchaType;
mode?: ModeEnum;
solvedImagesCount?: number;
powDifficulty?: number;
storedAtTimestamp?: Date;
Expand Down
Loading