common

package
v3.0.0-...-838862a Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetricsNamespace is the namespace for all metrics.
	MetricsNamespace = "gitpwned"
	// MetricsSubsystem is the subsystem for all metrics.
	MetricsSubsystem = "scanner"
)
View Source
const AlphaNumPattern = "0-9a-zA-Z"
View Source
const DefaultResponseTimeout = 5 * time.Second
View Source
const EmailPattern = `` /* 456-byte string literal not displayed */
View Source
const HexPattern = "0-9a-f"
View Source
const RegexPattern = "0-9a-z"
View Source
const SubDomainPattern = `\b([A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?)\b`
View Source
const UUIDPattern = `\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b`
View Source
const UUIDPatternUpperCase = `\b([0-9A-Z]{8}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{12})\b`

Variables

View Source
var (
	KB, MB, GB, TB, PB = 1e3, 1e6, 1e9, 1e12, 1e15
	IgnoredExtensions  = []string{"mp4", "avi", "mpeg", "mpg", "mov", "wmv", "m4p", "swf", "mp2", "flv", "vob", "webm", "hdv", "3gp", "ogg", "mp3", "wav", "flac", "webp"}
)

Functions

func AddStringSliceItem

func AddStringSliceItem(item string, slice *[]string)

func BuildRegex

func BuildRegex(pattern string, specialChar string, length int) string

Custom Regex functions

func BuildRegexJWT

func BuildRegexJWT(firstRange, secondRange, thirdRange string) string

func BytesEqual

func BytesEqual(a, b []byte, numBytes int) bool

func CancellableWrite

func CancellableWrite[T any](ctx context.Context, ch chan<- T, item T) error

CancellableWrite blocks on writing the item to the channel but can be cancelled by the context. If both the context is cancelled and the channel write would succeed, either operation will be performed randomly.

func ConstantResponseHttpClient

func ConstantResponseHttpClient(statusCode int, body string) *http.Client

func IsDone

func IsDone(ctx context.Context) bool

func MinInt

func MinInt(a, b int) int

func PinnedCertPool

func PinnedCertPool() *x509.CertPool

func PinnedRetryableHttpClient

func PinnedRetryableHttpClient() *http.Client

func RandomID

func RandomID(length int) string

RandomID returns a random string of the given length.

func RangeValidation

func RangeValidation(rangeInput string) bool

func Recover

func Recover(ctx context.Context)

Recover handles panics and reports to Sentry.

func RecoverWithExit

func RecoverWithExit(ctx context.Context)

RecoverWithExit handles panics and reports to Sentry before exiting.

func RemoveStringSliceItem

func RemoveStringSliceItem(item string, slice *[]string)

func ResponseContainsSubstring

func ResponseContainsSubstring(reader io.ReadCloser, target string) (bool, error)

func RetryableHttpClient

func RetryableHttpClient() *http.Client

func RetryableHttpClientTimeout

func RetryableHttpClientTimeout(timeOutSeconds int64) *http.Client

func SaneHttpClient

func SaneHttpClient() *http.Client

func SaneHttpClientTimeOut

func SaneHttpClientTimeOut(timeout time.Duration) *http.Client

SaneHttpClientTimeOut adds a custom timeout for some scanners

func SkipFile

func SkipFile(filename string) bool

func ToUpperCase

func ToUpperCase(input string) string

Types

type CustomTransport

type CustomTransport struct {
	T http.RoundTripper
}

func NewCustomTransport

func NewCustomTransport(T http.RoundTripper) *CustomTransport

func (*CustomTransport) RoundTrip

func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error)

type FakeTransport

type FakeTransport struct {
	CreateResponse func(req *http.Request) (*http.Response, error)
}

func (FakeTransport) RoundTrip

func (t FakeTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Filter

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

func FilterEmpty

func FilterEmpty() *Filter

FilterEmpty returns a Filter that always passes.

func FilterFromFiles

func FilterFromFiles(includeFilterPath, excludeFilterPath string) (*Filter, error)

FilterFromFiles creates a Filter using the rules in the provided include and exclude files.

func (*Filter) Pass

func (filter *Filter) Pass(object string) bool

Pass returns true if the include FilterRuleSet matches the pattern and the exclude FilterRuleSet does not match.

type FilterRuleSet

type FilterRuleSet []regexp.Regexp

func FilterRulesFromFile

func FilterRulesFromFile(source string) (*FilterRuleSet, error)

FilterRulesFromFile loads the list of regular expression filter rules in `source` and creates a FilterRuleSet.

func (*FilterRuleSet) Matches

func (rules *FilterRuleSet) Matches(object string) bool

Matches will return true if any of the regular expressions in the FilterRuleSet match the pattern.

type RegexState

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

func PasswordRegexCheck

func PasswordRegexCheck(pattern string) RegexState

PasswordRegexCheck constructs an username usernameRegex pattern from a given pattern of excluded characters.

func UsernameRegexCheck

func UsernameRegexCheck(pattern string) RegexState

UsernameRegexCheck constructs an username usernameRegex pattern from a given pattern of excluded characters.

func (RegexState) Matches

func (r RegexState) Matches(data []byte) []string

type Secret

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

func GetSecret

func GetSecret(ctx context.Context, gcpProject, name string) (secret *Secret, err error)

func GetSecretFromEnv

func GetSecretFromEnv(filename string) (secret *Secret, err error)

func GetTestSecret

func GetTestSecret(ctx context.Context) (secret *Secret, err error)

func (*Secret) MustGetField

func (s *Secret) MustGetField(name string) string

Jump to

Keyboard shortcuts

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