turnstile

package
v0.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package turnstile checks a Cloudflare Turnstile token with the siteverify API, as documented at https://developers.cloudflare.com/turnstile/get-started/server-side-validation/: a form POST of the widget's secret key and the token, answered by a JSON object. The visitor's address, optional, is never sent.

A token is valid once and for 300 seconds, so a check is never retried: a second try of the same token is refused as a duplicate. The secret and the token are never logged nor quoted in an error.

Index

Constants

View Source
const SiteverifyURL = "https://" + siteverifyHost + "/turnstile/v0/siteverify"

SiteverifyURL is the endpoint of the siteverify API.

Variables

This section is empty.

Functions

func Hosts

func Hosts() []string

Hosts returns the hosts a Verifier reaches.

Types

type Submitter

type Submitter interface {
	Submit(ctx context.Context, rawURL, contentType string, body []byte) ([]byte, error)
}

Submitter posts a body and returns the answer; *httpclient.Client is one. Its errors must not quote the body.

type Verifier

type Verifier struct {
	// contains filtered or unexported fields
}

Verifier checks the tokens of one Turnstile widget, served on one hostname.

func New

func New(client Submitter, secret []byte, hostname string) *Verifier

New returns a Verifier posting through client the secret key of the widget, whose valid tokens name hostname.

func NewLive

func NewLive(secret []byte, hostname string) (*Verifier, error)

NewLive returns a Verifier reaching siteverify through an HTTP client allowed on its host only, trying each token once.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, token string) (bool, error)

Verify reports whether token is a valid token of the widget, solved on its hostname. A refused token is false with a nil error; an error means the token could not be checked. The visitor's address is not sent: it is a personal datum, and siteverify does not require it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL