Repository navigation
[2.x] feat(audit): search the log by partial IP address or subnet - #5431
Merged
Merged
Conversation
The `ip:` filter matched only exact strings, so IPv6 subnets could not be searched: the same address is stored in several representations, and where `::` falls depends on the zeros, not on the subnet boundary. Each entry now also stores its address as 32 hex digits of the 16-byte form (IPv4 as IPv4-mapped IPv6) in an indexed `ip_hex` column, and `ip:` accepts full addresses, CIDR ranges, partial addresses and trailing wildcards, matched with an indexed range query on every database driver. Existing entries are indexed by `php flarum audit:backfill-ip`, kept out of the migration so upgrading a large log does not stall. Until then they are still found by an exact `ip:` search. Fixes #4939
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4939
Changes proposed in this pull request:
The audit
ip:filter now matches partial addresses, CIDR ranges and trailing wildcards as well as full addresses, for IPv4 and IPv6 (ip:192.168,ip:10.0.0.0/8,ip:2a02:390:9e5c:beeffor its /64). Each entry also stores its address as 32 hex digits of the 16-byte form (IPv4 as IPv4-mapped IPv6) in a new indexedip_hexcolumn, so every way of writing an IPv6 address matches and a range is an indexedBETWEENon every driver. Existing entries are indexed by the newphp flarum audit:backfill-ipcommand rather than the migration, so upgrading a large log doesn't stall; until it runs they are still found by exact searches. The search help text shows the new forms.Reviewers should focus on:
char(32)column instead of a binary column, which avoids binding raw bytes for PostgreSQLbyteaand SQLite blobs.-ip:now keeps entries that have no IP address (e.g. console actions); before, SQLNOT INdropped them as a side effect of NULL.down()leaves the column in place, because uninstalling logsextension.uninstalledafter rolling migrations back.Screenshot
Necessity
Confirmed
yarn testinjs/).composer test).Tests pass on SQLite and MariaDB 11.8 (
utf8mb4_unicode_ci); PostgreSQL is covered by CI only.Required changes: