Skip to content

[persistent collections] based on PR-866#1261

Draft
tty2 wants to merge 31 commits intocorazawaf:mainfrom
tty2:pr-866
Draft

[persistent collections] based on PR-866#1261
tty2 wants to merge 31 commits intocorazawaf:mainfrom
tty2:pr-866

Conversation

@tty2
Copy link
Copy Markdown
Contributor

@tty2 tty2 commented Dec 25, 2024

This PR is based on the PR-866 of the original repository.
It is related to the issue-1227.
Persistence collections

Thanks for your contribution ❤️

return fmt.Errorf("initcol: collection %s is not valid", col)
}
// we validate if this is a persistent collection
persistent := []string{"USER", "SESSION", "IP", "RESOURCE", "GLOBAL"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to restrict arbitrary collection creation?

// key is also required
if strings.ToUpper(colKey) != "TX" {
return errors.New("invalid arguments, expected collection TX")
available := []string{"TX", "USER", "GLOBAL", "RESOURCE", "SESSION", "IP"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jptosso Clould you help me here? It's your changes, I believe you have more context here.

I personally see the reason of making constraints, just to minimize unpredictable behavior.
And in the future, if we really need we can extend it without breaking compatibility.
On the other hand if we make it possible to pass anything now and bring constrains after, there is a chance to break code for someone.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! setvar can only be used for this set of variables. Others are not mutuable, but IMOwe can use type assertion for this

)

// defaultEngine
// defaultEngine is just a sample and it shouldn't be used in production.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use the third-party library then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use own custom engine if we need.
Take a look here.

switch v := res.(type) {
case string:
return v, nil
case int:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even store it as int if we only set a value of type string?

@@ -0,0 +1,50 @@
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors

Maybe even 2025.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. These changes made in 2023 by Juan.
I'd keep it as it is.

@jptosso
Copy link
Copy Markdown
Member

jptosso commented Dec 30, 2024

Great job here. There is a PR for the close implementation #1200

@tty2
Copy link
Copy Markdown
Contributor Author

tty2 commented Dec 30, 2024

Great job here. There is a PR for the close implementation #1200

Thanks @jptosso
I'll come back to it after finishing with tests.

@tty2
Copy link
Copy Markdown
Contributor Author

tty2 commented Jan 7, 2025

JFYI: the PR is ready from my side. There are unit-tests and I checked it on my local machine with some rules.
I'm not opening it just because we'd like to make some manual tests with current implementation using many existing sec rules we already have for system. As soon as we make sure it works fine, I'll open if for review.
Hopefully we'll do it during the next couple of weeks.

@ghost
Copy link
Copy Markdown

ghost commented Jun 12, 2025

hello, any update on this? I would love to see this implemented! I am planning on transferring from modsecurity to coraza and i have a rule that uses persistent collection...

@fzipi
Copy link
Copy Markdown
Member

fzipi commented Mar 28, 2026

@tty2 Sorry to catch up again on this, but can you fix the conflicts and let's try to push this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants