|
| 1 | +diff --git a/node_modules/remix-utils/build/react/honeypot-inputs.js b/node_modules/remix-utils/build/react/honeypot-inputs.js |
| 2 | +index 9b2aabb..fb47966 100644 |
| 3 | +--- a/node_modules/remix-utils/build/react/honeypot-inputs.js |
| 4 | ++++ b/node_modules/remix-utils/build/react/honeypot-inputs.js |
| 5 | +@@ -1,42 +1,47 @@ |
| 6 | +-import * as React from "react"; |
| 7 | +-import { useRouteLoaderData } from "@remix-run/react"; |
| 8 | ++import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 9 | ++import { createContext, useContext } from "react"; |
| 10 | ++const HoneyPotContext = createContext(null); |
| 11 | + export function HoneypotInputs() { |
| 12 | +- let rootLoaderData = useRouteLoaderData("root"); |
| 13 | +- if (!rootLoaderData) throw new Error("Missing loader data from root"); |
| 14 | +- if (!rootLoaderData.nameFieldName) { |
| 15 | +- throw new Error("Missing Honeypot's nameFieldName on root loader data"); |
| 16 | +- } |
| 17 | +- if (!rootLoaderData.validFromFieldName) { |
| 18 | +- throw new Error( |
| 19 | +- "Missing Honeypot's validFromFieldName on root loader data" |
| 20 | +- ); |
| 21 | +- } |
| 22 | +- if (!rootLoaderData.encryptedValidFrom) { |
| 23 | +- throw new Error( |
| 24 | +- "Missing Honeypot's encryptedValidFrom on root loader data" |
| 25 | +- ); |
| 26 | +- } |
| 27 | +- return React.createElement( |
| 28 | +- "div", |
| 29 | +- { |
| 30 | +- id: `${rootLoaderData.nameFieldName}_wrap`, |
| 31 | +- style: { display: "none" }, |
| 32 | +- "aria-hidden": "true", |
| 33 | ++ const {nameFieldName, validFromFieldName, encryptedValidFrom} = useContext(HoneyPotContext); |
| 34 | ++ return _jsxs("div", { |
| 35 | ++ id: `${nameFieldName}_wrap`, |
| 36 | ++ style: { display: "none" }, |
| 37 | ++ "aria-hidden": "true", |
| 38 | ++ children: [ |
| 39 | ++ _jsx("label", { |
| 40 | ++ htmlFor: nameFieldName, |
| 41 | ++ children: "Please leave this field blank", |
| 42 | ++ }), |
| 43 | ++ _jsx("input", { |
| 44 | ++ id: nameFieldName, |
| 45 | ++ name: nameFieldName, |
| 46 | ++ type: "text", |
| 47 | ++ defaultValue: "", |
| 48 | ++ autoComplete: "off", |
| 49 | ++ tabIndex: -1, |
| 50 | ++ }), |
| 51 | ++ _jsx("label", { |
| 52 | ++ htmlFor: validFromFieldName, |
| 53 | ++ children: "Please leave this field blank", |
| 54 | ++ }), |
| 55 | ++ _jsx("input", { |
| 56 | ++ name: validFromFieldName, |
| 57 | ++ type: "text", |
| 58 | ++ value: encryptedValidFrom, |
| 59 | ++ readOnly: true, |
| 60 | ++ autoComplete: "off", |
| 61 | ++ tabIndex: -1, |
| 62 | ++ }), |
| 63 | ++ ], |
| 64 | ++ }); |
| 65 | ++} |
| 66 | ++export function HoneypotProvider({children, nameFieldName, validFromFieldName, encryptedValidFrom}) { |
| 67 | ++ return _jsx(HoneyPotContext.Provider, { |
| 68 | ++ value: { |
| 69 | ++ nameFieldName, |
| 70 | ++ validFromFieldName, |
| 71 | ++ encryptedValidFrom, |
| 72 | + }, |
| 73 | +- React.createElement("input", { |
| 74 | +- id: rootLoaderData.nameFieldName, |
| 75 | +- name: rootLoaderData.nameFieldName, |
| 76 | +- type: "text", |
| 77 | +- defaultValue: "", |
| 78 | +- autoComplete: "off", |
| 79 | +- tabIndex: -1, |
| 80 | +- }), |
| 81 | +- React.createElement("input", { |
| 82 | +- name: rootLoaderData.validFromFieldName, |
| 83 | +- type: "text", |
| 84 | +- value: rootLoaderData.encryptedValidFrom, |
| 85 | +- autoComplete: "off", |
| 86 | +- tabIndex: -1, |
| 87 | +- }) |
| 88 | +- ); |
| 89 | ++ children: children, |
| 90 | ++ }); |
| 91 | + } |
| 92 | +diff --git a/node_modules/remix-utils/build/server/honeypot.d.ts b/node_modules/remix-utils/build/server/honeypot.d.ts |
| 93 | +index d1b2154..eb334b3 100644 |
| 94 | +--- a/node_modules/remix-utils/build/server/honeypot.d.ts |
| 95 | ++++ b/node_modules/remix-utils/build/server/honeypot.d.ts |
| 96 | +@@ -7,7 +7,6 @@ export interface HonetpotConfig { |
| 97 | + randomizeNameFieldName?: boolean; |
| 98 | + nameFieldName?: string; |
| 99 | + validFromFieldName?: string; |
| 100 | +- validFromTimestamp?: number; |
| 101 | + encryptionSeed?: string; |
| 102 | + } |
| 103 | + export declare class SpamError extends Error {} |
| 104 | +@@ -15,11 +14,10 @@ export declare class Honeypot { |
| 105 | + protected config: HonetpotConfig; |
| 106 | + private generatedEncryptionSeed; |
| 107 | + constructor(config?: HonetpotConfig); |
| 108 | +- getInputProps(): HoneypotInputProps; |
| 109 | ++ getInputProps(config?: {validFromTimestamp?: Date}): HoneypotInputProps; |
| 110 | + check(formData: FormData): void; |
| 111 | + protected get nameFieldName(): string; |
| 112 | + protected get validFromFieldName(): string; |
| 113 | +- protected get validFromTimestamp(): number; |
| 114 | + protected get encryptionSeed(): string; |
| 115 | + protected getRandomizedNameFieldName( |
| 116 | + nameFieldName: string, |
| 117 | +diff --git a/node_modules/remix-utils/build/server/honeypot.js b/node_modules/remix-utils/build/server/honeypot.js |
| 118 | +index 1a876c5..a71adeb 100644 |
| 119 | +--- a/node_modules/remix-utils/build/server/honeypot.js |
| 120 | ++++ b/node_modules/remix-utils/build/server/honeypot.js |
| 121 | +@@ -6,15 +6,15 @@ export class Honeypot { |
| 122 | + constructor(config = {}) { |
| 123 | + this.config = config; |
| 124 | + } |
| 125 | +- getInputProps() { |
| 126 | ++ getInputProps({validFromTimestamp = new Date()} = {}) { |
| 127 | + return { |
| 128 | + nameFieldName: this.nameFieldName, |
| 129 | + validFromFieldName: this.validFromFieldName, |
| 130 | +- encryptedValidFrom: this.encrypt(this.validFromTimestamp.toString()), |
| 131 | ++ encryptedValidFrom: this.encrypt(validFromTimestamp.toString()), |
| 132 | + }; |
| 133 | + } |
| 134 | + check(formData) { |
| 135 | +- let nameFieldName = this.config.nameFieldName ?? "honeypot"; |
| 136 | ++ let nameFieldName = this.config.nameFieldName ?? "name__confirm"; |
| 137 | + if (this.config.randomizeNameFieldName) { |
| 138 | + let actualName = this.getRandomizedNameFieldName(nameFieldName, formData); |
| 139 | + if (actualName) nameFieldName = actualName; |
| 140 | +@@ -25,7 +25,7 @@ export class Honeypot { |
| 141 | + } |
| 142 | + let honeypotValue = formData.get(nameFieldName); |
| 143 | + if (honeypotValue !== "") throw new SpamError("Honeypot input not empty"); |
| 144 | +- if (!this.config.validFromTimestamp) return; |
| 145 | ++ if (!this.validFromFieldName) return; |
| 146 | + let validFrom = formData.get(this.validFromFieldName); |
| 147 | + if (!validFrom) throw new SpamError("Missing honeypot valid from input"); |
| 148 | + let time = this.decrypt(validFrom); |
| 149 | +@@ -38,15 +38,12 @@ export class Honeypot { |
| 150 | + } |
| 151 | + } |
| 152 | + get nameFieldName() { |
| 153 | +- let fieldName = this.config.nameFieldName ?? "honeypot"; |
| 154 | ++ let fieldName = this.config.nameFieldName ?? "name__confirm"; |
| 155 | + if (!this.config.randomizeNameFieldName) return fieldName; |
| 156 | + return `${fieldName}_${this.randomValue()}`; |
| 157 | + } |
| 158 | + get validFromFieldName() { |
| 159 | +- return this.config.validFromFieldName ?? "honeypot_from"; |
| 160 | +- } |
| 161 | +- get validFromTimestamp() { |
| 162 | +- return this.config.validFromTimestamp ?? Date.now(); |
| 163 | ++ return this.config.validFromFieldName ?? "from__confirm"; |
| 164 | + } |
| 165 | + get encryptionSeed() { |
| 166 | + return this.config.encryptionSeed ?? this.generatedEncryptionSeed; |
0 commit comments