Honeytrap (Honeytrap v0.1.0)

Copy Markdown View Source

Public API for arming and rendering honeypot fields.

Three helpers cover the render side of the story:

  • arm/2 stores a timestamp on the session when a form is shown.
  • field/2 renders the invisible honeypot input.
  • signals_field/1 renders a hidden input plus a small script that collects passive interaction signals.

The submission side lives in Honeytrap.Plug.

Summary

Functions

Arms the honeytrap for name by storing a timestamp on the session.

Renders an invisible honeypot input under name.

Renders the signals field plus its companion script.

Functions

arm(conn, name)

Arms the honeytrap for name by storing a timestamp on the session.

Call this from the controller action that renders the form. The timestamp is later used by Honeytrap.Plug to detect submissions that arrived too quickly.

field(name, html_attrs \\ [])

Renders an invisible honeypot input under name.

Returns a {:safe, iodata} tuple ready to be embedded in a template. The input is hidden with inline styles by default and carries attributes that discourage keyboard focus and assistive tech interaction.

Pass a :class or :style in html_attrs to hide the input your own way. Any other options are merged onto the tag.

signals_field(html_attrs \\ [])

Renders the signals field plus its companion script.

Returns a {:safe, iodata} tuple ready to be embedded in a template. The hidden input carries the JSON blob populated by the script, which watches the form for mouse, touch, scroll, keyboard, and focus events.

Any options in html_attrs are merged onto the input tag. Pass :name to override the default input name.