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

Feat: Match allowed cookies with optional character #71047

Merged
merged 2 commits into from Jul 5, 2023

Conversation

itsmylife
Copy link
Contributor

What is this feature?

This adds a new option for "Allowed Cookies". Allowed cookies can be determined via their name or an optional part.
This optional part will be matched with []. If the allowed cookie name ends with [] we match all cookies that start with the given string.

Example:
Allowed Cookie: cookie[]
Matched Cookies: cookie1, cookie2, cookie__special, cookieeeeee
NOT Matched Cookies: supercookie1, super_cookie2, special_cookie__special

More details are here: https://github.com/grafana/observability-metrics-squad/issues/124

This PR is an up-to-date version of this PR. The old one had some weird change list so I created a new PR to prevent confusion.

Why do we need this feature?

To have an easier matcher for allowed cookies.

Which issue(s) does this PR fix?:

Fixes https://github.com/grafana/observability-metrics-squad/issues/124
Fixes https://github.com/grafana/observability-metrics-squad/issues/102

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@itsmylife itsmylife requested review from a team as code owners July 4, 2023 14:23
@itsmylife itsmylife requested review from zserge, suntala and yangkb09 and removed request for a team July 4, 2023 14:23
@itsmylife itsmylife added this to the 10.1.x milestone Jul 4, 2023
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor comment regarding readability but it can be ignored

@itsmylife
Copy link
Contributor Author

LGTM, just one minor comment regarding readability but it can be ignored

Let me know about that and I will update it quickly ;)

@andresmgot
Copy link
Contributor

LGTM, just one minor comment regarding readability but it can be ignored

Let me know about that and I will update it quickly ;)

that's weird, the message got lost, let me re-send it 🤔

Comment on lines 49 to 65
// match all
if v == "[]" {
keepCookies[c.Name] = c
continue
}

l := len(v) - 2
if v[l:] == "[]" {
if len(c.Name) >= l && c.Name[:l] == v[:l] {
keepCookies[c.Name] = c
}
} else {
// look for exact match
if c.Name == v {
keepCookies[c.Name] = c
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggested to use the strings package to be a bit more readable:

			if strings.HasSuffix(v, "[]") {
				// match prefix
				pattern := strings.TrimSuffix(v, "[]")
				if strings.HasPrefix(c.Name, pattern) {
					keepCookies[c.Name] = c
				}
			} else {
				// exact match
				if c.Name == v {
					keepCookies[c.Name] = c
				}

Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

LGTM!

@itsmylife itsmylife merged commit 81ba27c into main Jul 5, 2023
12 checks passed
@itsmylife itsmylife deleted the ismail/allowed-cookies-pattern-options-2 branch July 5, 2023 14:12
polibb pushed a commit that referenced this pull request Jul 14, 2023
* Match allowed cookies with optional character

* Use strings package
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants