leakspok

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

README

leakspok

Go Report Card Build Status

leakspok is an open-source library written in Go, inspired in pii, designed to detect Personally Identifiable Information (PII) in strings. It helps developers ensure data privacy and compliance by spotting potential information leaks.

Features

  • Detect various PII types including:
    • Banking Info
    • Brazilian CNPJ, CPF, and cellphone numbers
    • Credit Card numbers
    • Email Addresses
    • IP Addresses
    • Phone Numbers
    • SSN (Social Security Numbers)
    • Street Addresses
    • UUIDs
    • VIN (Vehicle Identification Numbers)

Installation

To install leakspok, use go get:

go get github.com/New-Horizons-Team/leakspok

Usage

Here's a simple example to use leakspok:

package main

import (
	"fmt"
	"github.com/New-Horizons-Team/leakspok"
)

func main() {
    text := []{"My email is [email protected]", "my sensible pii"}
	t := leakspok.NewDefaultStringTester()
	result, err := t.Find(text)
    }

	// Error handling
	...

    // Print result
	fmt.Println("result: %v", result)

}

Contributing

  1. Fork the repository on GitHub.
  2. Clone the forked repository to your machine.
  3. Create a new branch.
  4. Make your changes and write tests when practical.
  5. Commit changes to the branch.
  6. Push changes to your fork.
  7. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultRuleSet provides a rule set of default PII rules
	DefaultRuleSet = RuleSet{
		"cpf_number":    DefaultCPFRule,
		"cnpj_number":   DefaultCNPJRule,
		"email_address": DefaultEmailRule,
		"ip_address":    DefaultIPRule,
		"credit_card":   DefaultCreditCardRule,
	}

	// DefaultCPFRule is a default rule for Brazilian CPF
	DefaultCPFRule = Rule{
		Name:        "brazilian_CPF",
		Description: "Brazilian CPF",
		Severity:    3,
		Filter:      CPF(),
	}

	// DefaultCNPJRule is a default rule for Brazilian CNPJ
	DefaultCNPJRule = Rule{
		Name:        "brazilian_CNPJ",
		Description: "Brazilian CNPJ",
		Severity:    3,
		Filter:      CNPJ(),
	}

	// DefaultEmailRule is a default rule for email address
	DefaultEmailRule = Rule{
		Name:        "email_address",
		Description: "valid email address",
		Severity:    3,
		Filter:      Email(),
	}

	// DefaultIPRule is a default rule for IP address
	DefaultIPRule = Rule{
		Name:        "ip_address",
		Description: "valid IPv4 address",
		Severity:    2,
		Filter:      IPv4(),
	}

	// DefaultCreditCardRule is a default rule for credit card number
	DefaultCreditCardRule = Rule{
		Name:        "credit_card",
		Description: "valid credit card number",
		Severity:    5,
		Filter:      CreditCard(),
	}
)
View Source
var DefaultMaskString = "<MASKED>"

DefaultMaskString is used to mask matches. It's useful when should report leaks on security alerts

View Source
var DefaultRedactString = "<REDACTED>"

DefaultRedactString is used to redact matches. It's useful when should report leaks on security alerts

Functions

This section is empty.

Types

type AnonymizeOptions added in v0.2.0

type AnonymizeOptions struct {
	Strategy        AnonymizeStrategy
	AnonymizeString string
	AnonymizeLength int
}

AnonymizeOptions defines the options for anonymizing a finding

type AnonymizeStrategy added in v0.2.0

type AnonymizeStrategy int

AnonymizeStrategy defines the strategy for anonymizing a finding

const (
	// REDACT is the strategy for redacting a finding
	REDACT AnonymizeStrategy = iota
	// MASK is the strategy for masking a finding
	MASK
)

type Matcher

type Matcher func(string) bool

Matcher is an evaluation type

func Address

func Address() Matcher

Address returns a matcher for identifying street address, po boxes, and zip codes

func All

func All(funcs ...Matcher) Matcher

All returns a meta-matcher that requires all supplied matchers evaluate to true

func And

func And(a, b Matcher) Matcher

And creates a meta matcher for requiring a logical AND between supplied matchers

func Any

func Any(funcs ...Matcher) Matcher

Any creates a meta matcher for any possible hits against a set of matchers

func AtLeastN

func AtLeastN(n int, funcs ...Matcher) Matcher

AtLeastN creates an at least n rule against a set of matchers

func BankInfo

func BankInfo() Matcher

BankInfo returns a matcher for identifying either IBANs or US Routing #s

func BrazilianPII

func BrazilianPII() Matcher

BrazilianPII generates a matcher for identifying Brazilian identification numbers

func CNPJ

func CNPJ() Matcher

CNPJ generates a matcher for identifying Brazilian CPJs

func CPF

func CPF() Matcher

CPF generates a matcher for identifying Brazilian CPFs

func CreditCard

func CreditCard() Matcher

CreditCard returns a matcher for identifying major credit card numbers

func Email

func Email() Matcher

Email returns a matcher for identifying email addresses

func HaltLangDetect

func HaltLangDetect() Matcher

HaltLangDetect is a special matcher for preventing language detection from running

func IP

func IP() Matcher

IP returns a matcher for identifying IPv4 and IPv6 addresses

func IPv4

func IPv4() Matcher

IPv4 returns a matcher for identifying IP addresses

func IPv6

func IPv6() Matcher

IPv6 returns a matcher for identifying IPv6 addresses

func Link() Matcher

Link returns a matcher for identifying URLs and links that are not emails

func Not

func Not(f Matcher) Matcher

Not is the logical negation of a Matcher

func Or

func Or(a, b Matcher) Matcher

Or creates a meta matcher for performing a logical OR on two matchers

func Phone

func Phone() Matcher

Phone returns a matcher for identifying international phone numbers

func SSN

func SSN() Matcher

SSN returns a matcher for identifying US social security numbers

func UUID

func UUID() Matcher

UUID returns a matcher for identifying GUIDs, UUIDs, v3, v4, and v5

func VIN

func VIN() Matcher

VIN generates a matcher for identifying vehicle identification numbers

type Rule

type Rule struct {
	Name             string           `json:"name,omitempty"`
	Description      string           `json:"description,omitempty"`
	Severity         int              `json:"severity,omitempty"`
	Filter           Matcher          `json:"-"`
	Anonymize        bool             `json:"redact,omitempty"`
	AnonymizeOptions AnonymizeOptions `json:"anonymize,omitempty"`
}

Rule defines a matching requirement

type RuleSet

type RuleSet map[string]Rule

RuleSet creates a map of multiple rules

func (RuleSet) Hits

func (r RuleSet) Hits(s string) []Rule

Hits enumerates all rules within a ruleset returning any matching rules

type StringTester

type StringTester struct {
	Rules []Rule `json:"rules,omitempty"`
}

StringTester defines a test harness for assessment

func NewDefaultStringTester

func NewDefaultStringTester() *StringTester

NewDefaultStringTester creates a new default StringTester object with all default rules included

func NewEmptyStringTester

func NewEmptyStringTester() *StringTester

NewEmptyStringTester returns an empty StringTester object with no rules loaded

func NewStringTester

func NewStringTester(set RuleSet) *StringTester

NewStringTester creates a new StringTester object with all rules included by the user

func (*StringTester) AnonymizeFindings added in v0.2.0

func (t *StringTester) AnonymizeFindings(s string) (string, bool)

AnonymizeFindings anonymizes all matches within the rules

func (*StringTester) Find

func (t *StringTester) Find(s []string) (StringTesterResult, error)

Find creates a new default StringTesterResult object with all default rules included

func (*StringTester) MaskFindings

func (t *StringTester) MaskFindings(s string) string

MaskFindings masks all matches within the rules

type StringTesterResult

type StringTesterResult struct {
	BrazilianCNPJ bool `json:"brazilian_CNPJ"`
	BrazilianCPF  bool `json:"brazilian_CPF"`
	CreditCard    bool `json:"credit_card"`
	EmailAddress  bool `json:"email_address"`
	IPAddress     bool `json:"ip_address"`
}

StringTesterResult must sync with the DefaultRuleSet TODO: use code generation for this

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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