fingerprint

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FingerprintKey = "_fingerprint_"
)

Variables

This section is empty.

Functions

func SessionFingerprintMiddleware

func SessionFingerprintMiddleware(generator *Generator, strict bool) gin.HandlerFunc

func UpdateFingerprint

func UpdateFingerprint(s *session.SessionData, fp *DeviceFingerprint)

UpdateFingerprint stores or updates fingerprint in the session this should be called during the login process

func ValidateFingerprint

func ValidateFingerprint(fp *DeviceFingerprint) error

ValidateFingerprint validates a fingerprint structure

Types

type Config

type Config struct {
	// IncludeUserAgent determines if User-Agent header should be included
	IncludeUserAgent bool `json:"includeUserAgent"`

	// IncludeAcceptHeaders determines if Accept-* headers should be included
	IncludeAcceptHeaders bool `json:"includeAcceptHeaders"`

	// IncludeTimezone determines if timezone should be included
	IncludeTimezone bool `json:"includeTimezone"`

	// IncludeIPAddress determines if IP address should be included
	IncludeIPAddress bool `json:"includeIPAddress"`

	// UseIPSubnet determines if IP subnet should be used instead of exact IP
	UseIPSubnet bool `json:"useIPSubnet"`

	// IncludeGeolocation determines if country detection should be included
	IncludeGeolocation bool `json:"includeGeolocation"`
}

Config holds configuration for device fingerprinting

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a default fingerprinting configuration

func NewPrivacyFriendlyConfig

func NewPrivacyFriendlyConfig() *Config

NewPrivacyFriendlyConfig creates a privacy-friendly configuration

func NewStrictConfig

func NewStrictConfig() *Config

NewStrictConfig creates a strict fingerprinting configuration

type DeviceFingerprint

type DeviceFingerprint struct {
	UserAgent   string `json:"user_agent"`
	AcceptLang  string `json:"accept_language"`
	AcceptEnc   string `json:"accept_encoding"`
	IPAddress   string `json:"ip_address"`
	IPSubnet    string `json:"ip_subnet"`
	Timezone    string `json:"timezone"`
	Fingerprint string `json:"fingerprint"` // SHA256 hash of components
	Location    string `json:"location"`
	CreatedAt   int64  `json:"created_at"`
}

DeviceFingerprint represents a unique device identifier

func GetFingerprint

func GetFingerprint(c *gin.Context) *DeviceFingerprint

GetFingerprint fetch fingerprint from session if exists

type Generator

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

Generator generates device fingerprints from HTTP requests

func NewGenerator

func NewGenerator(config *Config, opts ...GeneratorOption) *Generator

NewGenerator creates a new device fingerprint generator

func (*Generator) Compare

func (g *Generator) Compare(stored, current *DeviceFingerprint, strict bool) bool

Compare compares two device fingerprints with configurable strictness

func (*Generator) DetectChanges

func (g *Generator) DetectChanges(stored, current *DeviceFingerprint) []string

DetectChanges analyzes differences between fingerprints and returns change flags

func (*Generator) Generate

func (g *Generator) Generate(c *gin.Context) *DeviceFingerprint

Generate creates a device fingerprint from a Gin context

func (*Generator) GetConfig

func (g *Generator) GetConfig() *Config

GetConfig returns the current configuration

func (*Generator) SetConfig

func (g *Generator) SetConfig(config *Config)

SetConfig updates the generator configuration

type GeneratorOption

type GeneratorOption func(*Generator)

func WithGeoResolver

func WithGeoResolver(geoResolver GeoResolverFunc) GeneratorOption

WithGeoResolver specify custom function to resolve ipaddr -> location

type GeoResolverFunc

type GeoResolverFunc func(string) string

GeoResolverFunc convert ip address in location info

Jump to

Keyboard shortcuts

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