Documentation
¶
Index ¶
- Constants
- func Load() (bool, error)
- func Usable() (bool, error)
- func Version() string
- type WAFBuilder
- type WAFConfig
- type WAFConfigLimits
- type WAFConfigObfuscator
- type WAFContext
- type WAFHandle
- type WAFLib
- func (waf *WAFLib) BuilderAddOrUpdateConfig(builder WAFBuilder, path string, config *WAFObject, diags *WAFObject) bool
- func (waf *WAFLib) BuilderBuildInstance(builder WAFBuilder) WAFHandle
- func (waf *WAFLib) BuilderDestroy(builder WAFBuilder)
- func (waf *WAFLib) BuilderGetConfigPaths(builder WAFBuilder, filter string) []string
- func (waf *WAFLib) BuilderInit(cfg *WAFConfig) WAFBuilder
- func (waf *WAFLib) BuilderRemoveConfig(builder WAFBuilder, path string) bool
- func (waf *WAFLib) Close() error
- func (waf *WAFLib) ContextDestroy(context WAFContext)
- func (waf *WAFLib) ContextInit(handle WAFHandle) WAFContext
- func (waf *WAFLib) Destroy(handle WAFHandle)
- func (waf *WAFLib) GetVersion() string
- func (waf *WAFLib) Handle() uintptr
- func (waf *WAFLib) KnownActions(handle WAFHandle) []string
- func (waf *WAFLib) KnownAddresses(handle WAFHandle) []string
- func (waf *WAFLib) ObjectFree(obj *WAFObject)
- func (waf *WAFLib) ObjectFromJSON(json []byte) (WAFObject, bool)
- func (waf *WAFLib) Run(context WAFContext, persistentData, ephemeralData *WAFObject, ...) WAFReturnCode
- func (waf *WAFLib) SetLogCb(cb uintptr, level log.Level)
- type WAFObject
- func (w *WAFObject) AnyValue() (any, error)
- func (w *WAFObject) ArrayValue() ([]any, error)
- func (w *WAFObject) BoolValue() (bool, error)
- func (w *WAFObject) FloatValue() (float64, error)
- func (w *WAFObject) IntValue() (int64, error)
- func (w *WAFObject) IsArray() bool
- func (w *WAFObject) IsBool() bool
- func (w *WAFObject) IsFloat() bool
- func (w *WAFObject) IsInt() bool
- func (w *WAFObject) IsInvalid() bool
- func (w *WAFObject) IsMap() bool
- func (w *WAFObject) IsNil() bool
- func (w *WAFObject) IsString() bool
- func (w *WAFObject) IsUint() bool
- func (w *WAFObject) IsUnusable() bool
- func (w *WAFObject) MapKey() string
- func (w *WAFObject) MapValue() (map[string]any, error)
- func (w *WAFObject) SetArray(pinner pin.Pinner, capacity uint64) []WAFObject
- func (w *WAFObject) SetArrayData(pinner pin.Pinner, data []WAFObject)
- func (w *WAFObject) SetBool(b bool)
- func (w *WAFObject) SetFloat(f float64)
- func (w *WAFObject) SetInt(i int64)
- func (w *WAFObject) SetInvalid()
- func (w *WAFObject) SetMap(pinner pin.Pinner, capacity uint64) []WAFObject
- func (w *WAFObject) SetMapData(pinner pin.Pinner, data []WAFObject)
- func (w *WAFObject) SetMapKey(pinner pin.Pinner, key string)
- func (w *WAFObject) SetNil()
- func (w *WAFObject) SetString(pinner pin.Pinner, str string)
- func (w *WAFObject) SetUint(i uint64)
- func (w *WAFObject) StringValue() (string, error)
- func (w *WAFObject) UIntValue() (uint64, error)
- func (w *WAFObject) Values() ([]WAFObject, error)
- type WAFObjectType
- type WAFResult
- type WAFReturnCode
Constants ¶
const ( MaxStringLength = 4096 MaxContainerDepth = 20 MaxContainerSize = 256 )
Variables ¶
This section is empty.
Functions ¶
func Load ¶ added in v4.5.0
Load loads libddwaf's dynamic library. The dynamic library is opened only once by the first call to this function and internally stored globally. No function is currently provided in this API to unload it.
This function is automatically called by [NewBuilder], and most users need not explicitly call it. It is however useful in order to explicitly check for the status of the Lib library's initialization.
The function returns true when libddwaf was successfully loaded, along with an error value. An error might still be returned even though the Lib load was successful: in such cases the error is indicative that some non-critical features are not available; but the Lib may still be used.
func Usable ¶ added in v4.5.0
Usable returns true if the Lib is usable, false and an error otherwise.
If the Lib is usable, an error value may still be returned and should be treated as a warning (it is non-blocking).
The following conditions are checked:
- The Lib library has been loaded successfully (you need to call Load first for this case to be taken into account)
- The Lib library has not been manually disabled with the `datadog.no_waf` go build tag
- The Lib library is not in an unsupported OS/Arch
- The Lib library is not in an unsupported Go version
Types ¶
type WAFBuilder ¶
type WAFBuilder uintptr
WAFBuilder is a forward declaration in ddwaf.h header We basically don't need to modify it, only to give it to the waf
type WAFConfig ¶
type WAFConfig struct {
Limits WAFConfigLimits
Obfuscator WAFConfigObfuscator
FreeFn uintptr
// contains filtered or unexported fields
}
type WAFConfigLimits ¶
type WAFConfigObfuscator ¶
type WAFContext ¶
type WAFContext uintptr
WAFContext is a forward declaration in ddwaf.h header We basically don't need to modify it, only to give it to the waf
type WAFHandle ¶
type WAFHandle uintptr
WAFHandle is a forward declaration in ddwaf.h header We basically don't need to modify it, only to give it to the waf
type WAFLib ¶
type WAFLib struct {
// contains filtered or unexported fields
}
WAFLib is the type wrapper for all C calls to the waf It uses `libwaf` to make C calls All calls must go through this one-liner to be type safe since purego calls are not type safe
var ( // Lib is libddwaf's dynamic library handle and entrypoints. This is only safe to // read after calling [Load] or having acquired [gMu]. Lib *WAFLib )
Globally dlopen() libddwaf only once because several dlopens (eg. in tests) aren't supported by macOS.
func (*WAFLib) BuilderAddOrUpdateConfig ¶
func (waf *WAFLib) BuilderAddOrUpdateConfig(builder WAFBuilder, path string, config *WAFObject, diags *WAFObject) bool
BuilderAddOrUpdateConfig adds or updates a configuration based on the given path, which must be a unique identifier for the provided configuration. Returns false in case of an error.
func (*WAFLib) BuilderBuildInstance ¶
func (waf *WAFLib) BuilderBuildInstance(builder WAFBuilder) WAFHandle
BuilderBuildInstance builds a WAF instance based on the current set of configurations. Returns nil in case of an error.
func (*WAFLib) BuilderDestroy ¶
func (waf *WAFLib) BuilderDestroy(builder WAFBuilder)
BuilderDestroy destroys a WAF builder instance.
func (*WAFLib) BuilderGetConfigPaths ¶
func (waf *WAFLib) BuilderGetConfigPaths(builder WAFBuilder, filter string) []string
BuilderGetConfigPaths returns the list of currently loaded paths. Returns nil in case of an error.
func (*WAFLib) BuilderInit ¶
func (waf *WAFLib) BuilderInit(cfg *WAFConfig) WAFBuilder
BuilderInit initializes a new WAF builder with the provided configuration, which may be nil. Returns nil in case of an error.
func (*WAFLib) BuilderRemoveConfig ¶
func (waf *WAFLib) BuilderRemoveConfig(builder WAFBuilder, path string) bool
BuilderRemoveConfig removes a configuration based on the provided path. Returns false in case of an error.
func (*WAFLib) ContextDestroy ¶
func (waf *WAFLib) ContextDestroy(context WAFContext)
func (*WAFLib) ContextInit ¶
func (waf *WAFLib) ContextInit(handle WAFHandle) WAFContext
func (*WAFLib) GetVersion ¶
GetVersion returned string is a static string so we do not need to free it
func (*WAFLib) KnownActions ¶
func (*WAFLib) KnownAddresses ¶
func (*WAFLib) ObjectFree ¶
func (*WAFLib) ObjectFromJSON ¶ added in v4.5.0
func (*WAFLib) Run ¶
func (waf *WAFLib) Run(context WAFContext, persistentData, ephemeralData *WAFObject, result *WAFObject, timeout uint64) WAFReturnCode
type WAFObject ¶
type WAFObject struct {
ParameterName uintptr
ParameterNameLength uint64
Value uintptr
NbEntries uint64
Type WAFObjectType
// contains filtered or unexported fields
}
func (*WAFObject) ArrayValue ¶ added in v4.2.0
func (*WAFObject) FloatValue ¶ added in v4.2.0
func (*WAFObject) IsBool ¶ added in v4.1.0
IsBool determines whether this WAF Object is a bool or not.
func (*WAFObject) IsFloat ¶ added in v4.1.0
IsFloat determines whether this WAF Object is a float or not.
func (*WAFObject) IsInvalid ¶
IsInvalid determines whether this WAF Object has the invalid type (which is the 0-value).
func (*WAFObject) IsString ¶ added in v4.2.0
IsString determines whether this WAF Object is a string or not.
func (*WAFObject) IsUint ¶ added in v4.1.0
IsUint determines whether this WAF Object is a uint or not.
func (*WAFObject) IsUnusable ¶
IsUnusable returns true if the wafObject has no impact on the WAF execution But we still need this kind of objects to forward map keys in case the value of the map is invalid
func (*WAFObject) SetArray ¶
SetArray sets the receiving WAFObject to a new array with the given capacity.
func (*WAFObject) SetArrayData ¶ added in v4.2.0
SetArrayData sets the receiving WAFObject to the provided array items.
func (*WAFObject) SetBool ¶ added in v4.1.0
SetBool sets the receiving WAFObject value to the given bool.
func (*WAFObject) SetFloat ¶ added in v4.1.0
SetFloat sets the receiving WAFObject value to the given float.
func (*WAFObject) SetInt ¶ added in v4.1.0
SetInt sets the receiving WAFObject value to the given int.
func (*WAFObject) SetInvalid ¶ added in v4.1.0
func (w *WAFObject) SetInvalid()
SetInvalid sets the receiving WAFObject to invalid.
func (*WAFObject) SetMap ¶
SetMap sets the receiving WAFObject to a new map with the given capacity.
func (*WAFObject) SetMapData ¶ added in v4.2.0
SetMapData sets the receiving WAFObject to the provided map items.
func (*WAFObject) SetMapKey ¶
SetMapKey sets the receiving WAFObject to a new map key with the given string.
func (*WAFObject) SetNil ¶ added in v4.1.0
func (w *WAFObject) SetNil()
SetNil sets the receiving WAFObject to nil.
func (*WAFObject) SetUint ¶ added in v4.1.0
SetUint sets the receiving WAFObject value to the given uint.
func (*WAFObject) StringValue ¶ added in v4.2.0
type WAFObjectType ¶
type WAFObjectType uint32
WAFObjectType is an enum in C which has the size of DWORD. But DWORD is 4 bytes in amd64 and arm64 so uint32 it is.
const ( WAFIntType WAFObjectType = 1 << iota WAFUintType WAFStringType WAFArrayType WAFMapType WAFBoolType WAFFloatType WAFNilType )
const WAFInvalidType WAFObjectType = 0
func (WAFObjectType) String ¶
func (w WAFObjectType) String() string
type WAFReturnCode ¶
type WAFReturnCode int32
const ( WAFErrInternal WAFReturnCode = iota - 3 WAFErrInvalidObject WAFErrInvalidArgument WAFOK WAFMatch )