Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
828f1c7bc5 | ||
|
|
8e3879a0c9 |
No files matched your search
@@ -817,8 +817,8 @@ The supported apps are:
|
|||||||
- `vaultwarden`;
|
- `vaultwarden`;
|
||||||
- `wordpress`.
|
- `wordpress`.
|
||||||
|
|
||||||
Each app's fixes are in one file, such as `internal/coreruleset/gitea.conf`, and
|
Each app's fixes are in one file named for the app, such as
|
||||||
one entry of `apps` in `internal/coreruleset/coreruleset.go`. gitea's fixes are:
|
`internal/coreruleset/apps/gitea.conf`. gitea's fixes are:
|
||||||
|
|
||||||
1. Ten parameters are not checked against the Core Rule Set's lists of system
|
1. Ten parameters are not checked against the Core Rule Set's lists of system
|
||||||
files (930120), shell paths (932160) and command names (932260), on any path:
|
files (930120), shell paths (932160) and command names (932260), on any path:
|
||||||
@@ -851,8 +851,8 @@ one entry of `apps` in `internal/coreruleset/coreruleset.go`. gitea's fixes are:
|
|||||||
3. On gitea's paths, some fields skip the rules that refused ordinary gitea
|
3. On gitea's paths, some fields skip the rules that refused ordinary gitea
|
||||||
requests there. They are the fields where gitea sends a search, a file's name
|
requests there. They are the fields where gitea sends a search, a file's name
|
||||||
or text, a commit message, a branch name or a repository's name.
|
or text, a commit message, a branch name or a repository's name.
|
||||||
`internal/coreruleset/gitea.conf` lists each rule and the request it refused.
|
`internal/coreruleset/apps/gitea.conf` lists each rule and the request it
|
||||||
The fields are:
|
refused. The fields are:
|
||||||
- `q` on gitea's searches of code, of issues and pull requests, and of
|
- `q` on gitea's searches of code, of issues and pull requests, and of
|
||||||
commits. A code search holds code, such as `<script>`,
|
commits. A code search holds code, such as `<script>`,
|
||||||
`SELECT * FROM users WHERE` or `../`. The searches of issues and pull
|
`SELECT * FROM users WHERE` or `../`. The searches of issues and pull
|
||||||
@@ -1037,7 +1037,7 @@ one entry of `apps` in `internal/coreruleset/coreruleset.go`. gitea's fixes are:
|
|||||||
- The `Content-Range` header of an artifact upload from
|
- The `Content-Range` header of an artifact upload from
|
||||||
`actions/upload-artifact@v3` (920450).
|
`actions/upload-artifact@v3` (920450).
|
||||||
- The passwords in a body, for each rule that random passwords set off. The
|
- The passwords in a body, for each rule that random passwords set off. The
|
||||||
numbers are in `internal/coreruleset/gitea.conf`.
|
numbers are in `internal/coreruleset/apps/gitea.conf`.
|
||||||
- `password` on these paths:
|
- `password` on these paths:
|
||||||
- `/user/login`, `/user/sign_up`, `/user/activate`;
|
- `/user/login`, `/user/sign_up`, `/user/activate`;
|
||||||
- `/user/link_account_signin` and `/user/link_account_signup`;
|
- `/user/link_account_signin` and `/user/link_account_signup`;
|
||||||
@@ -1069,8 +1069,8 @@ one entry of `apps` in `internal/coreruleset/coreruleset.go`. gitea's fixes are:
|
|||||||
such as `owner/python3-app` would have that push refused.
|
such as `owner/python3-app` would have that push refused.
|
||||||
|
|
||||||
WordPress's fixes: on WordPress's paths, some fields skip the rules that refused
|
WordPress's fixes: on WordPress's paths, some fields skip the rules that refused
|
||||||
ordinary WordPress requests there. `internal/coreruleset/wordpress.conf` lists
|
ordinary WordPress requests there. `internal/coreruleset/apps/wordpress.conf`
|
||||||
each rule and the request it refused. The REST API has four addresses:
|
lists each rule and the request it refused. The REST API has four addresses:
|
||||||
|
|
||||||
- `/wp-json/...`
|
- `/wp-json/...`
|
||||||
- `/index.php/wp-json/...`
|
- `/index.php/wp-json/...`
|
||||||
@@ -1162,9 +1162,9 @@ Elsewhere WordPress's fixes do not apply. The paths are those of WordPress at
|
|||||||
the site root.
|
the site root.
|
||||||
|
|
||||||
Drupal's fixes: on Drupal's paths, some fields skip the rules that refused
|
Drupal's fixes: on Drupal's paths, some fields skip the rules that refused
|
||||||
ordinary Drupal requests there. `internal/coreruleset/drupal.conf` lists each
|
ordinary Drupal requests there. `internal/coreruleset/apps/drupal.conf` lists
|
||||||
rule and the request it refused. These query fields skip the lists of system
|
each rule and the request it refused. These query fields skip the lists of
|
||||||
files and command names (930120, 932120, 932250, 932260):
|
system files and command names (930120, 932120, 932250, 932260):
|
||||||
|
|
||||||
- On every page under `/admin`: `title`, `name`, `user`, `filename`, `filemime`,
|
- On every page under `/admin`: `title`, `name`, `user`, `filename`, `filemime`,
|
||||||
`info`, `subject`, `author_name`, `search`, `q` and `destination`.
|
`info`, `subject`, `author_name`, `search`, `q` and `destination`.
|
||||||
@@ -1254,10 +1254,10 @@ first path segment of two or three lowercase letters, optionally followed by a
|
|||||||
hyphen and more letters, so `/api` counts too.
|
hyphen and more letters, so `/api` counts too.
|
||||||
|
|
||||||
MediaWiki's fixes: on MediaWiki's paths, some fields skip the rules that refused
|
MediaWiki's fixes: on MediaWiki's paths, some fields skip the rules that refused
|
||||||
ordinary MediaWiki requests there. `internal/coreruleset/mediawiki.conf` lists
|
ordinary MediaWiki requests there. `internal/coreruleset/apps/mediawiki.conf`
|
||||||
each rule and the request it refused. These fields skip the lists of system
|
lists each rule and the request it refused. These fields skip the lists of
|
||||||
files and command names (930120, 932120, 932250, 932260), in the query or the
|
system files and command names (930120, 932120, 932250, 932260), in the query or
|
||||||
body:
|
the body:
|
||||||
|
|
||||||
- On MediaWiki's pages, which are `/index.php` and the paths under `/index.php/`
|
- On MediaWiki's pages, which are `/index.php` and the paths under `/index.php/`
|
||||||
and `/wiki/`:
|
and `/wiki/`:
|
||||||
@@ -1363,9 +1363,9 @@ Elsewhere these fields keep every rule. The paths are those of MediaWiki at the
|
|||||||
site root or under `/w/`.
|
site root or under `/w/`.
|
||||||
|
|
||||||
Mastodon's fixes: on Mastodon's paths, some fields skip the rules that refused
|
Mastodon's fixes: on Mastodon's paths, some fields skip the rules that refused
|
||||||
ordinary Mastodon requests there. `internal/coreruleset/mastodon.conf` lists
|
ordinary Mastodon requests there. `internal/coreruleset/apps/mastodon.conf`
|
||||||
each rule and the request it refused. These fields skip the lists of system
|
lists each rule and the request it refused. These fields skip the lists of
|
||||||
files and command names (930120, 932120, 932250, 932260), in the query:
|
system files and command names (930120, 932120, 932250, 932260), in the query:
|
||||||
|
|
||||||
- On the API's search, accounts and admin accounts, under `/api/v1/` and
|
- On the API's search, accounts and admin accounts, under `/api/v1/` and
|
||||||
`/api/v2/`, the searches and names `q`, `acct`, `username`, `display_name`,
|
`/api/v2/`, the searches and names `q`, `acct`, `username`, `display_name`,
|
||||||
@@ -1526,7 +1526,7 @@ every rule.
|
|||||||
|
|
||||||
Vaultwarden's fixes: on Vaultwarden's paths, some fields skip the rules that
|
Vaultwarden's fixes: on Vaultwarden's paths, some fields skip the rules that
|
||||||
refused ordinary Vaultwarden requests there.
|
refused ordinary Vaultwarden requests there.
|
||||||
`internal/coreruleset/vaultwarden.conf` lists each rule and the request it
|
`internal/coreruleset/apps/vaultwarden.conf` lists each rule and the request it
|
||||||
refused. The apps encrypt vault items, folders, collections and sends before
|
refused. The apps encrypt vault items, folders, collections and sends before
|
||||||
sending them, so those fields skip no rules. The fields below hold plain text.
|
sending them, so those fields skip no rules. The fields below hold plain text.
|
||||||
|
|
||||||
@@ -1577,8 +1577,8 @@ has a parameter of the same name.
|
|||||||
|
|
||||||
`token` in the body of `/admin`, the admin token typed on the admin page, skips
|
`token` in the body of `/admin`, the admin token typed on the admin page, skips
|
||||||
each rule that random passwords set off. The numbers are in
|
each rule that random passwords set off. The numbers are in
|
||||||
`internal/coreruleset/vaultwarden.conf`. It applies only when the query has no
|
`internal/coreruleset/apps/vaultwarden.conf`. It applies only when the query has
|
||||||
`token` parameter. `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and
|
no `token` parameter. `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and
|
||||||
`<img src=x onerror=x()>` sent as the token reach Vaultwarden;
|
`<img src=x onerror=x()>` sent as the token reach Vaultwarden;
|
||||||
`<script>alert(1)</script>` and `javascript:alert(1)` are still refused.
|
`<script>alert(1)</script>` and `javascript:alert(1)` are still refused.
|
||||||
|
|
||||||
@@ -1600,7 +1600,7 @@ Elsewhere these fields keep every rule.
|
|||||||
|
|
||||||
Nextcloud's fixes: on Nextcloud's paths, some fields skip the rules that refused
|
Nextcloud's fixes: on Nextcloud's paths, some fields skip the rules that refused
|
||||||
ordinary Nextcloud requests there, and its WebDAV methods are allowed.
|
ordinary Nextcloud requests there, and its WebDAV methods are allowed.
|
||||||
`internal/coreruleset/nextcloud.conf` lists each rule and the request it
|
`internal/coreruleset/apps/nextcloud.conf` lists each rule and the request it
|
||||||
refused.
|
refused.
|
||||||
|
|
||||||
The sync client and the Files app use WebDAV on these paths:
|
The sync client and the Files app use WebDAV on these paths:
|
||||||
@@ -1610,7 +1610,8 @@ The sync client and the Files app use WebDAV on these paths:
|
|||||||
- `/remote.php/webdav/`;
|
- `/remote.php/webdav/`;
|
||||||
- `/public.php/webdav/`.
|
- `/public.php/webdav/`.
|
||||||
|
|
||||||
These methods are allowed there, besides those of the first change:
|
These methods are allowed there, besides `PUT`, `PATCH` and `DELETE`, which
|
||||||
|
every app gets:
|
||||||
|
|
||||||
- `PROPFIND` and `PROPPATCH`;
|
- `PROPFIND` and `PROPPATCH`;
|
||||||
- `MKCOL`;
|
- `MKCOL`;
|
||||||
@@ -1754,7 +1755,7 @@ gets gitea's fixes too. Forgejo's own fixes hold only what Forgejo sends and
|
|||||||
gitea does not.
|
gitea does not.
|
||||||
|
|
||||||
On Forgejo's paths, some fields skip the rules that refused ordinary Forgejo
|
On Forgejo's paths, some fields skip the rules that refused ordinary Forgejo
|
||||||
requests there. `internal/coreruleset/forgejo.conf` lists each rule and the
|
requests there. `internal/coreruleset/apps/forgejo.conf` lists each rule and the
|
||||||
request it refused.
|
request it refused.
|
||||||
|
|
||||||
`q` skips rules on some of Forgejo's searches. The searches are:
|
`q` skips rules on some of Forgejo's searches. The searches are:
|
||||||
@@ -1800,10 +1801,10 @@ The Core Rule Set reads the request without the `flash` cookie, in which Forgejo
|
|||||||
puts what gitea puts in `gitea_flash` (gitea's second fix).
|
puts what gitea puts in `gitea_flash` (gitea's second fix).
|
||||||
|
|
||||||
Ghost's fixes: on Ghost's paths, some fields skip the rules that refused
|
Ghost's fixes: on Ghost's paths, some fields skip the rules that refused
|
||||||
ordinary Ghost requests there. `internal/coreruleset/ghost.conf` lists each rule
|
ordinary Ghost requests there. `internal/coreruleset/apps/ghost.conf` lists each
|
||||||
and the request it refused. Ghost's admin and integrations call the Admin API
|
rule and the request it refused. Ghost's admin and integrations call the Admin
|
||||||
under `/ghost/api/admin/`. Themes and Ghost's scripts call the Content API under
|
API under `/ghost/api/admin/`. Themes and Ghost's scripts call the Content API
|
||||||
`/ghost/api/content/`, and members call `/members/api/`. The admin calls
|
under `/ghost/api/content/`, and members call `/members/api/`. The admin calls
|
||||||
ActivityPub, a service of its own, under `/.ghost/activitypub/`.
|
ActivityPub, a service of its own, under `/.ghost/activitypub/`.
|
||||||
|
|
||||||
Eight rules refused words that name commands and files, such as `python3`,
|
Eight rules refused words that name commands and files, such as `python3`,
|
||||||
@@ -1941,9 +1942,9 @@ That name holds `.profile`, a file on the list of system files, so the name
|
|||||||
skips 930120 when a profile is saved.
|
skips 930120 when a profile is saved.
|
||||||
|
|
||||||
The passwords skip each rule that random passwords set off. The numbers are in
|
The passwords skip each rule that random passwords set off. The numbers are in
|
||||||
`internal/coreruleset/ghost.conf`. They are `password` when signing in, and the
|
`internal/coreruleset/apps/ghost.conf`. They are `password` when signing in, and
|
||||||
passwords sent when creating the first staff user, accepting an invitation, and
|
the passwords sent when creating the first staff user, accepting an invitation,
|
||||||
resetting or changing a password. `' OR '1'='1`, `../../etc/passwd`,
|
and resetting or changing a password. `' OR '1'='1`, `../../etc/passwd`,
|
||||||
`; cat /etc/passwd` and `<img src=x onerror=x()>` sent as a password reach
|
`; cat /etc/passwd` and `<img src=x onerror=x()>` sent as a password reach
|
||||||
Ghost; `<script>alert(1)</script>` and `javascript:alert(1)` are still refused.
|
Ghost; `<script>alert(1)</script>` and `javascript:alert(1)` are still refused.
|
||||||
|
|
||||||
|
|||||||
+32
-93
@@ -75,7 +75,7 @@ type WAF struct {
|
|||||||
BytesLimitPerMinute int64
|
BytesLimitPerMinute int64
|
||||||
BytesLimitPerHour int64
|
BytesLimitPerHour int64
|
||||||
BytesLimitPerDay int64
|
BytesLimitPerDay int64
|
||||||
BytesCounted BytesCounted
|
BytesCounted string
|
||||||
// LookupSource is where each client's AS number and country are looked
|
// LookupSource is where each client's AS number and country are looked
|
||||||
// up (SWW_WAF_LOOKUP_SOURCE): geojs, file, or off for nowhere.
|
// up (SWW_WAF_LOOKUP_SOURCE): geojs, file, or off for nowhere.
|
||||||
// LookupDBPath is the lookup database, the IPinfo Lite file looked up in
|
// LookupDBPath is the lookup database, the IPinfo Lite file looked up in
|
||||||
@@ -86,7 +86,7 @@ type WAF struct {
|
|||||||
// AddLookupHeaders is true when the app is passed the client's AS number
|
// AddLookupHeaders is true when the app is passed the client's AS number
|
||||||
// and country in headers (SWW_WAF_ADD_LOOKUP_HEADERS), by default unless
|
// and country in headers (SWW_WAF_ADD_LOOKUP_HEADERS), by default unless
|
||||||
// LookupSource is off.
|
// LookupSource is off.
|
||||||
LookupSource LookupSource
|
LookupSource string
|
||||||
LookupDBPath string
|
LookupDBPath string
|
||||||
ASNAndCountryLookupTimeout time.Duration
|
ASNAndCountryLookupTimeout time.Duration
|
||||||
AddLookupHeaders bool
|
AddLookupHeaders bool
|
||||||
@@ -131,7 +131,7 @@ type WAF struct {
|
|||||||
// BlocklistLimitPercent is the percentage of every limit it gets.
|
// BlocklistLimitPercent is the percentage of every limit it gets.
|
||||||
BlocklistURLs []string
|
BlocklistURLs []string
|
||||||
BlocklistRefresh time.Duration
|
BlocklistRefresh time.Duration
|
||||||
BlocklistAction ReputationAction
|
BlocklistAction string
|
||||||
BlocklistLimitPercent int64
|
BlocklistLimitPercent int64
|
||||||
// DNSBLZones are the DNSBL zones clients are asked about
|
// DNSBLZones are the DNSBL zones clients are asked about
|
||||||
// (SWW_WAF_DNSBL_ZONES), through DNSBLResolver (SWW_WAF_DNSBL_RESOLVER), or
|
// (SWW_WAF_DNSBL_ZONES), through DNSBLResolver (SWW_WAF_DNSBL_RESOLVER), or
|
||||||
@@ -154,7 +154,7 @@ type WAF struct {
|
|||||||
AbuseIPDBKey string
|
AbuseIPDBKey string
|
||||||
AbuseIPDBMinScore int64
|
AbuseIPDBMinScore int64
|
||||||
AbuseIPDBDailyBudget int
|
AbuseIPDBDailyBudget int
|
||||||
DNSBLAbuseIPDBAction ReputationAction
|
DNSBLAbuseIPDBAction string
|
||||||
DNSBLAbuseIPDBLimitPercent int64
|
DNSBLAbuseIPDBLimitPercent int64
|
||||||
IPReputationCacheTTL time.Duration
|
IPReputationCacheTTL time.Duration
|
||||||
DNSBLAbuseIPDBTimeout time.Duration
|
DNSBLAbuseIPDBTimeout time.Duration
|
||||||
@@ -237,7 +237,7 @@ type WAF struct {
|
|||||||
// reads none.
|
// reads none.
|
||||||
// CoreRuleSetExclusionsFile is the path of the file of its exclusions
|
// CoreRuleSetExclusionsFile is the path of the file of its exclusions
|
||||||
// (SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE), "" while there is none.
|
// (SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE), "" while there is none.
|
||||||
CoreRuleSetMode CoreRuleSetMode
|
CoreRuleSetMode string
|
||||||
CoreRuleSetParanoiaLevel int
|
CoreRuleSetParanoiaLevel int
|
||||||
CoreRuleSetScoreThreshold int
|
CoreRuleSetScoreThreshold int
|
||||||
CoreRuleSetDisabledRules []int
|
CoreRuleSetDisabledRules []int
|
||||||
@@ -316,66 +316,20 @@ type WAF struct {
|
|||||||
settings []slog.Attr
|
settings []slog.Attr
|
||||||
}
|
}
|
||||||
|
|
||||||
// BytesCounted is which body bytes count toward the byte limits and the
|
|
||||||
// byte anomaly thresholds, a value of SWW_WAF_BYTES_COUNTED.
|
|
||||||
type BytesCounted string
|
|
||||||
|
|
||||||
// The values of SWW_WAF_BYTES_COUNTED.
|
|
||||||
const (
|
|
||||||
// BytesCountedResponse counts the response's body bytes.
|
|
||||||
BytesCountedResponse BytesCounted = "response"
|
|
||||||
// BytesCountedRequest counts the request's body bytes.
|
|
||||||
BytesCountedRequest BytesCounted = "request"
|
|
||||||
// BytesCountedBoth counts the body bytes of both.
|
|
||||||
BytesCountedBoth BytesCounted = "both"
|
|
||||||
)
|
|
||||||
|
|
||||||
// LookupSource is where each client's AS number and country are looked up,
|
|
||||||
// a value of SWW_WAF_LOOKUP_SOURCE.
|
|
||||||
type LookupSource string
|
|
||||||
|
|
||||||
// The values of SWW_WAF_LOOKUP_SOURCE.
|
|
||||||
const (
|
|
||||||
// LookupSourceGeoJS asks GeoJS.
|
|
||||||
LookupSourceGeoJS LookupSource = "geojs"
|
|
||||||
// LookupSourceFile looks clients up in the lookup database, the file
|
|
||||||
// SWW_WAF_LOOKUP_DB_PATH names.
|
|
||||||
LookupSourceFile LookupSource = "file"
|
|
||||||
// LookupSourceOff looks no client up.
|
|
||||||
LookupSourceOff LookupSource = "off"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReputationAction is what is done with a client a reputation source
|
|
||||||
// lists, a value of SWW_WAF_BLOCKLIST_ACTION and of
|
|
||||||
// SWW_WAF_DNSBL_ABUSEIPDB_ACTION.
|
|
||||||
type ReputationAction string
|
|
||||||
|
|
||||||
// The values of SWW_WAF_BLOCKLIST_ACTION and SWW_WAF_DNSBL_ABUSEIPDB_ACTION.
|
|
||||||
const (
|
|
||||||
// ReputationActionDeny refuses the client's requests.
|
|
||||||
ReputationActionDeny ReputationAction = "deny"
|
|
||||||
// ReputationActionLimit gives the client a percentage of every limit,
|
|
||||||
// written limit:<percent> in the setting.
|
|
||||||
ReputationActionLimit ReputationAction = "limit"
|
|
||||||
// ReputationActionLog only notes the hit in the log line and raises an
|
|
||||||
// alert.
|
|
||||||
ReputationActionLog ReputationAction = "log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CoreRuleSetMode is what the Core Rule Set does, a value of
|
|
||||||
// SWW_WAF_CORE_RULE_SET_MODE.
|
|
||||||
type CoreRuleSetMode string
|
|
||||||
|
|
||||||
// The values of SWW_WAF_CORE_RULE_SET_MODE.
|
// The values of SWW_WAF_CORE_RULE_SET_MODE.
|
||||||
const (
|
const (
|
||||||
// CoreRuleSetModeOff runs no request through the Core Rule Set.
|
// CoreRuleSetModeOff runs no request through the Core Rule Set.
|
||||||
CoreRuleSetModeOff CoreRuleSetMode = "off"
|
CoreRuleSetModeOff = off
|
||||||
// CoreRuleSetModeDetect logs and alerts a match, and refuses nothing.
|
// CoreRuleSetModeDetect logs and alerts a match, and refuses nothing.
|
||||||
CoreRuleSetModeDetect CoreRuleSetMode = "detect"
|
CoreRuleSetModeDetect = "detect"
|
||||||
// CoreRuleSetModeBlock refuses a match with 403.
|
// CoreRuleSetModeBlock refuses a match with 403.
|
||||||
CoreRuleSetModeBlock CoreRuleSetMode = "block"
|
CoreRuleSetModeBlock = "block"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// fileSource is the SWW_WAF_LOOKUP_SOURCE that looks clients up in the
|
||||||
|
// lookup database, the file SWW_WAF_LOOKUP_DB_PATH names.
|
||||||
|
const fileSource = "file"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
day = 24 * time.Hour
|
day = 24 * time.Hour
|
||||||
ipv4Bits = 32
|
ipv4Bits = 32
|
||||||
@@ -604,13 +558,10 @@ func WAFFromEnvironment(v *viper.Viper) (*WAF, error) {
|
|||||||
),
|
),
|
||||||
BytesLimitPerHour: env.size("SWW_WAF_BYTES_LIMIT_PER_HOUR", "50G"),
|
BytesLimitPerHour: env.size("SWW_WAF_BYTES_LIMIT_PER_HOUR", "50G"),
|
||||||
BytesLimitPerDay: env.size("SWW_WAF_BYTES_LIMIT_PER_DAY", "100G"),
|
BytesLimitPerDay: env.size("SWW_WAF_BYTES_LIMIT_PER_DAY", "100G"),
|
||||||
BytesCounted: env.bytesCounted(
|
BytesCounted: env.bytesCounted("SWW_WAF_BYTES_COUNTED", "both"),
|
||||||
"SWW_WAF_BYTES_COUNTED",
|
|
||||||
BytesCountedBoth,
|
|
||||||
),
|
|
||||||
LookupSource: env.lookupSource(
|
LookupSource: env.lookupSource(
|
||||||
"SWW_WAF_LOOKUP_SOURCE",
|
"SWW_WAF_LOOKUP_SOURCE",
|
||||||
LookupSourceGeoJS,
|
"geojs",
|
||||||
),
|
),
|
||||||
LookupDBPath: env.value("SWW_WAF_LOOKUP_DB_PATH", ""),
|
LookupDBPath: env.value("SWW_WAF_LOOKUP_DB_PATH", ""),
|
||||||
ASNAndCountryLookupTimeout: env.milliseconds(
|
ASNAndCountryLookupTimeout: env.milliseconds(
|
||||||
@@ -807,9 +758,9 @@ func WAFFromEnvironment(v *viper.Viper) (*WAF, error) {
|
|||||||
cfg.InstanceName, cfg.LogRemoteURL != nil)
|
cfg.InstanceName, cfg.LogRemoteURL != nil)
|
||||||
// The app gets the headers by default, unless no client is looked up.
|
// The app gets the headers by default, unless no client is looked up.
|
||||||
cfg.AddLookupHeaders = env.boolean("SWW_WAF_ADD_LOOKUP_HEADERS",
|
cfg.AddLookupHeaders = env.boolean("SWW_WAF_ADD_LOOKUP_HEADERS",
|
||||||
strconv.FormatBool(cfg.LookupSource != LookupSourceOff))
|
strconv.FormatBool(cfg.LookupSource != off))
|
||||||
cfg.BlocklistAction, cfg.BlocklistLimitPercent = env.action(
|
cfg.BlocklistAction, cfg.BlocklistLimitPercent = env.action(
|
||||||
"SWW_WAF_BLOCKLIST_ACTION", string(ReputationActionDeny))
|
"SWW_WAF_BLOCKLIST_ACTION", "deny")
|
||||||
cfg.DNSBLAbuseIPDBAction, cfg.DNSBLAbuseIPDBLimitPercent = env.action(
|
cfg.DNSBLAbuseIPDBAction, cfg.DNSBLAbuseIPDBLimitPercent = env.action(
|
||||||
"SWW_WAF_DNSBL_ABUSEIPDB_ACTION", "limit:25")
|
"SWW_WAF_DNSBL_ABUSEIPDB_ACTION", "limit:25")
|
||||||
|
|
||||||
@@ -907,12 +858,9 @@ func (e *environment) count(name, defaultValue string) int64 {
|
|||||||
|
|
||||||
// bytesCounted reads the setting that is which body bytes count toward the
|
// bytesCounted reads the setting that is which body bytes count toward the
|
||||||
// byte limits and the byte anomaly thresholds: response, request or both.
|
// byte limits and the byte anomaly thresholds: response, request or both.
|
||||||
func (e *environment) bytesCounted(
|
func (e *environment) bytesCounted(name, defaultValue string) string {
|
||||||
name string, defaultValue BytesCounted,
|
value := e.value(name, defaultValue)
|
||||||
) BytesCounted {
|
if value != "response" && value != "request" && value != "both" {
|
||||||
value := BytesCounted(e.value(name, string(defaultValue)))
|
|
||||||
if value != BytesCountedResponse && value != BytesCountedRequest &&
|
|
||||||
value != BytesCountedBoth {
|
|
||||||
e.check(name, fmt.Errorf("%q %w", value, errNotBytesCounted))
|
e.check(name, fmt.Errorf("%q %w", value, errNotBytesCounted))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -957,10 +905,8 @@ func (e *environment) trapPaths(name string) []string {
|
|||||||
|
|
||||||
// coreRuleSetMode reads the setting that is what the Core Rule Set does: off,
|
// coreRuleSetMode reads the setting that is what the Core Rule Set does: off,
|
||||||
// detect or block.
|
// detect or block.
|
||||||
func (e *environment) coreRuleSetMode(
|
func (e *environment) coreRuleSetMode(name, defaultValue string) string {
|
||||||
name string, defaultValue CoreRuleSetMode,
|
mode := e.value(name, defaultValue)
|
||||||
) CoreRuleSetMode {
|
|
||||||
mode := CoreRuleSetMode(e.value(name, string(defaultValue)))
|
|
||||||
if mode != CoreRuleSetModeOff && mode != CoreRuleSetModeDetect &&
|
if mode != CoreRuleSetModeOff && mode != CoreRuleSetModeDetect &&
|
||||||
mode != CoreRuleSetModeBlock {
|
mode != CoreRuleSetModeBlock {
|
||||||
e.check(name, fmt.Errorf("%q %w", mode, errNotCoreRuleSetMode))
|
e.check(name, fmt.Errorf("%q %w", mode, errNotCoreRuleSetMode))
|
||||||
@@ -1110,24 +1056,20 @@ func (e *environment) refresh(name, defaultValue string) time.Duration {
|
|||||||
// action reads a setting that is what is done with a client a blocklist
|
// action reads a setting that is what is done with a client a blocklist
|
||||||
// or a DNSBL zone lists: deny, log, or limit:<percent>, which it returns
|
// or a DNSBL zone lists: deny, log, or limit:<percent>, which it returns
|
||||||
// as limit and the percentage.
|
// as limit and the percentage.
|
||||||
func (e *environment) action(
|
func (e *environment) action(name, defaultValue string) (string, int64) {
|
||||||
name, defaultValue string,
|
value := e.value(name, defaultValue)
|
||||||
) (ReputationAction, int64) {
|
if value == "deny" || value == "log" {
|
||||||
value := ReputationAction(e.value(name, defaultValue))
|
|
||||||
if value == ReputationActionDeny || value == ReputationActionLog {
|
|
||||||
return value, 0
|
return value, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
percentText, isLimit := strings.CutPrefix(
|
percentText, isLimit := strings.CutPrefix(value, "limit:")
|
||||||
string(value), string(ReputationActionLimit)+":",
|
|
||||||
)
|
|
||||||
|
|
||||||
percent, err := ParsePercent(percentText)
|
percent, err := ParsePercent(percentText)
|
||||||
if !isLimit || err != nil {
|
if !isLimit || err != nil {
|
||||||
e.check(name, fmt.Errorf("%q %w", value, errNotAction))
|
e.check(name, fmt.Errorf("%q %w", value, errNotAction))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReputationActionLimit, percent
|
return "limit", percent
|
||||||
}
|
}
|
||||||
|
|
||||||
// zones reads the setting that is the list of DNSBL zones. It is empty by
|
// zones reads the setting that is the list of DNSBL zones. It is empty by
|
||||||
@@ -1178,12 +1120,9 @@ func (e *environment) routeWatchURL(name string) string {
|
|||||||
|
|
||||||
// lookupSource reads the setting that is where clients are looked up:
|
// lookupSource reads the setting that is where clients are looked up:
|
||||||
// geojs, file, or off.
|
// geojs, file, or off.
|
||||||
func (e *environment) lookupSource(
|
func (e *environment) lookupSource(name, defaultValue string) string {
|
||||||
name string, defaultValue LookupSource,
|
source := e.value(name, defaultValue)
|
||||||
) LookupSource {
|
if source != "geojs" && source != fileSource && source != off {
|
||||||
source := LookupSource(e.value(name, string(defaultValue)))
|
|
||||||
if source != LookupSourceGeoJS && source != LookupSourceFile &&
|
|
||||||
source != LookupSourceOff {
|
|
||||||
e.check(name, fmt.Errorf("%q %w", source, errNotLookupSource))
|
e.check(name, fmt.Errorf("%q %w", source, errNotLookupSource))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1195,12 +1134,12 @@ func (e *environment) lookupSource(
|
|||||||
// one source at a time.
|
// one source at a time.
|
||||||
func (e *environment) checkLookupDBPath(cfg *WAF) {
|
func (e *environment) checkLookupDBPath(cfg *WAF) {
|
||||||
switch {
|
switch {
|
||||||
case cfg.LookupSource == LookupSourceFile && cfg.LookupDBPath == "":
|
case cfg.LookupSource == fileSource && cfg.LookupDBPath == "":
|
||||||
e.check("SWW_WAF_LOOKUP_SOURCE", fmt.Errorf(
|
e.check("SWW_WAF_LOOKUP_SOURCE", fmt.Errorf(
|
||||||
"is file while SWW_WAF_LOOKUP_DB_PATH is unset; %w",
|
"is file while SWW_WAF_LOOKUP_DB_PATH is unset; %w",
|
||||||
errNeedsDBPath,
|
errNeedsDBPath,
|
||||||
))
|
))
|
||||||
case cfg.LookupSource != LookupSourceFile && cfg.LookupDBPath != "":
|
case cfg.LookupSource != fileSource && cfg.LookupDBPath != "":
|
||||||
e.check("SWW_WAF_LOOKUP_DB_PATH", fmt.Errorf(
|
e.check("SWW_WAF_LOOKUP_DB_PATH", fmt.Errorf(
|
||||||
"is set while SWW_WAF_LOOKUP_SOURCE is %s; %w",
|
"is set while SWW_WAF_LOOKUP_SOURCE is %s; %w",
|
||||||
cfg.LookupSource,
|
cfg.LookupSource,
|
||||||
@@ -1225,7 +1164,7 @@ func (e *environment) checkCountriesAndLookups(cfg *WAF) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.LookupSource != LookupSourceOff {
|
if cfg.LookupSource != off {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -614,7 +614,7 @@ func TestCoreRuleSetSettings(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
environment{
|
environment{
|
||||||
coreRuleSetMode: string(config.CoreRuleSetModeDetect),
|
coreRuleSetMode: config.CoreRuleSetModeDetect,
|
||||||
coreRuleSetParanoiaLevel: "4",
|
coreRuleSetParanoiaLevel: "4",
|
||||||
coreRuleSetScoreThreshold: "10",
|
coreRuleSetScoreThreshold: "10",
|
||||||
coreRuleSetDisabledRules: "942100, 920350",
|
coreRuleSetDisabledRules: "942100, 920350",
|
||||||
@@ -2033,8 +2033,7 @@ func TestReputationSettingsAsSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
value string
|
value, action string
|
||||||
action config.ReputationAction
|
|
||||||
percent int64
|
percent int64
|
||||||
}{
|
}{
|
||||||
{actionDeny, actionDeny, 0},
|
{actionDeny, actionDeny, 0},
|
||||||
@@ -2168,7 +2167,7 @@ func TestDNSBLSettingsAsSet(t *testing.T) {
|
|||||||
// want are the zones, resolver, action and percent config.WAF gives.
|
// want are the zones, resolver, action and percent config.WAF gives.
|
||||||
want []string
|
want []string
|
||||||
wantResolver string
|
wantResolver string
|
||||||
wantAction config.ReputationAction
|
wantAction string
|
||||||
wantPercent int64
|
wantPercent int64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@@ -3050,7 +3049,7 @@ func TestLogsEachSettingWithItsValue(t *testing.T) {
|
|||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
ruleFilesDir: "/etc/sww/rules.d",
|
ruleFilesDir: "/etc/sww/rules.d",
|
||||||
ruleFilesEnabled: "true",
|
ruleFilesEnabled: "true",
|
||||||
coreRuleSetMode: string(config.CoreRuleSetModeBlock),
|
coreRuleSetMode: config.CoreRuleSetModeBlock,
|
||||||
coreRuleSetParanoiaLevel: "1",
|
coreRuleSetParanoiaLevel: "1",
|
||||||
coreRuleSetScoreThreshold: "5",
|
coreRuleSetScoreThreshold: "5",
|
||||||
coreRuleSetDisabledRules: defaultCoreRuleSetDisabledRules,
|
coreRuleSetDisabledRules: defaultCoreRuleSetDisabledRules,
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -37,9 +37,10 @@
|
|||||||
SecRule &TX:app_nextcloud "@eq 0" \
|
SecRule &TX:app_nextcloud "@eq 0" \
|
||||||
"id:900090,phase:1,pass,nolog,skipAfter:END_NEXTCLOUD"
|
"id:900090,phase:1,pass,nolog,skipAfter:END_NEXTCLOUD"
|
||||||
|
|
||||||
# The sync client and the Files app use these WebDAV methods besides those
|
# The sync client and the Files app use these WebDAV methods besides PUT,
|
||||||
# the first change allows, on /remote.php/dav/ and /public.php/dav/ and on the
|
# PATCH and DELETE, which sww allows for every app, on /remote.php/dav/ and
|
||||||
# older /remote.php/webdav/ and /public.php/webdav/. 911100 refused each:
|
# /public.php/dav/ and on the older /remote.php/webdav/ and /public.php/webdav/.
|
||||||
|
# 911100 refused each:
|
||||||
# PROPFIND, PROPPATCH: listing a folder, marking a file a favourite
|
# PROPFIND, PROPPATCH: listing a folder, marking a file a favourite
|
||||||
# MKCOL: making a folder, and starting a chunked upload
|
# MKCOL: making a folder, and starting a chunked upload
|
||||||
# COPY, MOVE: copying, moving and renaming, and ending a chunked upload
|
# COPY, MOVE: copying, moving and renaming, and ending a chunked upload
|
||||||
File renamed without changes.
File renamed without changes.
@@ -12,11 +12,10 @@
|
|||||||
package coreruleset
|
package coreruleset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"maps"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@@ -35,7 +34,7 @@ import (
|
|||||||
// directives are the Core Rule Set as sww runs it, with the
|
// directives are the Core Rule Set as sww runs it, with the
|
||||||
// paranoia level for %d, bodyDirectives for the first %s while
|
// paranoia level for %d, bodyDirectives for the first %s while
|
||||||
// SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set, the exclusions file for
|
// SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set, the exclusions file for
|
||||||
// the second, and the directives of every app in apps for the third.
|
// the second, and the fixes of every app in appFixes for the third.
|
||||||
// Each rule sww adds has an id from 900000 to 900999, the ids the
|
// Each rule sww adds has an id from 900000 to 900999, the ids the
|
||||||
// Core Rule Set keeps for the rules that set it up, which
|
// Core Rule Set keeps for the rules that set it up, which
|
||||||
// SWW_WAF_CORE_RULE_SET_DISABLED_RULES and the exclusions file refuse, so that no
|
// SWW_WAF_CORE_RULE_SET_DISABLED_RULES and the exclusions file refuse, so that no
|
||||||
@@ -54,13 +53,12 @@ Include @crs-setup.conf.example
|
|||||||
SecAction "id:900000,phase:1,pass,nolog,\
|
SecAction "id:900000,phase:1,pass,nolog,\
|
||||||
setvar:tx.blocking_paranoia_level=%d"
|
setvar:tx.blocking_paranoia_level=%d"
|
||||||
|
|
||||||
# The first change: PUT, PATCH and DELETE are allowed besides GET, HEAD,
|
# PUT, PATCH and DELETE are allowed besides GET, HEAD, POST and OPTIONS.
|
||||||
# POST and OPTIONS.
|
|
||||||
SecAction "id:900200,phase:1,pass,nolog,\
|
SecAction "id:900200,phase:1,pass,nolog,\
|
||||||
setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'"
|
setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'"
|
||||||
|
|
||||||
# The second: Expect and Content-Encoding are taken off the Core Rule Set's
|
# Expect and Content-Encoding are taken off the Core Rule Set's list of the
|
||||||
# list of the headers it refuses. Content-Encoding goes back on it for a
|
# headers it refuses. Content-Encoding goes back on it for a
|
||||||
# body the Core Rule Set reads (900260 in bodyDirectives).
|
# body the Core Rule Set reads (900260 in bodyDirectives).
|
||||||
SecAction "id:900250,phase:1,pass,nolog,\
|
SecAction "id:900250,phase:1,pass,nolog,\
|
||||||
setvar:'tx.restricted_headers_basic=/proxy/ /lock-token/ /content-range/ \
|
setvar:'tx.restricted_headers_basic=/proxy/ /lock-token/ /content-range/ \
|
||||||
@@ -86,18 +84,17 @@ SecRule ARGUMENTS_LIMIT_REACHED "@eq 1" "id:900300,phase:2,pass,\
|
|||||||
# The apps' fixes come before the rules for the same reason.
|
# The apps' fixes come before the rules for the same reason.
|
||||||
%s
|
%s
|
||||||
|
|
||||||
# The fifth: only the rules for requests are loaded, and no response is
|
# Only the rules for requests are loaded, and no response is inspected.
|
||||||
# inspected.
|
|
||||||
Include @owasp_crs/REQUEST-*.conf
|
Include @owasp_crs/REQUEST-*.conf
|
||||||
|
|
||||||
# The third: redirect_uri is not checked for a URL naming an IP address or
|
# redirect_uri is not checked for a URL naming an IP address or
|
||||||
# localhost. Coraza matches a parameter name here without regard to case.
|
# localhost. Coraza matches a parameter name here without regard to case.
|
||||||
# ARGS holds the fields of a form data or multipart body Coraza reads as
|
# ARGS holds the fields of a form data or multipart body Coraza reads as
|
||||||
# well as the query parameters, so a field of this name is left out too.
|
# well as the query parameters, so a field of this name is left out too.
|
||||||
SecRuleUpdateTargetById 931100 "!ARGS:redirect_uri"
|
SecRuleUpdateTargetById 931100 "!ARGS:redirect_uri"
|
||||||
SecRuleUpdateTargetById 934110 "!ARGS:redirect_uri"
|
SecRuleUpdateTargetById 934110 "!ARGS:redirect_uri"
|
||||||
|
|
||||||
# The fourth: Referer is not checked for a Unix command without arguments
|
# Referer is not checked for a Unix command without arguments
|
||||||
# or for Java starting a process.
|
# or for Java starting a process.
|
||||||
SecRuleUpdateTargetById 932340 "!REQUEST_HEADERS:Referer"
|
SecRuleUpdateTargetById 932340 "!REQUEST_HEADERS:Referer"
|
||||||
SecRuleUpdateTargetById 944110 "!REQUEST_HEADERS:Referer"
|
SecRuleUpdateTargetById 944110 "!REQUEST_HEADERS:Referer"
|
||||||
@@ -122,9 +119,9 @@ SecRule REQUEST_HEADERS:Content-Type \
|
|||||||
"@rx ^(?:application|text)/(?:[a-z0-9.-]+[+])?json" \
|
"@rx ^(?:application|text)/(?:[a-z0-9.-]+[+])?json" \
|
||||||
"id:900420,phase:1,pass,nolog,t:none,t:lowercase,ctl:requestBodyProcessor=JSON"
|
"id:900420,phase:1,pass,nolog,t:none,t:lowercase,ctl:requestBodyProcessor=JSON"
|
||||||
|
|
||||||
# The rest of the second change: Content-Encoding is refused again on a
|
# Content-Encoding goes back on the list of the headers the Core Rule Set
|
||||||
# body of a kind the Core Rule Set reads, since a compressed body cannot be
|
# refuses (900250 in directives) for a body of a kind it reads, since a
|
||||||
# inspected.
|
# compressed body cannot be inspected.
|
||||||
SecRule REQBODY_PROCESSOR "@rx ^(?:URLENCODED|MULTIPART|JSON|XML)$" \
|
SecRule REQBODY_PROCESSOR "@rx ^(?:URLENCODED|MULTIPART|JSON|XML)$" \
|
||||||
"id:900260,phase:1,pass,nolog,\
|
"id:900260,phase:1,pass,nolog,\
|
||||||
setvar:'tx.restricted_headers_basic=%%{tx.restricted_headers_basic} \
|
setvar:'tx.restricted_headers_basic=%%{tx.restricted_headers_basic} \
|
||||||
@@ -145,15 +142,19 @@ SecRule MULTIPART_STRICT_ERROR "!@eq 0" "id:900450,phase:2,pass,\
|
|||||||
severity:'CRITICAL',setvar:'tx.inbound_anomaly_score_pl1=+5'"
|
severity:'CRITICAL',setvar:'tx.inbound_anomaly_score_pl1=+5'"
|
||||||
`
|
`
|
||||||
|
|
||||||
// app is an app whose ordinary requests the Core Rule Set would refuse,
|
// appFixes holds the fixes of each app whose ordinary requests the Core
|
||||||
// with the fixes that let them pass.
|
// Rule Set would refuse, in a file named for the app by the name
|
||||||
|
// SWW_WAF_APPS gives it, such as apps/gitea.conf. The fixes are Coraza
|
||||||
|
// exclusions, loaded before the Core Rule Set's rules. Their first rule
|
||||||
|
// skips to the marker they end with, unless Inspect sets the transaction
|
||||||
|
// variable named for the app, such as app_gitea. The skip reaches only
|
||||||
|
// phase 1, so a rule of a later phase must check that variable itself.
|
||||||
|
//
|
||||||
|
//go:embed apps/*.conf
|
||||||
|
var appFixes embed.FS
|
||||||
|
|
||||||
|
// app is what an app's file in appFixes cannot say about it.
|
||||||
type app struct {
|
type app struct {
|
||||||
// directives are Coraza exclusions, loaded before the Core Rule Set's
|
|
||||||
// rules. Their first rule skips to the marker they end with, unless
|
|
||||||
// Inspect sets the transaction variable named for the app, such as
|
|
||||||
// app_gitea. The skip reaches only phase 1, so a rule of a later phase
|
|
||||||
// must check that variable itself.
|
|
||||||
directives string
|
|
||||||
// cookies are the cookies the Core Rule Set reads a request without.
|
// cookies are the cookies the Core Rule Set reads a request without.
|
||||||
cookies []string
|
cookies []string
|
||||||
// forkOf names the app this one is a fork of, "" for none. A hostname
|
// forkOf names the app this one is a fork of, "" for none. A hostname
|
||||||
@@ -161,60 +162,34 @@ type app struct {
|
|||||||
forkOf string
|
forkOf string
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed gitea.conf
|
// apps are the apps that need more than their file in appFixes, by the
|
||||||
var giteaDirectives string
|
// name SWW_WAF_APPS gives each. flash is Forgejo's name for gitea_flash.
|
||||||
|
|
||||||
//go:embed wordpress.conf
|
|
||||||
var wordpressDirectives string
|
|
||||||
|
|
||||||
//go:embed drupal.conf
|
|
||||||
var drupalDirectives string
|
|
||||||
|
|
||||||
//go:embed mediawiki.conf
|
|
||||||
var mediawikiDirectives string
|
|
||||||
|
|
||||||
//go:embed mastodon.conf
|
|
||||||
var mastodonDirectives string
|
|
||||||
|
|
||||||
//go:embed vaultwarden.conf
|
|
||||||
var vaultwardenDirectives string
|
|
||||||
|
|
||||||
//go:embed nextcloud.conf
|
|
||||||
var nextcloudDirectives string
|
|
||||||
|
|
||||||
//go:embed forgejo.conf
|
|
||||||
var forgejoDirectives string
|
|
||||||
|
|
||||||
//go:embed ghost.conf
|
|
||||||
var ghostDirectives string
|
|
||||||
|
|
||||||
// apps are the apps whose fixes sww has, by the name SWW_WAF_APPS gives each.
|
|
||||||
// flash is Forgejo's name for gitea_flash.
|
|
||||||
//
|
//
|
||||||
//nolint:gochecknoglobals // a constant cannot be a map
|
//nolint:gochecknoglobals // a constant cannot be a map
|
||||||
var apps = map[string]app{
|
var apps = map[string]app{
|
||||||
"drupal": {directives: drupalDirectives},
|
|
||||||
"forgejo": {
|
"forgejo": {
|
||||||
directives: forgejoDirectives,
|
|
||||||
cookies: []string{"flash"},
|
cookies: []string{"flash"},
|
||||||
forkOf: "gitea",
|
forkOf: "gitea",
|
||||||
},
|
},
|
||||||
"ghost": {directives: ghostDirectives},
|
|
||||||
"gitea": {
|
"gitea": {
|
||||||
directives: giteaDirectives,
|
|
||||||
cookies: []string{"gitea_flash", "redirect_to"},
|
cookies: []string{"gitea_flash", "redirect_to"},
|
||||||
},
|
},
|
||||||
"mastodon": {directives: mastodonDirectives},
|
|
||||||
"mediawiki": {directives: mediawikiDirectives},
|
|
||||||
"nextcloud": {directives: nextcloudDirectives},
|
|
||||||
"vaultwarden": {directives: vaultwardenDirectives},
|
|
||||||
"wordpress": {directives: wordpressDirectives},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppNames returns the names of the apps whose fixes sww has, in
|
// AppNames returns the names of the apps whose fixes sww has, in
|
||||||
// alphabetical order.
|
// alphabetical order.
|
||||||
func AppNames() []string {
|
func AppNames() []string {
|
||||||
return slices.Sorted(maps.Keys(apps))
|
// An embedded directory always reads.
|
||||||
|
files, _ := appFixes.ReadDir("apps")
|
||||||
|
|
||||||
|
names := make([]string, len(files))
|
||||||
|
for i, file := range files {
|
||||||
|
names[i] = strings.TrimSuffix(file.Name(), ".conf")
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(names)
|
||||||
|
|
||||||
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params are what New needs.
|
// Params are what New needs.
|
||||||
@@ -373,8 +348,11 @@ func New(params Params) (*CoreRuleSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fixes strings.Builder
|
var fixes strings.Builder
|
||||||
|
|
||||||
for _, name := range AppNames() {
|
for _, name := range AppNames() {
|
||||||
fixes.WriteString(apps[name].directives + "\n")
|
// An embedded file always reads.
|
||||||
|
file, _ := appFixes.ReadFile("apps/" + name + ".conf")
|
||||||
|
fixes.WriteString(string(file) + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
text := fmt.Sprintf(directives, params.ParanoiaLevel, body, exclusions,
|
text := fmt.Sprintf(directives, params.ParanoiaLevel, body, exclusions,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// giteaSearches are searches of the pages gitea and Forgejo share whose q
|
// giteaSearches are searches of the pages gitea and Forgejo share whose q
|
||||||
// skips the lists of system files and command names, in the eighth change.
|
// skips the lists of system files and command names, in gitea's fixes.
|
||||||
// gitea serves its admin pages under /-/admin/ and Forgejo under /admin/.
|
// gitea serves its admin pages under /-/admin/ and Forgejo under /admin/.
|
||||||
//
|
//
|
||||||
//nolint:gochecknoglobals // a constant cannot be a list
|
//nolint:gochecknoglobals // a constant cannot be a list
|
||||||
@@ -222,8 +222,8 @@ func TestGiteaSearchExclusionsAreNarrow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Under /admin/, where Forgejo serves its admin pages, only the hard
|
// Under /admin/, where Forgejo serves its admin pages, only the hard
|
||||||
// values are left out: the tenth change lets them through in q on every
|
// values are left out: Drupal's fixes let them through in q on every path
|
||||||
// path there, for Drupal.
|
// there.
|
||||||
for _, target := range []string{
|
for _, target := range []string{
|
||||||
"/admin/packages/delete?q=",
|
"/admin/packages/delete?q=",
|
||||||
"/admin/packages?other=",
|
"/admin/packages?other=",
|
||||||
|
|||||||
@@ -660,9 +660,7 @@ func TestCoreRuleSetExclusionsFileThatCannotBeUsedStopsTheStartWhileTheCoreRuleS
|
|||||||
|
|
||||||
status := run(t.Context(), map[string]string{
|
status := run(t.Context(), map[string]string{
|
||||||
listenAddr: localhost + ":0", stateDir: t.TempDir(), ruleFilesDir: t.TempDir(),
|
listenAddr: localhost + ":0", stateDir: t.TempDir(), ruleFilesDir: t.TempDir(),
|
||||||
"SWW_WAF_CORE_RULE_SET_MODE": string(
|
"SWW_WAF_CORE_RULE_SET_MODE": config.CoreRuleSetModeOff,
|
||||||
config.CoreRuleSetModeOff,
|
|
||||||
),
|
|
||||||
"SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE": path,
|
"SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE": path,
|
||||||
}, out)
|
}, out)
|
||||||
if status != 1 {
|
if status != 1 {
|
||||||
|
|||||||
+4
-29
@@ -2,7 +2,6 @@ package sww
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
@@ -176,35 +175,11 @@ func newRuleFiles(
|
|||||||
return ruleFiles, nil
|
return ruleFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCoreRuleSet returns the Core Rule Set at SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL,
|
// newCoreRuleSet returns the Core Rule Set, as waf.NewCoreRuleSet does.
|
||||||
// without the rules SWW_WAF_CORE_RULE_SET_DISABLED_RULES switches off, reading bodies
|
|
||||||
// up to SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE, with the exclusions in
|
|
||||||
// SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE and the fixes of the apps in SWW_WAF_APPS,
|
|
||||||
// or nil while SWW_WAF_CORE_RULE_SET_MODE is off. An exclusions file that
|
|
||||||
// coreruleset.New refuses is an error in every mode. While the mode is off, a
|
|
||||||
// set file is loaded with the Core Rule Set only to check it.
|
|
||||||
func newCoreRuleSet(cfg *config.WAF) (*coreruleset.CoreRuleSet, error) {
|
func newCoreRuleSet(cfg *config.WAF) (*coreruleset.CoreRuleSet, error) {
|
||||||
if cfg.CoreRuleSetMode == config.CoreRuleSetModeOff &&
|
crs, err := waf.NewCoreRuleSet(cfg)
|
||||||
cfg.CoreRuleSetExclusionsFile == "" {
|
|
||||||
return nil, nil //nolint:nilnil // off is no Core Rule Set, and no error
|
|
||||||
}
|
|
||||||
|
|
||||||
crs, err := coreruleset.New(coreruleset.Params{
|
|
||||||
ParanoiaLevel: cfg.CoreRuleSetParanoiaLevel,
|
|
||||||
DisabledRules: cfg.CoreRuleSetDisabledRules,
|
|
||||||
BodyInspectionSize: cfg.CoreRuleSetBodyInspectionSize,
|
|
||||||
ExclusionsFile: cfg.CoreRuleSetExclusionsFile,
|
|
||||||
Apps: cfg.Apps,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, startError{
|
return nil, startError{"cannot use the Core Rule Set", err}
|
||||||
"cannot use the Core Rule Set",
|
|
||||||
fmt.Errorf("SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE: %w", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.CoreRuleSetMode == config.CoreRuleSetModeOff {
|
|
||||||
return nil, nil //nolint:nilnil // off is no Core Rule Set, and no error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return crs, nil
|
return crs, nil
|
||||||
@@ -217,7 +192,7 @@ func newLookupFile(
|
|||||||
lc fx.Lifecycle, cfg *config.WAF, processLog *slog.Logger,
|
lc fx.Lifecycle, cfg *config.WAF, processLog *slog.Logger,
|
||||||
alertQueue *alerts.Queue,
|
alertQueue *alerts.Queue,
|
||||||
) (*lookup.File, error) {
|
) (*lookup.File, error) {
|
||||||
if cfg.LookupSource != config.LookupSourceFile {
|
if cfg.LookupSource != "file" {
|
||||||
return nil, nil //nolint:nilnil // no lookup database, and no error
|
return nil, nil //nolint:nilnil // no lookup database, and no error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func (abuseIPDB) check(
|
|||||||
"scored by AbuseIPDB at or over SWW_WAF_ABUSEIPDB_MIN_SCORE",
|
"scored by AbuseIPDB at or over SWW_WAF_ABUSEIPDB_MIN_SCORE",
|
||||||
)
|
)
|
||||||
|
|
||||||
if rq.h.config.DNSBLAbuseIPDBAction != config.ReputationActionDeny {
|
if rq.h.config.DNSBLAbuseIPDBAction != deny {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,15 +86,14 @@ func (rq *request) countedBytes() int64 {
|
|||||||
response, request := rq.out.bytes, rq.requestBytes
|
response, request := rq.out.bytes, rq.requestBytes
|
||||||
|
|
||||||
switch rq.h.config.BytesCounted {
|
switch rq.h.config.BytesCounted {
|
||||||
case config.BytesCountedResponse:
|
case "response":
|
||||||
return response
|
return response
|
||||||
case config.BytesCountedRequest:
|
case "request":
|
||||||
return request
|
return request
|
||||||
case config.BytesCountedBoth:
|
default: // both
|
||||||
}
|
|
||||||
|
|
||||||
return response + request
|
return response + request
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// banForLimit bans the client's netblock at now for a broken limit, the
|
// banForLimit bans the client's netblock at now for a broken limit, the
|
||||||
// one hit names, notes the offence for the log line and counts the hit in
|
// one hit names, notes the offence for the log line and counts the hit in
|
||||||
|
|||||||
@@ -548,10 +548,6 @@ func (s *sender) requestWithHeader(
|
|||||||
// body is sent as it is after the headers, header holding its
|
// body is sent as it is after the headers, header holding its
|
||||||
// Content-Length or Transfer-Encoding. header may hold several lines,
|
// Content-Length or Transfer-Encoding. header may hold several lines,
|
||||||
// separated by "\r\n". It returns the whole answer.
|
// separated by "\r\n". It returns the whole answer.
|
||||||
//
|
|
||||||
// It waits for the answer as long as it takes, since a busy host can slow
|
|
||||||
// the Core Rule Set past any shorter wait. go test's -timeout ends a test
|
|
||||||
// whose answer never comes.
|
|
||||||
func (s *sender) requestWithBody(
|
func (s *sender) requestWithBody(
|
||||||
method, from, path, header, body string, status int, action string,
|
method, from, path, header, body string, status int, action string,
|
||||||
) (logLine, answer) {
|
) (logLine, answer) {
|
||||||
@@ -570,6 +566,11 @@ func (s *sender) requestWithBody(
|
|||||||
send(s.t, conn, method+" "+path+" HTTP/1.1\r\nHost: "+appHost+"\r\n"+
|
send(s.t, conn, method+" "+path+" HTTP/1.1\r\nHost: "+appHost+"\r\n"+
|
||||||
forwardedFor+": "+from+"\r\n"+header+"\r\n"+body)
|
forwardedFor+": "+from+"\r\n"+header+"\r\n"+body)
|
||||||
|
|
||||||
|
err := conn.SetReadDeadline(time.Now().Add(waitLimit))
|
||||||
|
if err != nil {
|
||||||
|
s.t.Fatalf("set read deadline: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var got answer
|
var got answer
|
||||||
|
|
||||||
res, err := http.ReadResponse(bufio.NewReader(conn), nil)
|
res, err := http.ReadResponse(bufio.NewReader(conn), nil)
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blocklisted := percentage{percent: whole}
|
blocklisted := percentage{percent: whole}
|
||||||
if rq.blocklisted &&
|
if rq.blocklisted && cfg.BlocklistAction == "limit" {
|
||||||
cfg.BlocklistAction == config.ReputationActionLimit {
|
|
||||||
blocklisted = percentage{
|
blocklisted = percentage{
|
||||||
cfg.BlocklistLimitPercent,
|
cfg.BlocklistLimitPercent,
|
||||||
"SWW_WAF_BLOCKLIST_ACTION",
|
"SWW_WAF_BLOCKLIST_ACTION",
|
||||||
@@ -73,7 +72,7 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
|||||||
|
|
||||||
dnsblAbuseIPDBListed := percentage{percent: whole}
|
dnsblAbuseIPDBListed := percentage{percent: whole}
|
||||||
if (rq.dnsblListed || rq.abuseIPDBHit) &&
|
if (rq.dnsblListed || rq.abuseIPDBHit) &&
|
||||||
cfg.DNSBLAbuseIPDBAction == config.ReputationActionLimit {
|
cfg.DNSBLAbuseIPDBAction == "limit" {
|
||||||
dnsblAbuseIPDBListed = percentage{
|
dnsblAbuseIPDBListed = percentage{
|
||||||
cfg.DNSBLAbuseIPDBLimitPercent,
|
cfg.DNSBLAbuseIPDBLimitPercent,
|
||||||
"SWW_WAF_DNSBL_ABUSEIPDB_ACTION",
|
"SWW_WAF_DNSBL_ABUSEIPDB_ACTION",
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
|
||||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,6 +41,5 @@ func (blocklists) check(
|
|||||||
// client, given listedBy, the blocklists that list it: it does when one lists
|
// client, given listedBy, the blocklists that list it: it does when one lists
|
||||||
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
||||||
func (rq *request) refusedByBlocklists(listedBy []string) bool {
|
func (rq *request) refusedByBlocklists(listedBy []string) bool {
|
||||||
return len(listedBy) > 0 && rq.h.config.BlocklistAction ==
|
return len(listedBy) > 0 && rq.h.config.BlocklistAction == deny
|
||||||
config.ReputationActionDeny
|
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ func (coreRuleSet) check(
|
|||||||
rq.line.CoreRuleSetScore = &result.Score
|
rq.line.CoreRuleSetScore = &result.Score
|
||||||
|
|
||||||
for _, id := range result.RuleIDs {
|
for _, id := range result.RuleIDs {
|
||||||
rq.h.metrics.CoreRuleSetMatched(string(cfg.CoreRuleSetMode), id)
|
rq.h.metrics.CoreRuleSetMatched(cfg.CoreRuleSetMode, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
threshold := cfg.CoreRuleSetScoreThreshold
|
threshold := cfg.CoreRuleSetScoreThreshold
|
||||||
@@ -99,7 +99,7 @@ func (rq *request) alertCoreRuleSetMatch(result coreruleset.Result) {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case rq.h.config.CoreRuleSetMode == config.CoreRuleSetModeDetect:
|
case rq.h.config.CoreRuleSetMode == config.CoreRuleSetModeDetect:
|
||||||
detail["mode"] = string(config.CoreRuleSetModeDetect)
|
detail["mode"] = config.CoreRuleSetModeDetect
|
||||||
case rq.h.config.Observe:
|
case rq.h.config.Observe:
|
||||||
detail["mode"] = "observe"
|
detail["mode"] = "observe"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ func (dnsbl) check(ctx context.Context, rq *request, _ time.Time) *verdict {
|
|||||||
rq.addTag(config.DNSBLTagPrefix + strings.ToLower(zone))
|
rq.addTag(config.DNSBLTagPrefix + strings.ToLower(zone))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rq.dnsblListed ||
|
if !rq.dnsblListed || rq.h.config.DNSBLAbuseIPDBAction != deny {
|
||||||
rq.h.config.DNSBLAbuseIPDBAction != config.ReputationActionDeny {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ func (rq *request) startLookUp(
|
|||||||
) <-chan lookupResult {
|
) <-chan lookupResult {
|
||||||
result := make(chan lookupResult, 1)
|
result := make(chan lookupResult, 1)
|
||||||
|
|
||||||
if rq.h.config.LookupSource == config.LookupSourceOff ||
|
if rq.h.config.LookupSource == "off" || !canBePlaced(rq.client) {
|
||||||
!canBePlaced(rq.client) {
|
|
||||||
result <- lookupResult{}
|
result <- lookupResult{}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -58,7 +57,7 @@ func (rq *request) startLookUp(
|
|||||||
|
|
||||||
client := clientGroup(rq.h.config, rq.client)
|
client := clientGroup(rq.h.config, rq.client)
|
||||||
|
|
||||||
if rq.h.config.LookupSource == config.LookupSourceFile {
|
if rq.h.config.LookupSource == "file" {
|
||||||
result <- lookupResult{
|
result <- lookupResult{
|
||||||
lookedUp: true, answer: rq.h.lookupFile.LookUp(client),
|
lookedUp: true, answer: rq.h.lookupFile.LookUp(client),
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-2
@@ -6,6 +6,7 @@ package waf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -82,8 +83,8 @@ type Params struct {
|
|||||||
// LookupFile is the lookup database they are looked up in while
|
// LookupFile is the lookup database they are looked up in while
|
||||||
// SWW_WAF_LOOKUP_SOURCE is file, and nil otherwise.
|
// SWW_WAF_LOOKUP_SOURCE is file, and nil otherwise.
|
||||||
LookupFile *lookup.File
|
LookupFile *lookup.File
|
||||||
// CoreRuleSet is what inspects requests while
|
// CoreRuleSet is what NewCoreRuleSet returns: what inspects requests
|
||||||
// SWW_WAF_CORE_RULE_SET_MODE is not off, and nil while it is.
|
// while SWW_WAF_CORE_RULE_SET_MODE is not off, and nil while it is.
|
||||||
CoreRuleSet CoreRuleSetInspector
|
CoreRuleSet CoreRuleSetInspector
|
||||||
// Now tells the time by which requests are counted for the rate
|
// Now tells the time by which requests are counted for the rate
|
||||||
// limits, bans are made and run out, and GeoJS's answers are kept,
|
// limits, bans are made and run out, and GeoJS's answers are kept,
|
||||||
@@ -173,6 +174,40 @@ func newHandler(params Params) *handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCoreRuleSet returns the Core Rule Set at SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL,
|
||||||
|
// without the rules SWW_WAF_CORE_RULE_SET_DISABLED_RULES switches off, reading bodies
|
||||||
|
// up to SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE, with the exclusions in
|
||||||
|
// SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE and the fixes of the apps in SWW_WAF_APPS,
|
||||||
|
// or nil while SWW_WAF_CORE_RULE_SET_MODE is off. An exclusions file that
|
||||||
|
// coreruleset.New refuses is an error in every mode. While the mode is off, a
|
||||||
|
// set file is loaded with the Core Rule Set only to check it.
|
||||||
|
func NewCoreRuleSet(cfg *config.WAF) (*coreruleset.CoreRuleSet, error) {
|
||||||
|
if cfg.CoreRuleSetMode == config.CoreRuleSetModeOff &&
|
||||||
|
cfg.CoreRuleSetExclusionsFile == "" {
|
||||||
|
return nil, nil //nolint:nilnil // off is no Core Rule Set, and no error
|
||||||
|
}
|
||||||
|
|
||||||
|
coreRuleSet, err := coreruleset.New(coreruleset.Params{
|
||||||
|
ParanoiaLevel: cfg.CoreRuleSetParanoiaLevel,
|
||||||
|
DisabledRules: cfg.CoreRuleSetDisabledRules,
|
||||||
|
BodyInspectionSize: cfg.CoreRuleSetBodyInspectionSize,
|
||||||
|
ExclusionsFile: cfg.CoreRuleSetExclusionsFile,
|
||||||
|
Apps: cfg.Apps,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE: %w",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.CoreRuleSetMode == config.CoreRuleSetModeOff {
|
||||||
|
return nil, nil //nolint:nilnil // off is no Core Rule Set, and no error
|
||||||
|
}
|
||||||
|
|
||||||
|
return coreRuleSet, nil
|
||||||
|
}
|
||||||
|
|
||||||
// handler is waf's handler. It holds what every request shares; what
|
// handler is waf's handler. It holds what every request shares; what
|
||||||
// belongs to one request is in a request.
|
// belongs to one request is in a request.
|
||||||
type handler struct {
|
type handler struct {
|
||||||
|
|||||||
+12
-29
@@ -20,7 +20,6 @@ import (
|
|||||||
"sneak.berlin/go/smallwebwaf/internal/bans"
|
"sneak.berlin/go/smallwebwaf/internal/bans"
|
||||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||||
"sneak.berlin/go/smallwebwaf/internal/config/configtest"
|
"sneak.berlin/go/smallwebwaf/internal/config/configtest"
|
||||||
"sneak.berlin/go/smallwebwaf/internal/coreruleset"
|
|
||||||
"sneak.berlin/go/smallwebwaf/internal/geojs"
|
"sneak.berlin/go/smallwebwaf/internal/geojs"
|
||||||
"sneak.berlin/go/smallwebwaf/internal/lookup"
|
"sneak.berlin/go/smallwebwaf/internal/lookup"
|
||||||
"sneak.berlin/go/smallwebwaf/internal/metrics"
|
"sneak.berlin/go/smallwebwaf/internal/metrics"
|
||||||
@@ -193,11 +192,11 @@ func (o *output) requestLine(t *testing.T) logLine {
|
|||||||
// endedLines waits for count requests that went through rproxy, or to waf's
|
// endedLines waits for count requests that went through rproxy, or to waf's
|
||||||
// own endpoints, to have ended, and returns the last log line of each, in the
|
// own endpoints, to have ended, and returns the last log line of each, in the
|
||||||
// order waf took them. A question's last line is the one its report writes.
|
// order waf took them. A question's last line is the one its report writes.
|
||||||
// It waits as long as it takes, as requestWithBody does.
|
|
||||||
func (o *output) endedLines(t *testing.T, count int) []logLine {
|
func (o *output) endedLines(t *testing.T, count int) []logLine {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
for {
|
deadline := time.Now().Add(waitLimit)
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
found := o.lastLines(t)
|
found := o.lastLines(t)
|
||||||
|
|
||||||
ended := len(found) >= count
|
ended := len(found) >= count
|
||||||
@@ -213,6 +212,10 @@ func (o *output) endedLines(t *testing.T, count int) []logLine {
|
|||||||
|
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(pollInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Fatalf("fewer than %d requests have ended after %s", count, waitLimit)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// lastLines returns the last request log line written so far of each request,
|
// lastLines returns the last request log line written so far of each request,
|
||||||
@@ -501,11 +504,17 @@ func newWAFWith(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coreRuleSet, err := waf.NewCoreRuleSet(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Core Rule Set: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
params := waf.Params{
|
params := waf.Params{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
RequestLog: out,
|
RequestLog: out,
|
||||||
ProcessLog: processLog,
|
ProcessLog: processLog,
|
||||||
LookupFile: lookupFile,
|
LookupFile: lookupFile,
|
||||||
|
CoreRuleSet: coreRuleSet,
|
||||||
Now: now,
|
Now: now,
|
||||||
Rules: ruleFiles,
|
Rules: ruleFiles,
|
||||||
Alerts: alertQueue,
|
Alerts: alertQueue,
|
||||||
@@ -513,8 +522,6 @@ func newWAFWith(
|
|||||||
// with a stand-in.
|
// with a stand-in.
|
||||||
BesideLookupTimeLimit: time.Hour,
|
BesideLookupTimeLimit: time.Hour,
|
||||||
}
|
}
|
||||||
|
|
||||||
addCoreRuleSet(t, ¶ms)
|
|
||||||
addCounters(¶ms)
|
addCounters(¶ms)
|
||||||
addOutsideSources(¶ms, geojsURL, abuseIPDBCheckURL)
|
addOutsideSources(¶ms, geojsURL, abuseIPDBCheckURL)
|
||||||
|
|
||||||
@@ -523,30 +530,6 @@ func newWAFWith(
|
|||||||
return server, out, alertQueue
|
return server, out, alertQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
// addCoreRuleSet adds to params the Core Rule Set, with the settings for it,
|
|
||||||
// while SWW_WAF_CORE_RULE_SET_MODE is not off.
|
|
||||||
func addCoreRuleSet(t *testing.T, params *waf.Params) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
cfg := params.Config
|
|
||||||
if cfg.CoreRuleSetMode == config.CoreRuleSetModeOff {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
coreRuleSet, err := coreruleset.New(coreruleset.Params{
|
|
||||||
ParanoiaLevel: cfg.CoreRuleSetParanoiaLevel,
|
|
||||||
DisabledRules: cfg.CoreRuleSetDisabledRules,
|
|
||||||
BodyInspectionSize: cfg.CoreRuleSetBodyInspectionSize,
|
|
||||||
ExclusionsFile: cfg.CoreRuleSetExclusionsFile,
|
|
||||||
Apps: cfg.Apps,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Core Rule Set: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
params.CoreRuleSet = coreRuleSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// addCounters adds to params the metrics, the table of clients, the ledger
|
// addCounters adds to params the metrics, the table of clients, the ledger
|
||||||
// and the anomaly counters, as sww builds them from params' settings. The
|
// and the anomaly counters, as sww builds them from params' settings. The
|
||||||
// metrics read the ledger, the table of clients and the rules.
|
// metrics read the ledger, the table of clients and the rules.
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import (
|
|||||||
"sneak.berlin/go/smallwebwaf/internal/bans"
|
"sneak.berlin/go/smallwebwaf/internal/bans"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// deny is the SWW_WAF_BLOCKLIST_ACTION and the SWW_WAF_DNSBL_ABUSEIPDB_ACTION that
|
||||||
|
// refuses the requests of a client a source lists.
|
||||||
|
const deny = "deny"
|
||||||
|
|
||||||
// noteListed notes each of sources, the URLs of the blocklists or the
|
// noteListed notes each of sources, the URLs of the blocklists or the
|
||||||
// DNSBL zones, their keys masked, that list the client, as noteHit does,
|
// DNSBL zones, their keys masked, that list the client, as noteHit does,
|
||||||
// with reason.
|
// with reason.
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ func (rq *request) answerAtTheEnd() (geojs.Answer, bool) {
|
|||||||
return geojs.Answer{}, false
|
return geojs.Answer{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if rq.h.config.LookupSource == config.LookupSourceFile {
|
if rq.h.config.LookupSource == "file" {
|
||||||
return rq.lookupAnswer, true
|
return rq.lookupAnswer, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user