-
Notifications
You must be signed in to change notification settings - Fork 705
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
[FIXED] Validation in jetstream and KV #1613
Conversation
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
kv.go
Outdated
validKeyRe = regexp.MustCompile(`\A[-/_=\.a-zA-Z0-9]+\z`) | ||
validBucketRe = regexp.MustCompile(`\A[a-zA-Z0-9_-]+\z`) | ||
validKeyRe = regexp.MustCompile(`\A[-/_=\.a-zA-Z0-9]+\z`) | ||
validSearchKeyRe = regexp.MustCompile(`^[^ >]*[>]?$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would allow matching keys that arent valid keys like x!y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll just base it on validKeyRe
+ allow wildcards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to ^[-/_=\.a-zA-Z0-9*]*[>]?$
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
if dur == "" { | ||
return fmt.Errorf("%w: '%s'", ErrInvalidConsumerName, "name is required") | ||
} | ||
if strings.ContainsAny(dur, ">*. /\\") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now is aligned with CLI and .js clients, but I'm afraid implementing this change could break some users.
Any thoughts @ripienaar ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, perhaps the only one the server wouldnt catch really is the space right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually no - space would break the protocol there so that wouldnt have worked, I think its fine but we do need to call it out carefully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we definately need to add space and wildcards, but /
and \
are not that obvious IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/
and \
are already rejected by the server with API error: code=400 err_code=10128 description=Stream name can not contain path separators
(same for consumer names), so the only change here would be client-side validation instead of server-side. But I don't think we absolutely need it since this at least does not break protocol when put in subject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq, when creating a consumer do we check for whether trying to create an filter subject like foo.>.
or foo.>.*
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't. I assume safe validations (100% non-breaking) would be checking for >
and .
placements right? Plus spaces in subject. Anything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes ending with .
need to be client side since it becomes a malformed subject so the server cannot match the JS API, foo.>.*
looks like the server does handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added validating filter subject
@@ -344,8 +344,9 @@ const ( | |||
|
|||
// Regex for valid keys and buckets. | |||
var ( | |||
validBucketRe = regexp.MustCompile(`\A[a-zA-Z0-9_-]+\z`) | |||
validKeyRe = regexp.MustCompile(`\A[-/_=\.a-zA-Z0-9]+\z`) | |||
validBucketRe = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would test thse regex expressions (or better - a functin that valide those items).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
ccf606d
to
ff5437f
Compare
@ripienaar you're fine with the current state of this PR after recent changes? |
@Jarema i think so yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski piotr@synadia.com