types

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectionsToString

func CollectionsToString(collections []Collection, separator string) string

func ToSeclang

func ToSeclang(configList ConfigurationList) string

func VariablesToString

func VariablesToString(variables []Variable, separator string) string

Types

type Action

type Action interface {
	GetKey() string
	ToString() string
}

Action interface represents a generic action

func NewActionOnly

func NewActionOnly[T ActionType](action T) (Action, error)

NewActionOnly creates a new NewActionOnly with the given action type It uses generics to accept DisruptiveAction, FlowAction, DataAction, or NonDisruptiveAction

type ActionOnly

type ActionOnly string

ActionOnly represents an action without parameters

func (ActionOnly) GetKey

func (a ActionOnly) GetKey() string

GetKey returns the action name

func (ActionOnly) ToString

func (a ActionOnly) ToString() string

ToString returns the string representation of the action

type ActionType

type ActionType interface {
	DisruptiveAction | FlowAction | DataAction | NonDisruptiveAction
	String() string
}

ActionType is a constraint for all action types

type ActionWithParam

type ActionWithParam map[string]string

ActionWithParam represents a single action with its parameters It's a map where the key is the action name and the value is the parameter

func NewActionWithParam

func NewActionWithParam[T ActionType](action T, param string) (ActionWithParam, error)

NewActionWithParam creates a new NewActionWithParam with the given action type and parameter It uses generics to accept DisruptiveAction, FlowAction, DataAction, or NonDisruptiveAction

func (ActionWithParam) GetKey

func (a ActionWithParam) GetKey() string

GetKey returns the action name (first key in the map)

func (ActionWithParam) GetParam

func (a ActionWithParam) GetParam() string

GetParam returns the parameter value for the action

func (ActionWithParam) ToString

func (a ActionWithParam) ToString() string

ToString converts the action to its string representation

type ChainableDirective

type ChainableDirective interface {
	SeclangDirective
	GetMetadata() Metadata
	GetActions() *SeclangActions
	GetTransformations() Transformations
	ToSeclangWithIdent(string) string
	GetChainedDirective() ChainableDirective
	AppendChainedDirective(ChainableDirective)
	NonDisruptiveActionsCount() int
}

func FromConditionToUnmorfattedDirective

func FromConditionToUnmorfattedDirective(conditionDirective RuleWithCondition) ChainableDirective

type Collection

type Collection struct {
	Name      CollectionName `yaml:"name,omitempty"`
	Arguments []string       `yaml:"arguments,omitempty"`
	Excluded  []string       `yaml:"excludeds,omitempty"`
	Count     bool           `yaml:"count,omitempty"`
}

type CollectionName

type CollectionName int
const (
	// Collections
	UNKNOWN_COLLECTION CollectionName = iota
	ARGS
	ARGS_GET
	ARGS_GET_NAMES
	ARGS_NAMES
	ARGS_POST_NAMES
	ARGS_POST
	ENV
	FILES
	GEO
	GLOBAL
	IP
	MATCHED_VARS_NAMES
	MATCHED_VARS
	MULTIPART_PART_HEADERS
	PERF_RULES
	REQUEST_COOKIES_NAMES
	REQUEST_COOKIES
	REQUEST_HEADERS_NAMES
	REQUEST_HEADERS
	RESOURCE
	RESPONSE_HEADERS_NAMES
	RESPONSE_HEADERS
	RULE
	SESSION
	TX
	USER
	XML
)

func (CollectionName) MarshalYAML

func (c CollectionName) MarshalYAML() (interface{}, error)

func (CollectionName) String

func (c CollectionName) String() string

func (*CollectionName) UnmarshalYAML

func (c *CollectionName) UnmarshalYAML(unmarshal func(interface{}) error) error

type CommentDirective

type CommentDirective struct {
	Kind     Kind            `yaml:"kind"`
	Metadata CommentMetadata `yaml:",inline"`
}

func (CommentDirective) GetKind

func (d CommentDirective) GetKind() Kind

func (CommentDirective) ToSeclang

func (d CommentDirective) ToSeclang() string

type CommentMetadata

type CommentMetadata struct {
	Comment string `yaml:"comment,omitempty"`
}

func (*CommentMetadata) AddTag

func (c *CommentMetadata) AddTag(value string)

func (CommentMetadata) GetKind

func (c CommentMetadata) GetKind() Kind

func (*CommentMetadata) SetComment

func (c *CommentMetadata) SetComment(value string)

func (*CommentMetadata) SetId

func (c *CommentMetadata) SetId(value string)

func (*CommentMetadata) SetMaturity

func (c *CommentMetadata) SetMaturity(value string)

func (*CommentMetadata) SetMsg

func (c *CommentMetadata) SetMsg(value string)

func (*CommentMetadata) SetPhase

func (c *CommentMetadata) SetPhase(value string)

func (*CommentMetadata) SetRev

func (c *CommentMetadata) SetRev(value string)

func (*CommentMetadata) SetSeverity

func (c *CommentMetadata) SetSeverity(value string)

func (*CommentMetadata) SetVer

func (c *CommentMetadata) SetVer(value string)

func (CommentMetadata) ToSeclang

func (c CommentMetadata) ToSeclang() string

type Condition

type Condition struct {
	// SecRule conditions are represented by Variables, Collections, Operator, and Transformations.
	Variables       []Variable   `yaml:"variables,omitempty"`
	Collections     []Collection `yaml:"collections,omitempty"`
	Operator        Operator     `yaml:"operator,omitempty"`
	Transformations `yaml:",inline,omitempty"`
	// SecAction conditions are represented by an AlwaysMatch flag and it can also have Transformations.
	AlwaysMatch bool `yaml:"always-match,omitempty"`
	// Script conditions are represented by a ScriptPath.
	Script string `yaml:"script,omitempty"`
}

Condition represents a condition defined in a rule. It can represent SecActions, SecRules, or Script conditions.

type ConfigurationDirective

type ConfigurationDirective struct {
	Kind      Kind                       `yaml:"kind"`
	Metadata  *CommentMetadata           `yaml:",inline"`
	Name      ConfigurationDirectiveType `yaml:"name"`
	Parameter string                     `yaml:"parameter"`
}

func NewConfigurationDirective

func NewConfigurationDirective() *ConfigurationDirective

func (ConfigurationDirective) GetKind

func (c ConfigurationDirective) GetKind() Kind

func (ConfigurationDirective) GetMetadata

func (c ConfigurationDirective) GetMetadata() Metadata

func (*ConfigurationDirective) SetName

func (c *ConfigurationDirective) SetName(name string) error

func (ConfigurationDirective) ToSeclang

func (c ConfigurationDirective) ToSeclang() string

TODO: add quotes around the value when the parameter is a string

type ConfigurationDirectiveType

type ConfigurationDirectiveType string
const (
	SecAuditLogStorageDir         ConfigurationDirectiveType = "SecAuditLogStorageDir"
	SecAuditLogDirMode            ConfigurationDirectiveType = "SecAuditLogDirMode"
	SecAuditEngine                ConfigurationDirectiveType = "SecAuditEngine"
	SecAuditLogFileMode           ConfigurationDirectiveType = "SecAuditLogFileMode"
	SecAuditLog2                  ConfigurationDirectiveType = "SecAuditLog2"
	SecAuditLog                   ConfigurationDirectiveType = "SecAuditLog"
	SecAuditLogFormat             ConfigurationDirectiveType = "SecAuditLogFormat"
	SecAuditLogParts              ConfigurationDirectiveType = "SecAuditLogParts"
	SecAuditLogRelevantStatus     ConfigurationDirectiveType = "SecAuditLogRelevantStatus"
	SecAuditLogType               ConfigurationDirectiveType = "SecAuditLogType"
	SecUploadKeepFiles            ConfigurationDirectiveType = "SecUploadKeepFiles"
	SecTmpSaveUploadedFiles       ConfigurationDirectiveType = "SecTmpSaveUploadedFiles"
	SecUploadDir                  ConfigurationDirectiveType = "SecUploadDir"
	SecUploadFileLimit            ConfigurationDirectiveType = "SecUploadFileLimit"
	SecUploadFileMode             ConfigurationDirectiveType = "SecUploadFileMode"
	SecComponentSignature         ConfigurationDirectiveType = "SecComponentSignature"
	SecServerSignature            ConfigurationDirectiveType = "SecServerSignature"
	SecWebAppId                   ConfigurationDirectiveType = "SecWebAppId"
	SecMarker                     ConfigurationDirectiveType = "SecMarker"
	SecConnEngine                 ConfigurationDirectiveType = "SecConnEngine"
	SecContentInjection           ConfigurationDirectiveType = "SecContentInjection"
	SecArgumentsLimit             ConfigurationDirectiveType = "SecArgumentsLimit"
	SecDebugLog                   ConfigurationDirectiveType = "SecDebugLog"
	SecDebugLogLevel              ConfigurationDirectiveType = "SecDebugLogLevel"
	SecGeoLookupDb                ConfigurationDirectiveType = "SecGeoLookupDb"
	SecGsbLookupDb                ConfigurationDirectiveType = "SecGsbLookupDb"
	SecPcreMatchLimit             ConfigurationDirectiveType = "SecPcreMatchLimit"
	SecPcreMatchLimitRecursion    ConfigurationDirectiveType = "SecPcreMatchLimitRecursion"
	SecRequestBodyJsonDepthLimit  ConfigurationDirectiveType = "SecRequestBodyJsonDepthLimit"
	SecRequestBodyAccess          ConfigurationDirectiveType = "SecRequestBodyAccess"
	SecRequestBodyInMemoryLimit   ConfigurationDirectiveType = "SecRequestBodyInMemoryLimit"
	SecRequestBodyLimit           ConfigurationDirectiveType = "SecRequestBodyLimit"
	SecRequestBodyLimitAction     ConfigurationDirectiveType = "SecRequestBodyLimitAction"
	SecRequestBodyNoFilesLimit    ConfigurationDirectiveType = "SecRequestBodyNoFilesLimit"
	SecResponseBodyMimeType       ConfigurationDirectiveType = "SecResponseBodyMimeType"
	SecResponseBodyMimeTypesClear ConfigurationDirectiveType = "SecResponseBodyMimeTypesClear"
	SecResponseBodyAccess         ConfigurationDirectiveType = "SecResponseBodyAccess"
	SecResponseBodyLimit          ConfigurationDirectiveType = "SecResponseBodyLimit"
	SecResponseBodyLimitAction    ConfigurationDirectiveType = "SecResponseBodyLimitAction"
	SecRuleEngine                 ConfigurationDirectiveType = "SecRuleEngine"
	SecCookieFormat               ConfigurationDirectiveType = "SecCookieFormat"
	SecCookieV0Separator          ConfigurationDirectiveType = "SecCookieV0Separator"
	SecDataDir                    ConfigurationDirectiveType = "SecDataDir"
	SecStatusEngine               ConfigurationDirectiveType = "SecStatusEngine"
	SecTmpDir                     ConfigurationDirectiveType = "SecTmpDir"
	SecUnicodeMapFile             ConfigurationDirectiveType = "SecUnicodeMapFile"
	SecArgumentSeparator          ConfigurationDirectiveType = "SecArgumentSeparator"
	SecChrootDir                  ConfigurationDirectiveType = "SecChrootDir"
	SecCollectionTimeout          ConfigurationDirectiveType = "SecCollectionTimeout"
	SecConnReadStateLimit         ConfigurationDirectiveType = "SecConnReadStateLimit"
	SecConnWriteStateLimit        ConfigurationDirectiveType = "SecConnWriteStateLimit"
	SecDisableBackendCompression  ConfigurationDirectiveType = "SecDisableBackendCompression"
	SecGuardianLog                ConfigurationDirectiveType = "SecGuardianLog"
	SecHashEngine                 ConfigurationDirectiveType = "SecHashEngine"
	SecHashKey                    ConfigurationDirectiveType = "SecHashKey"
	SecHashParam                  ConfigurationDirectiveType = "SecHashParam"
	SecHashMethodRx               ConfigurationDirectiveType = "SecHashMethodRx"
	SecHashMethodPm               ConfigurationDirectiveType = "SecHashMethodPm"
	SecHttpBlKey                  ConfigurationDirectiveType = "SecHttpBlKey"
	SecInterceptOnError           ConfigurationDirectiveType = "SecInterceptOnError"
	SecRemoteRulesFailAction      ConfigurationDirectiveType = "SecRemoteRulesFailAction"
	SecRuleInheritance            ConfigurationDirectiveType = "SecRuleInheritance"
	SecRulePerfTime               ConfigurationDirectiveType = "SecRulePerfTime"
	SecSensorId                   ConfigurationDirectiveType = "SecSensorId"
	SecStreamInBodyInspection     ConfigurationDirectiveType = "SecStreamInBodyInspection"
	SecStreamOutBodyInspection    ConfigurationDirectiveType = "SecStreamOutBodyInspection"
	SecXmlExternalEntity          ConfigurationDirectiveType = "SecXmlExternalEntity"
	SecCacheTransformations       ConfigurationDirectiveType = "SecCacheTransformations"
)

type ConfigurationList

type ConfigurationList struct {
	Global        DefaultConfigs  `yaml:"global,omitempty"`
	DirectiveList []DirectiveList `yaml:"directivelist,omitempty"`
}

func FromCRSLangToUnformattedDirectives

func FromCRSLangToUnformattedDirectives(configListWrapped ConfigurationList) *ConfigurationList

func LoadDirectivesWithConditions

func LoadDirectivesWithConditions(yamlFile []byte) ConfigurationList

LoadDirectivesWithConditions loads condition format directives from a yaml file

func LoadDirectivesWithConditionsFromFile

func LoadDirectivesWithConditionsFromFile(filename string) ConfigurationList

LoadDirectivesWithConditionsFromFile loads condition format directives from a yaml file

func ToDirectiveWithConditions

func ToDirectiveWithConditions(configList ConfigurationList) *ConfigurationList

func (*ConfigurationList) ExtractDefaultValues

func (c *ConfigurationList) ExtractDefaultValues()

ExtractDefaultValues extracts default values for version and tags from the rules in the configuration list

type DataAction

type DataAction int
const (
	DataUnknown DataAction = iota
	Status
	XLMNS
)

func StringToDataAction

func StringToDataAction(s string) DataAction

func (DataAction) String

func (d DataAction) String() string

type DefaultAction

type DefaultAction struct {
	Kind            Kind               `yaml:"kind,omitempty"`
	Metadata        *OnlyPhaseMetadata `yaml:"metadata"`
	Transformations `yaml:",inline"`
	Actions         *SeclangActions `yaml:"actions"`
}

func NewDefaultAction

func NewDefaultAction() *DefaultAction

func (DefaultAction) AppendChainedDirective

func (s DefaultAction) AppendChainedDirective(chainedDirective ChainableDirective)

func (DefaultAction) GetActions

func (d DefaultAction) GetActions() *SeclangActions

func (DefaultAction) GetKind

func (d DefaultAction) GetKind() Kind

func (DefaultAction) GetMetadata

func (d DefaultAction) GetMetadata() Metadata

func (DefaultAction) ToSeclang

func (s DefaultAction) ToSeclang() string

type DefaultConfigs

type DefaultConfigs struct {
	Version string   `yaml:"version,omitempty"`
	Tags    []string `yaml:"tags,omitempty"`
}

type DirectiveList

type DirectiveList struct {
	Id         string                 `yaml:"id"`
	Directives []SeclangDirective     `yaml:"directives,omitempty"`
	Marker     ConfigurationDirective `yaml:"marker,omitempty"`
}

func (DirectiveList) ToSeclang

func (d DirectiveList) ToSeclang() string

type DisruptiveAction

type DisruptiveAction int
const (
	Allow DisruptiveAction = iota
	Block
	Deny
	Drop
	Pass
	Pause
	Proxy
	Redirect
	Unknown
)

func StringToDisruptiveAction

func StringToDisruptiveAction(s string) DisruptiveAction

Helper functions to convert string to action types

func (DisruptiveAction) String

func (d DisruptiveAction) String() string

type FlowAction

type FlowAction int
const (
	Chain FlowAction = iota
	Skip
	SkipAfter
	FlowUnknown
)

func StringToFlowAction

func StringToFlowAction(s string) FlowAction

func (FlowAction) String

func (f FlowAction) String() string

type IdRange

type IdRange struct {
	Start int `yaml:"start"`
	End   int `yaml:"end"`
}

func (IdRange) ToString

func (r IdRange) ToString() string

type Kind

type Kind string
const (
	UnknownKind       Kind = "unknown"
	CommentKind       Kind = "comment"
	ConfigurationKind Kind = "configuration"
	DefaultActionKind Kind = "defaultaction"
	RuleKind          Kind = "rule"
	Remove            Kind = "remove"
	UpdateTarget      Kind = "update_target"
	UpdateAction      Kind = "update_action"
)

type Metadata

type Metadata interface {
	SetComment(value string)
	SetId(value string)
	SetPhase(value string)
	SetMsg(value string)
	SetMaturity(value string)
	SetRev(value string)
	SetSeverity(value string)
	AddTag(value string)
	SetVer(value string)
}

type ModifyAction

type ModifyAction struct {
	Metadata        *UpdateActionMetadata `yaml:"metadata,omitempty"`
	Transformations `yaml:",inline"`
	Actions         *SeclangActions `yaml:"actions,omitempty"`
}

type NonDisruptiveAction

type NonDisruptiveAction int
const (
	Append NonDisruptiveAction = iota
	AuditLog
	Capture
	Ctl
	DeprecateVar
	Exec
	ExpireVar
	InitCol
	Log
	LogData
	MultiMatch
	NoAuditLog
	NoLog
	Prepend
	SanitiseArg
	SanitiseMatched
	SanitiseMatchedBytes
	SanitiseRequestHeader
	SanitiseResponseHeader
	SetUid
	SetRsc
	SetSid
	SetEnv
	SetVar
	NonDisruptiveUnknown
)

func StringToNonDisruptiveAction

func StringToNonDisruptiveAction(s string) NonDisruptiveAction

func (NonDisruptiveAction) String

func (n NonDisruptiveAction) String() string

type OnlyPhaseMetadata

type OnlyPhaseMetadata struct {
	CommentMetadata `yaml:",inline"`
	Phase           string `yaml:"phase,omitempty"`
}

func (*OnlyPhaseMetadata) AddTag

func (m *OnlyPhaseMetadata) AddTag(value string)

func (*OnlyPhaseMetadata) SetId

func (m *OnlyPhaseMetadata) SetId(value string)

func (*OnlyPhaseMetadata) SetMaturity

func (m *OnlyPhaseMetadata) SetMaturity(value string)

func (*OnlyPhaseMetadata) SetMsg

func (m *OnlyPhaseMetadata) SetMsg(value string)

func (*OnlyPhaseMetadata) SetPhase

func (m *OnlyPhaseMetadata) SetPhase(value string)

func (*OnlyPhaseMetadata) SetRev

func (m *OnlyPhaseMetadata) SetRev(value string)

func (*OnlyPhaseMetadata) SetSeverity

func (m *OnlyPhaseMetadata) SetSeverity(value string)

func (*OnlyPhaseMetadata) SetVer

func (m *OnlyPhaseMetadata) SetVer(value string)

func (*OnlyPhaseMetadata) ToString

func (m *OnlyPhaseMetadata) ToString() string

type Operator

type Operator struct {
	Negate bool         `yaml:"negate,omitempty"`
	Name   OperatorType `yaml:"name"`
	Value  string       `yaml:",omitempty"`
}

func (Operator) MarshalYAML

func (o Operator) MarshalYAML() (interface{}, error)

func (*Operator) SetOperatorName

func (o *Operator) SetOperatorName(name string) error

func (*Operator) SetOperatorNot

func (o *Operator) SetOperatorNot(not bool)

func (*Operator) SetOperatorValue

func (o *Operator) SetOperatorValue(value string)

func (*Operator) ToString

func (o *Operator) ToString() string

func (*Operator) UnmarshalYAML

func (o *Operator) UnmarshalYAML(unmarshal func(interface{}) error) error

type OperatorType

type OperatorType int
const (
	UnknownOperator OperatorType = iota
	BeginsWith
	Contains
	ContainsWord
	DetectSQLi
	DetectXSS
	EndsWith
	Eq
	FuzzyHash
	Ge
	GeoLookup
	GsbLookup
	Gt
	InspectFile
	IpMatchF
	IpMatchFromFile
	IpMatch
	Le
	Lt
	Pmf
	PmFromFile
	Pm
	Rbl
	Rsub
	Rx
	RxGlobal
	StrEq
	StrMatch
	UnconditionalMatch
	ValidateByteRange
	ValidateDTD
	ValidateHash
	ValidateSchema
	ValidateUrlEncoding
	ValidateUtf8Encoding
	VerifyCC
	VerifyCPF
	VerifySSN
	VerifySVNR
	Within
)

func (OperatorType) MarshalYAML

func (o OperatorType) MarshalYAML() (interface{}, error)

func (OperatorType) String

func (o OperatorType) String() string

func (*OperatorType) UnmarshalYAML

func (o *OperatorType) UnmarshalYAML(unmarshal func(interface{}) error) error

type RemoveRuleDirective

type RemoveRuleDirective struct {
	Kind     Kind            `yaml:"kind"`
	Metadata CommentMetadata `yaml:"metadata,omitempty"`
	Ids      []int           `yaml:"ids,omitempty"`
	IdRanges []IdRange       `yaml:"id_ranges,omitempty"`
	Tags     []string        `yaml:"tags,omitempty"`
	Msgs     []string        `yaml:"msgs,omitempty"`
}

func (RemoveRuleDirective) GetKind

func (d RemoveRuleDirective) GetKind() Kind

func (RemoveRuleDirective) ToSeclang

func (d RemoveRuleDirective) ToSeclang() string

type RuleWithCondition

type RuleWithCondition struct {
	Kind        Kind               `yaml:"kind"`
	Metadata    SecRuleMetadata    `yaml:"metadata,omitempty"`
	Conditions  []Condition        `yaml:"conditions,omitempty"`
	Actions     SeclangActions     `yaml:"actions,omitempty"`
	ChainedRule *RuleWithCondition `yaml:"chainedRule,omitempty"`
}

func RuleToCondition

func RuleToCondition(directive ChainableDirective) *RuleWithCondition

func (*RuleWithCondition) GetKind

func (s *RuleWithCondition) GetKind() Kind

func (*RuleWithCondition) ToSeclang

func (s *RuleWithCondition) ToSeclang() string

type SecAction

type SecAction struct {
	Metadata        *SecRuleMetadata `yaml:"metadata,omitempty"`
	Transformations `yaml:",inline"`
	Actions         *SeclangActions    `yaml:"actions"`
	ChainedRule     ChainableDirective `yaml:"chainedRule,omitempty"`
}

func NewSecAction

func NewSecAction() *SecAction

func (*SecAction) AppendChainedDirective

func (s *SecAction) AppendChainedDirective(chainedDirective ChainableDirective)

func (SecAction) GetActions

func (d SecAction) GetActions() *SeclangActions

func (SecAction) GetChainedDirective

func (s SecAction) GetChainedDirective() ChainableDirective

func (SecAction) GetKind

func (d SecAction) GetKind() Kind

func (SecAction) GetMetadata

func (d SecAction) GetMetadata() Metadata

func (SecAction) GetTransformations

func (d SecAction) GetTransformations() Transformations

func (SecAction) NonDisruptiveActionsCount

func (s SecAction) NonDisruptiveActionsCount() int

func (SecAction) ToSeclang

func (s SecAction) ToSeclang() string

func (SecAction) ToSeclangWithIdent

func (s SecAction) ToSeclangWithIdent(initialString string) string

type SecRule

type SecRule struct {
	Metadata        *SecRuleMetadata `yaml:"metadata,omitempty"`
	Variables       []Variable       `yaml:"variables"`
	Collections     []Collection     `yaml:"collections,omitempty"`
	Transformations `yaml:",inline"`
	Operator        `yaml:"operator"`
	Actions         *SeclangActions    `yaml:"actions,omitempty"`
	ChainedRule     ChainableDirective `yaml:"chainedRule,omitempty"`
}

func NewSecRule

func NewSecRule() *SecRule

func (*SecRule) AddCollection

func (s *SecRule) AddCollection(name, value string, excluded, asCount bool) error

func (*SecRule) AddVariable

func (s *SecRule) AddVariable(name string, excluded bool) error

func (*SecRule) AppendChainedDirective

func (s *SecRule) AppendChainedDirective(chainedDirective ChainableDirective)

func (SecRule) GetActions

func (d SecRule) GetActions() *SeclangActions

func (SecRule) GetChainedDirective

func (s SecRule) GetChainedDirective() ChainableDirective

func (SecRule) GetKind

func (d SecRule) GetKind() Kind

func (SecRule) GetMetadata

func (d SecRule) GetMetadata() Metadata

func (SecRule) GetTransformations

func (d SecRule) GetTransformations() Transformations

func (SecRule) NonDisruptiveActionsCount

func (s SecRule) NonDisruptiveActionsCount() int

func (SecRule) ToSeclang

func (s SecRule) ToSeclang() string

func (SecRule) ToSeclangWithIdent

func (s SecRule) ToSeclangWithIdent(initialString string) string

type SecRuleMetadata

type SecRuleMetadata struct {
	OnlyPhaseMetadata `yaml:",inline"`
	Id                int      `yaml:"id,omitempty"`
	Msg               string   `yaml:"message,omitempty"`
	Maturity          string   `yaml:"maturity,omitempty"`
	Rev               string   `yaml:"revision,omitempty"`
	Severity          string   `yaml:"severity,omitempty"`
	Tags              []string `yaml:"tags,omitempty"`
	Ver               string   `yaml:"version,omitempty"`
}

func CopySecRuleMetadata

func CopySecRuleMetadata(s SecRuleMetadata) *SecRuleMetadata

func (*SecRuleMetadata) AddTag

func (s *SecRuleMetadata) AddTag(value string)

func (*SecRuleMetadata) SetId

func (s *SecRuleMetadata) SetId(value string)

func (*SecRuleMetadata) SetMaturity

func (s *SecRuleMetadata) SetMaturity(value string)

func (*SecRuleMetadata) SetMsg

func (s *SecRuleMetadata) SetMsg(value string)

func (*SecRuleMetadata) SetRev

func (s *SecRuleMetadata) SetRev(value string)

func (*SecRuleMetadata) SetSeverity

func (s *SecRuleMetadata) SetSeverity(value string)

func (*SecRuleMetadata) SetVer

func (s *SecRuleMetadata) SetVer(value string)

func (*SecRuleMetadata) ToString

func (s *SecRuleMetadata) ToString() string

type SecRuleScript

type SecRuleScript struct {
	Metadata        *SecRuleMetadata `yaml:"metadata,omitempty"`
	ScriptPath      string           `yaml:"scriptpath"`
	Transformations `yaml:",inline"`
	Actions         *SeclangActions    `yaml:"actions,omitempty"`
	ChainedRule     ChainableDirective `yaml:"chainedRule,omitempty"`
}

func NewSecRuleScript

func NewSecRuleScript() *SecRuleScript

func (*SecRuleScript) AppendChainedDirective

func (s *SecRuleScript) AppendChainedDirective(chainedDirective ChainableDirective)

func (SecRuleScript) GetActions

func (d SecRuleScript) GetActions() *SeclangActions

func (SecRuleScript) GetChainedDirective

func (s SecRuleScript) GetChainedDirective() ChainableDirective

func (SecRuleScript) GetKind

func (d SecRuleScript) GetKind() Kind

func (SecRuleScript) GetMetadata

func (d SecRuleScript) GetMetadata() Metadata

func (SecRuleScript) GetTransformations

func (d SecRuleScript) GetTransformations() Transformations

func (SecRuleScript) NonDisruptiveActionsCount

func (s SecRuleScript) NonDisruptiveActionsCount() int

func (SecRuleScript) ToSeclang

func (s SecRuleScript) ToSeclang() string

func (SecRuleScript) ToSeclangWithIdent

func (s SecRuleScript) ToSeclangWithIdent(initialString string) string

type SeclangActions

type SeclangActions struct {
	DisruptiveAction     Action   `yaml:"disruptive,omitempty"`
	NonDisruptiveActions []Action `yaml:"non-disruptive,omitempty"`
	FlowActions          []Action `yaml:"flow,omitempty"`
	DataActions          []Action `yaml:"data,omitempty"`
}

func CopyActions

func CopyActions(a SeclangActions) *SeclangActions

func (*SeclangActions) AddDataActionWithParams

func (s *SeclangActions) AddDataActionWithParams(action DataAction, param string) error

func (*SeclangActions) AddFlowActionOnly

func (s *SeclangActions) AddFlowActionOnly(action FlowAction) error

func (*SeclangActions) AddFlowActionWithParam

func (s *SeclangActions) AddFlowActionWithParam(action FlowAction, param string) error

func (*SeclangActions) AddNonDisruptiveActionOnly

func (s *SeclangActions) AddNonDisruptiveActionOnly(action NonDisruptiveAction) error

func (*SeclangActions) AddNonDisruptiveActionWithParam

func (s *SeclangActions) AddNonDisruptiveActionWithParam(action NonDisruptiveAction, param string) error

func (*SeclangActions) AddSetvarAction

func (s *SeclangActions) AddSetvarAction(collection, variable, operation, value string) error

AddSetvarAction adds a setvar action to the NonDisruptiveActions list

func (*SeclangActions) GetActionByKey

func (s *SeclangActions) GetActionByKey(key string) Action

func (*SeclangActions) GetActionKeys

func (s *SeclangActions) GetActionKeys() []string

func (*SeclangActions) GetActionsByKey

func (s *SeclangActions) GetActionsByKey(key string) []Action

func (*SeclangActions) SetDisruptiveActionOnly

func (s *SeclangActions) SetDisruptiveActionOnly(action DisruptiveAction) error

func (*SeclangActions) SetDisruptiveActionWithParam

func (s *SeclangActions) SetDisruptiveActionWithParam(action DisruptiveAction, value string) error

func (*SeclangActions) String

func (s *SeclangActions) String() string

func (*SeclangActions) ToString

func (s *SeclangActions) ToString() string

func (*SeclangActions) UnmarshalYAML

func (s *SeclangActions) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML unmarshals a YAML node into a SeclangActions struct it converts the actions to their respective types

type SeclangDirective

type SeclangDirective interface {
	GetKind() Kind
	ToSeclang() string
}

type SetvarAction

type SetvarAction struct {
	Collection  CollectionName  `yaml:"collection,omitempty"`
	Operation   VarOperation    `yaml:"operation,omitempty"`
	Assignments []VarAssignment `yaml:"assignments,omitempty"`
}

func NewSetvarAction

func NewSetvarAction(collection CollectionName, operation VarOperation, vars []VarAssignment) (SetvarAction, error)

NewSetvarAction creates a new SetvarAction with the given collection name, operation, and variable assignments

func (*SetvarAction) AppendAssignment

func (a *SetvarAction) AppendAssignment(variable, value string) error

func (SetvarAction) GetAllParams

func (a SetvarAction) GetAllParams() []string

func (SetvarAction) GetKey

func (a SetvarAction) GetKey() string

GetKey returns the action name (it is always "setvar")

func (SetvarAction) MarshalYAML

func (s SetvarAction) MarshalYAML() (interface{}, error)

func (SetvarAction) ToString

func (a SetvarAction) ToString() string

ToString allows to implement the Action interface

type Transformation

type Transformation int
const (
	UnknownTransformation Transformation = iota
	Base64Decode
	Base64DecodeExt
	Base64Encode
	CmdLine
	CompressWhitespace
	EscapeSeqDecode
	CssDecode
	HexEncode
	HexDecode
	HtmlEntityDecode
	JsDecode
	Length
	Lowercase
	Md5
	None
	NormalisePath

	NormalisePathWin

	ParityEven7bit
	ParityOdd7bit
	ParityZero7bit
	RemoveComments
	RemoveCommentsChar
	RemoveNulls
	RemoveWhitespace
	ReplaceComments
	ReplaceNulls
	Sha1
	SqlHexDecode
	Trim
	TrimLeft
	TrimRight
	Uppercase
	UrlEncode
	UrlDecode
	UrlDecodeUni
	Utf8toUnicode
)

func (Transformation) MarshalYAML

func (t Transformation) MarshalYAML() (interface{}, error)

func (Transformation) String

func (t Transformation) String() string

func (*Transformation) UnmarshalYAML

func (t *Transformation) UnmarshalYAML(unmarshal func(interface{}) error) error

type Transformations

type Transformations struct {
	Transformations []Transformation `yaml:"transformations,omitempty"`
}

func (*Transformations) AddTransformation

func (t *Transformations) AddTransformation(transformation string) error

func (Transformations) ToString

func (t Transformations) ToString() string

type UpdateActionDirective

type UpdateActionDirective struct {
	Kind    Kind         `yaml:"kind"`
	Comment string       `yaml:"comment,omitempty"`
	Id      int          `yaml:"id"`
	Modify  ModifyAction `yaml:"modify"`
}

func NewUpdateActionDirective

func NewUpdateActionDirective() *UpdateActionDirective

func (*UpdateActionDirective) AddTransformation

func (d *UpdateActionDirective) AddTransformation(t string) error

func (UpdateActionDirective) AppendChainedDirective

func (d UpdateActionDirective) AppendChainedDirective(directive ChainableDirective)

func (UpdateActionDirective) GetActions

func (d UpdateActionDirective) GetActions() *SeclangActions

func (UpdateActionDirective) GetKind

func (d UpdateActionDirective) GetKind() Kind

func (UpdateActionDirective) GetMetadata

func (d UpdateActionDirective) GetMetadata() Metadata

func (UpdateActionDirective) ToSeclang

func (d UpdateActionDirective) ToSeclang() string

type UpdateActionMetadata

type UpdateActionMetadata struct {
	Msg      string   `yaml:"message,omitempty"`
	Maturity string   `yaml:"maturity,omitempty"`
	Rev      string   `yaml:"revision,omitempty"`
	Severity string   `yaml:"severity,omitempty"`
	Tags     []string `yaml:"tags,omitempty"`
	Ver      string   `yaml:"version,omitempty"`
}

func (*UpdateActionMetadata) AddTag

func (m *UpdateActionMetadata) AddTag(value string)

func (*UpdateActionMetadata) SetComment

func (m *UpdateActionMetadata) SetComment(value string)

func (*UpdateActionMetadata) SetId

func (m *UpdateActionMetadata) SetId(value string)

func (*UpdateActionMetadata) SetMaturity

func (m *UpdateActionMetadata) SetMaturity(value string)

func (*UpdateActionMetadata) SetMsg

func (m *UpdateActionMetadata) SetMsg(value string)

func (*UpdateActionMetadata) SetPhase

func (m *UpdateActionMetadata) SetPhase(value string)

func (*UpdateActionMetadata) SetRev

func (m *UpdateActionMetadata) SetRev(value string)

func (*UpdateActionMetadata) SetSeverity

func (m *UpdateActionMetadata) SetSeverity(value string)

func (*UpdateActionMetadata) SetVer

func (m *UpdateActionMetadata) SetVer(value string)

func (*UpdateActionMetadata) ToString

func (s *UpdateActionMetadata) ToString() string

type UpdateTargetDirective

type UpdateTargetDirective struct {
	Kind        Kind             `yaml:"kind"`
	Metadata    *CommentMetadata `yaml:",inline"`
	Ids         []int            `yaml:"ids,omitempty"`
	Tags        []string         `yaml:"tags,omitempty"`
	Msgs        []string         `yaml:"msgs,omitempty"`
	Variables   []Variable       `yaml:"variables,omitempty"`
	Collections []Collection     `yaml:"collections,omitempty"`
}

func NewUpdateTargetDirective

func NewUpdateTargetDirective() *UpdateTargetDirective

func (*UpdateTargetDirective) AddCollection

func (d *UpdateTargetDirective) AddCollection(name, value string, excluded, asCount bool) error

func (*UpdateTargetDirective) AddVariable

func (d *UpdateTargetDirective) AddVariable(name string, excluded bool) error

func (UpdateTargetDirective) GetKind

func (d UpdateTargetDirective) GetKind() Kind

func (*UpdateTargetDirective) ToSeclang

func (d *UpdateTargetDirective) ToSeclang() string

type VarAssignment

type VarAssignment struct {
	Variable string `yaml:"variable"`
	Value    string `yaml:"value"`
}

func (VarAssignment) MarshalYAML

func (s VarAssignment) MarshalYAML() (interface{}, error)

type VarOperation

type VarOperation int
const (
	UnknownOp VarOperation = iota
	Assign
	Increment
	Decrement
)

func (VarOperation) String

func (v VarOperation) String() string

type Variable

type Variable struct {
	Name     VariableName `yaml:"name"`
	Excluded bool         `yaml:"excluded,omitempty"`
}

func (Variable) MarshalYAML

func (v Variable) MarshalYAML() (interface{}, error)

func (*Variable) UnmarshalYAML

func (v *Variable) UnmarshalYAML(value *yaml.Node) error

type VariableName

type VariableName int
const (
	UNKNOWN_VAR VariableName = iota
	ARGS_COMBINED_SIZE
	AUTH_TYPE
	DURATION
	FILES_COMBINED_SIZE
	FILES_NAMES
	FILES_SIZES
	FILES_TMP_CONTENT
	FILES_TMPNAMES
	FULL_REQUEST
	FULL_REQUEST_LENGTH
	HIGHEST_SEVERITY
	INBOUND_DATA_ERROR
	MATCHED_VAR
	MATCHED_VAR_NAME
	MODSEC_BUILD
	MSC_PCRE_LIMITS_EXCEEDED
	MULTIPART_CRLF_LF_LINES
	MULTIPART_FILENAME
	MULTIPART_NAME
	MULTIPART_STRICT_ERROR
	MULTIPART_UNMATCHED_BOUNDARY
	OUTBOUND_DATA_ERROR
	PATH_INFO
	PERF_ALL
	PERF_COMBINED
	PERF_GC
	PERF_LOGGING
	PERF_PHASE1
	PERF_PHASE2
	PERF_PHASE3
	PERF_PHASE4
	PERF_PHASE5
	PERF_SREAD
	PERF_SWRITE
	QUERY_STRING
	REMOTE_ADDR
	REMOTE_HOST
	REMOTE_PORT
	REMOTE_USER
	REQBODY_ERROR
	REQBODY_ERROR_MSG
	REQBODY_PROCESSOR
	REQUEST_BASENAME
	REQUEST_BODY
	REQUEST_BODY_LENGTH
	REQUEST_FILENAME
	REQUEST_LINE
	REQUEST_METHOD
	REQUEST_PROTOCOL
	REQUEST_URI
	REQUEST_URI_RAW
	RESPONSE_BODY
	RESPONSE_CONTENT_LENGTH
	RESPONSE_CONTENT_TYPE
	RESPONSE_PROTOCOL
	RESPONSE_STATUS
	SCRIPT_BASENAME
	SCRIPT_FILENAME
	SCRIPT_GID
	SCRIPT_GROUPNAME
	SCRIPT_MODE
	SCRIPT_UID
	SCRIPT_USERNAME
	SDBM_DELETE_ERROR
	SERVER_ADDR
	SERVER_NAME
	SERVER_PORT
	SESSIONID
	STATUS_LINE
	STREAM_INPUT_BODY
	STREAM_OUTPUT_BODY
	TIME
	TIME_DAY
	TIME_EPOCH
	TIME_HOUR
	TIME_MIN
	TIME_MON
	TIME_SEC
	TIME_WDAY
	TIME_YEAR
	UNIQUE_ID
	URLENCODED_ERROR
	USERAGENT_IP
	USERID
	WEBAPPID
	WEBSERVER_ERROR_LOG
	MSC_PCRE_ERROR
	MULTIPART_BOUNDARY_QUOTED
	MULTIPART_BOUNDARY_WHITESPACE
	MULTIPART_DATA_AFTER
	MULTIPART_DATA_BEFORE
	MULTIPART_FILE_LIMIT_EXCEEDED
	MULTIPART_HEADER_FOLDING
	MULTIPART_INVALID_HEADER_FOLDING
	MULTIPART_INVALID_PART
	MULTIPART_INVALID_QUOTING
	MULTIPART_LF_LINE
	MULTIPART_MISSING_SEMICOLON
	MULTIPART_SEMICOLON_MISSING
	REQBODY_PROCESSOR_ERROR
	REQBODY_PROCESSOR_ERROR_MSG
	STATUS
)

func (VariableName) MarshalYAML

func (v VariableName) MarshalYAML() (interface{}, error)

func (VariableName) String

func (v VariableName) String() string

func (*VariableName) UnmarshalYAML

func (v *VariableName) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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