fix(collections): Honour SecDataDir for LMDB, fix literal setvar writ…#3597
Open
20vikash wants to merge 1 commit into
Open
fix(collections): Honour SecDataDir for LMDB, fix literal setvar writ…#359720vikash wants to merge 1 commit into
20vikash wants to merge 1 commit into
Conversation
…es and case-insensitive collection keys
|
Member
|
Hi @20vikash, thanks for this PR. To be honest, I've been working on this solution for a while (well, I'm almost done), but I want to add that to 4.0, not to 3.0. I hope I can finish that work soon and can send my PR - I'll let you know when I'm done. |
Author
|
@airween Hey. Thanks for the reply. Hope to see the full fix in V4. I encountered this silent failure while implementing a basic rate limiter. So, decided to make a quick fix in V3. |
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.



what
SecDataDir is now honoured by the LMDB backend. The path is stored in
RulesSetProperties and used by the MDBEnvProvider singleton to open the LMDB
environment (data.mdb/lock.mdb) inside that directory. Falls back to the
legacy "./modsec-shared-collections" file when SecDataDir is unset.
SecDataDir misconfiguration is now loud. The parser validates the path
(exists, is a directory, writable) and fails configuration load on error,
surfacing the message through getParserError to the connector error log.
LMDB open failures are now logged to stderr instead of being silently
swallowed.
Literal setvar targets now persist. set_var.cc only dispatched writes to
the dynamic variable subclasses. Variables parsed as literal dict elements
fell through an empty else branch and were never stored. This adds name
based dispatch for the literal case.
Collection variable names are now case-insensitive. The composite key
compared variable names case-sensitively, so setvar:ip.counter and
IP:COUNTER resolved to different entries. All Collection wrapper methods now
lowercase the variable name term.
Bison and flex outputs regenerated from the edited grammar.
why
SecDataDir is a documented directive shipped in modsecurity.conf-recommended.
Users expect it to control where persistent collection data lives. In v3
with LMDB it was a no-op: the value was discarded and the file always
appeared in the worker current working directory, with no error in the log.
The silent setvar no-op was a data loss bug. Any rule writing a literal
collection variable lost the value with no error. The 2018 RunTimeString
refactor replaced the original generic dispatcher with per type dynamic
casts that omitted the literal case by oversight, not by design.
Case insensitive variable names are a SecLang property: the scanner matches
collection prefixes case insensitively. The case sensitive key broke the
natural pattern of a lowercase write and uppercase read, silently producing
empty match values. Fixing it at the Collection wrapper boundary covers both
LMDB and in memory backends.
references
commit f17af95 "Using RunTimeString on setvar action".
uppercase read asserted the value), collection-regular_expression_selection
.json (uppercase setvar only asserted the debug log line, masking the no-op).
related issue
#3394
changed files
Hand edited:
Regenerated: