jsreq

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

internal/local/jsreq

Go host bindings for the arcjet_analyze_js_req WebAssembly component — the same js-req world that arcjet-js (@arcjet/analyze-wasm) and arcjet-py (arcjet._analyze) consume, so all three SDKs make identical local decisions for bot detection, email validation, request filtering, and sensitive-info detection.

Regenerating

bindings.go is generated from js_req.wasm; only imports.go and this README are hand-maintained. js_req.wasm retains its component-type WIT custom section, so gravity reads the js-req world straight from the vendored module — regenerating needs no arcjet monorepo checkout.

From the repo root (after mise install for the pinned gravity — see the top-level mise.toml):

./internal/local/rebuild-bindings.sh

To pull a newer wasm build from a local arcjet monorepo checkout first, then regenerate:

./internal/local/rebuild-bindings.sh --from-monorepo [path-to-arcjet]

The script runs gravity --world js-req and renames the emitted package from js_req to jsreq.

js_req.wasm is the post-wizer, pre-component core module from arcjet-analyze/bindings_js_req/dist/arcjet_analyze_js_req.wasm. wazero speaks core wasm rather than the Component Model, and the wizer.initialize snapshot is load-bearing — without it, bot detection returns "failed to detect bot: user agent parser unavailable" because USER_AGENT_PARSER is populated during init. The retained component-type WIT section adds ~2 KB and is ignored by wazero at runtime.

Documentation

Index

Constants

View Source
const (
	Yes     emailValidatorOverridesValidatorResponse = iota
	No      emailValidatorOverridesValidatorResponse = iota
	Unknown emailValidatorOverridesValidatorResponse = iota
)
View Source
const (
	Verified     verifyBotValidatorResponse = iota
	Spoofed      verifyBotValidatorResponse = iota
	Unverifiable verifyBotValidatorResponse = iota
)
View Source
const (
	Valid   emailValidity = iota
	Invalid emailValidity = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowEmailValidationConfig

type AllowEmailValidationConfig struct {
	RequireTopLevelDomain bool
	AllowDomainLiteral    bool
	Allow                 []string
}

type AllowedBotConfig

type AllowedBotConfig struct {
	Entities         []BotEntity
	SkipCustomDetect bool
}

type BotConfig

type BotConfig interface {
	// contains filtered or unexported methods
}

type BotEntity

type BotEntity = string

type BotResult

type BotResult struct {
	Allowed  []BotEntity
	Denied   []BotEntity
	Verified bool
	Spoofed  bool
}

type Callbacks

type Callbacks struct {
	// DetectSensitiveInfo classifies tokens that the native analyzer didn't
	// recognise. Return nil for a token to leave it unclassified.
	DetectSensitiveInfo func(ctx context.Context, tokens []string) []SensitiveInfoEntity
}

Callbacks lets callers override the default fail-open import implementations. Any nil field uses a built-in default.

Mirrors arcjet-py's `ImportCallbacks` so the user-visible custom-detect hook has parity across SDKs.

type DeniedBotConfig

type DeniedBotConfig struct {
	Entities         []BotEntity
	SkipCustomDetect bool
}

type DenyEmailValidationConfig

type DenyEmailValidationConfig struct {
	RequireTopLevelDomain bool
	AllowDomainLiteral    bool
	Deny                  []string
}

type DetectedSensitiveInfoEntity

type DetectedSensitiveInfoEntity struct {
	Start          uint32
	End            uint32
	IdentifiedType SensitiveInfoEntity
}

type EmailValidationConfig

type EmailValidationConfig interface {
	// contains filtered or unexported methods
}

type EmailValidationResult

type EmailValidationResult struct {
	Validity EmailValidity
	Blocked  []string
}

type EmailValidatorOverridesValidatorResponse

type EmailValidatorOverridesValidatorResponse interface {
	// contains filtered or unexported methods
}

type EmailValidity

type EmailValidity interface {
	// contains filtered or unexported methods
}

type FilterResult

type FilterResult struct {
	Allowed                 bool
	MatchedExpressions      []string
	UndeterminedExpressions []string
}

type IJsReqBotIdentifier

type IJsReqBotIdentifier interface {
	Detect(
		ctx context.Context,
		request string,
	) []BotEntity
}

type IJsReqEmailValidatorOverrides

type IJsReqEmailValidatorOverrides interface {
	IsFreeEmail(
		ctx context.Context,
		domain string,
	) EmailValidatorOverridesValidatorResponse
	IsDisposableEmail(
		ctx context.Context,
		domain string,
	) EmailValidatorOverridesValidatorResponse
	HasMxRecords(
		ctx context.Context,
		domain string,
	) EmailValidatorOverridesValidatorResponse
	HasGravatar(
		ctx context.Context,
		email string,
	) EmailValidatorOverridesValidatorResponse
}

type IJsReqFilterOverrides

type IJsReqFilterOverrides interface {
	IpLookup(
		ctx context.Context,
		ip string,
	) *string
}

type IJsReqSensitiveInformationIdentifier

type IJsReqSensitiveInformationIdentifier interface {
	Detect(
		ctx context.Context,
		tokens []string,
	) []*SensitiveInfoEntity
}

type IJsReqVerifyBot

type IJsReqVerifyBot interface {
	Verify(
		ctx context.Context,
		botId string,
		ip string,
	) VerifyBotValidatorResponse
}

type JsReqFactory

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

func NewFactory

func NewFactory(ctx context.Context, cb Callbacks) (*JsReqFactory, error)

NewFactory compiles the js_req component and wires its host import callbacks, applying fail-open defaults for any callback left unset.

Mirrors arcjet-py's wire_imports and arcjet-js's createCoreImports: callbacks in, a ready-to-instantiate factory out. Keeping the five-interface wiring inside this package means callers never handle the import interfaces individually.

func NewJsReqFactory

func NewJsReqFactory(
	ctx context.Context,
	emailValidatorOverrides IJsReqEmailValidatorOverrides,
	sensitiveInformationIdentifier IJsReqSensitiveInformationIdentifier,
	verifyBot IJsReqVerifyBot,
	botIdentifier IJsReqBotIdentifier,
	filterOverrides IJsReqFilterOverrides,
) (*JsReqFactory, error)

func (*JsReqFactory) Close

func (f *JsReqFactory) Close(ctx context.Context)

func (*JsReqFactory) Instantiate

func (f *JsReqFactory) Instantiate(ctx context.Context) (*JsReqInstance, error)

type JsReqInstance

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

func (*JsReqInstance) Close

func (i *JsReqInstance) Close(ctx context.Context) error

func (*JsReqInstance) DetectBot

func (i *JsReqInstance) DetectBot(
	ctx context.Context,
	request string,
	options interface{},
) (BotResult, error)

func (*JsReqInstance) DetectSensitiveInfo

func (i *JsReqInstance) DetectSensitiveInfo(
	ctx context.Context,
	content string,
	options SensitiveInfoConfig,
) SensitiveInfoResult

func (*JsReqInstance) GenerateFingerprint

func (i *JsReqInstance) GenerateFingerprint(
	ctx context.Context,
	request string,
	characteristics []string,
) (string, error)

func (*JsReqInstance) IsValidEmail

func (i *JsReqInstance) IsValidEmail(
	ctx context.Context,
	candidate string,
	options interface{},
) (EmailValidationResult, error)

func (*JsReqInstance) MatchFilters

func (i *JsReqInstance) MatchFilters(
	ctx context.Context,
	request string,
	localFields string,
	expressions []string,
	allowIfMatch bool,
) (FilterResult, error)

func (*JsReqInstance) ValidateCharacteristics

func (i *JsReqInstance) ValidateCharacteristics(
	ctx context.Context,
	request string,
	characteristics []string,
) error

type SensitiveInfoConfig

type SensitiveInfoConfig struct {
	Entities          SensitiveInfoEntities
	ContextWindowSize *uint32
	SkipCustomDetect  bool
}

type SensitiveInfoEntities

type SensitiveInfoEntities interface {
	// contains filtered or unexported methods
}

type SensitiveInfoEntitiesAllow

type SensitiveInfoEntitiesAllow struct {
	Value []SensitiveInfoEntity
}

type SensitiveInfoEntitiesDeny

type SensitiveInfoEntitiesDeny struct {
	Value []SensitiveInfoEntity
}

type SensitiveInfoEntity

type SensitiveInfoEntity interface {
	// contains filtered or unexported methods
}

type SensitiveInfoEntityCreditCardNumber

type SensitiveInfoEntityCreditCardNumber struct{}

type SensitiveInfoEntityCustom

type SensitiveInfoEntityCustom struct {
	Value string
}

type SensitiveInfoEntityEmail

type SensitiveInfoEntityEmail struct{}

type SensitiveInfoEntityIpAddress

type SensitiveInfoEntityIpAddress struct{}

type SensitiveInfoEntityPhoneNumber

type SensitiveInfoEntityPhoneNumber struct{}

type SensitiveInfoResult

type SensitiveInfoResult struct {
	Allowed []DetectedSensitiveInfoEntity
	Denied  []DetectedSensitiveInfoEntity
}

type VerifyBotValidatorResponse

type VerifyBotValidatorResponse interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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