Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stricter CSP with nonce in Honeypot input #411

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Refactor HoneypotInputs component to accept className prop and improv…
…e type definitions
  • Loading branch information
sergiodxa committed Jan 20, 2025
commit 99a5ae1410b94f065f156edb6b984da0098e55b1
26 changes: 16 additions & 10 deletions src/react/honeypot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ const HoneypotContext = React.createContext<HoneypotContextType>({});
export function HoneypotInputs({
label = "Please leave this field blank",
nonce,
}: {
label?: string;
nonce?: string;
}) {
className = "__honeypot_inputs",
}: HoneypotInputs.Props) {
let context = React.useContext(HoneypotContext);

let {
Expand All @@ -21,12 +19,8 @@ export function HoneypotInputs({
} = context;

return (
<div
id={`${nameFieldName}_wrap`}
className="__honeypot_inputs"
aria-hidden="true"
>
<style nonce={nonce}>{`.__honeypot_inputs { display: none; }`}</style>
<div id={`${nameFieldName}_wrap`} className={className} aria-hidden="true">
<style nonce={nonce}>{".__honeypot_inputs { display: none; }"}</style>
<label htmlFor={nameFieldName}>{label}</label>
<input
id={nameFieldName}
Expand Down Expand Up @@ -54,6 +48,18 @@ export function HoneypotInputs({
);
}

export namespace HoneypotInputs {
export type Props = {
label?: string;
nonce?: string;
/**
* The classname used to link the Honeypot input with the CSS that hides it.
* @default "__honeypot_inputs"
*/
className?: string;
};
}

export type HoneypotProviderProps = HoneypotContextType & {
children: React.ReactNode;
};
Expand Down