sanitize

package
v1.20210116.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSanitizationDisallowedHeaders     = []string{"authorization", "cookie", "set-cookie"}
	DefaultSanitizationDisallowedQueryParams = []string{"access_token", "client_secret"}
)

Default values for disallowed field names Note: the values are compared using `strings.EqualFold` so the casing shouldn't matter

Functions

func DefaultValueSanitizer

func DefaultValueSanitizer(_ string, _ ...string) []string

DefaultValueSanitizer is the default value sanitizer.

func Request

func Request(r *http.Request, opts ...RequestOption) *http.Request

Request applies sanitization options to a given request.

Types

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption is a function that mutates sanitization options.

func OptRequestAddDisallowedHeaders

func OptRequestAddDisallowedHeaders(headers ...string) RequestOption

OptRequestAddDisallowedHeaders adds disallowed headers, augmenting defaults.

func OptRequestAddDisallowedQueryParams

func OptRequestAddDisallowedQueryParams(queryParams ...string) RequestOption

OptRequestAddDisallowedQueryParams adds disallowed query params, augmenting defaults.

func OptRequestSetDisallowedHeaders

func OptRequestSetDisallowedHeaders(headers ...string) RequestOption

OptRequestSetDisallowedHeaders sets the disallowed headers, overwriting defaults.

func OptRequestSetDisallowedQueryParams

func OptRequestSetDisallowedQueryParams(queryParams ...string) RequestOption

OptRequestSetDisallowedQueryParams sets the disallowed query params, overwriting defaults.

func OptRequestValueSanitizer

func OptRequestValueSanitizer(valueSanitizer ValueSanitizer) RequestOption

OptRequestValueSanitizer sets the value sanitizer.

type RequestOptions

type RequestOptions struct {
	DisallowedHeaders     []string
	DisallowedQueryParams []string
	ValueSanitizer        ValueSanitizer
}

RequestOptions are options for sanitization of http requests.

func (RequestOptions) IsHeaderDisallowed

func (ro RequestOptions) IsHeaderDisallowed(header string) bool

IsHeaderDisallowed returns if a header is in the disallowed list.

func (RequestOptions) IsQueryParamDisallowed

func (ro RequestOptions) IsQueryParamDisallowed(queryParam string) bool

IsQueryParamDisallowed returns if a query param is in the disallowed list.

type ValueSanitizer

type ValueSanitizer func(key string, values ...string) []string

ValueSanitizer is a function that sanitizes values.

It's designed to accept a variadic list of values that represent the Value of maps like `http.Header` and `url.Values`

Jump to

Keyboard shortcuts

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