Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[persistent collections] based on PR-866 #1261

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft

Conversation

tty2
Copy link
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
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?

@@ -76,8 +78,10 @@ func (a *setvarFn) Init(_ plugintypes.RuleMetadata, data string) error {
colKey, colVal, colOk := strings.Cut(key, ".")
// Right not it only makes sense to allow setting TX
// 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
Contributor

Choose a reason for hiding this comment

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

And here?

)

// defaultEngine
// defaultEngine is just a sample and it shouldn't be used in production.
Copy link
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?

switch v := res.(type) {
case string:
return v, nil
case int:
Copy link
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?

@@ -116,4 +116,10 @@ type TransactionVariables interface {
ArgsGetNames() collection.Collection
ArgsPostNames() collection.Collection
MultipartStrictError() collection.Single
// TODO(v4: Add these)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we should add them in this PR.

@@ -0,0 +1,50 @@
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors
Copy link
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.

Sessionid
// Userid is not supported
// Userid is a persistent collection of user ids
Copy link
Contributor

Choose a reason for hiding this comment

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

It's simply wrong. Could you add comments based on the official documentation?
image

@jptosso
Copy link
Member

jptosso commented Dec 30, 2024

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

@tty2
Copy link
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.

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.

3 participants