Skip to content

Commit 66bbbcf

Browse files
committed
simplify usage of honey input
move nonce to context remove className props as customization not needed
1 parent e343718 commit 66bbbcf

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"node": ">=20.0.0"
77
},
88
"type": "module",
9-
"funding": [
10-
"https://github.com/sponsors/sergiodxa"
11-
],
9+
"funding": ["https://github.com/sponsors/sergiodxa"],
1210
"exports": {
1311
"./package.json": "./package.json",
1412
"./promise": {
@@ -258,9 +256,5 @@
258256
"dependencies": {
259257
"type-fest": "^4.33.0"
260258
},
261-
"files": [
262-
"build",
263-
"package.json",
264-
"README.md"
265-
]
259+
"files": ["build", "package.json", "README.md"]
266260
}

src/react/honeypot.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ const HoneypotContext = React.createContext<HoneypotContextType>({});
77

88
export function HoneypotInputs({
99
label = "Please leave this field blank",
10-
nonce,
11-
className = "__honeypot_inputs",
1210
}: HoneypotInputs.Props) {
1311
let context = React.useContext(HoneypotContext);
1412

1513
let {
14+
nonce,
1615
nameFieldName = "name__confirm",
1716
validFromFieldName = "from__confirm",
1817
encryptedValidFrom,
1918
} = context;
2019

2120
return (
22-
<div id={`${nameFieldName}_wrap`} className={className} aria-hidden="true">
21+
<div
22+
id={`${nameFieldName}_wrap`}
23+
className="__honeypot_inputs"
24+
aria-hidden="true"
25+
>
2326
<style nonce={nonce}>{".__honeypot_inputs { display: none; }"}</style>
2427
<label htmlFor={nameFieldName}>{label}</label>
2528
<input
@@ -49,15 +52,7 @@ export function HoneypotInputs({
4952
}
5053

5154
export namespace HoneypotInputs {
52-
export type Props = {
53-
label?: string;
54-
nonce?: string;
55-
/**
56-
* The classname used to link the Honeypot input with the CSS that hides it.
57-
* @default "__honeypot_inputs"
58-
*/
59-
className?: string;
60-
};
55+
export type Props = { label?: string };
6156
}
6257

6358
export type HoneypotProviderProps = HoneypotContextType & {

src/server/honeypot.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { decrypt, encrypt, randomString } from "../common/crypto.js";
22

33
export interface HoneypotInputProps {
4+
/**
5+
* The nonce for the style tag that will be used to hide the honeypot input.
6+
*/
7+
nonce?: string;
48
/**
59
* The name expected to be used by the honeypot input field.
610
*/
@@ -21,6 +25,10 @@ export interface HoneypotConfig {
2125
* name will be different for each request.
2226
*/
2327
randomizeNameFieldName?: boolean;
28+
/**
29+
* The nonce for the style tag that will be used to hide the honeypot input.
30+
*/
31+
nonce?: string;
2432
/**
2533
* The name of the field that will be used for the honeypot input.
2634
*/
@@ -71,6 +79,7 @@ export class Honeypot {
7179
validFromTimestamp = Date.now(),
7280
} = {}): Promise<HoneypotInputProps> {
7381
return {
82+
nonce: this.config.nonce,
7483
nameFieldName: this.nameFieldName,
7584
validFromFieldName: this.validFromFieldName,
7685
encryptedValidFrom: await this.encrypt(validFromTimestamp.toString()),

0 commit comments

Comments
 (0)