[#225] Support wildcard in allowed origins and headers #225

Merged
alexvanin merged 1 commit from mbiryukova/frostfs-http-gw:feature/cors_matching into master 2025-04-09 13:54:19 +00:00
Member

Signed-off-by: Marina Biryukova m.biryukova@yadro.com

Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
mbiryukova self-assigned this 2025-04-07 13:56:50 +00:00
mbiryukova added 1 commit 2025-04-07 13:56:51 +00:00
[#xxx] Support wildcard in allowed origins and headers
Some checks failed
/ DCO (pull_request) Failing after 31s
/ Builds (pull_request) Successful in 1m7s
/ Vulncheck (pull_request) Successful in 1m44s
/ OCI image (pull_request) Successful in 1m56s
/ Lint (pull_request) Successful in 3m29s
/ Tests (pull_request) Successful in 1m21s
/ Integration tests (pull_request) Successful in 6m4s
ec88edd137
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
mbiryukova force-pushed feature/cors_matching from ec88edd137 to 273459e090 2025-04-07 13:57:21 +00:00 Compare
mbiryukova changed title from WIP: [#xxx] Support wildcard in allowed origins and headers to [#225] Support wildcard in allowed origins and headers 2025-04-07 14:04:28 +00:00
requested reviews from storage-services-developers, storage-services-committers 2025-04-07 14:04:28 +00:00
nzinkevich reviewed 2025-04-08 06:33:30 +00:00
@ -79,3 +81,3 @@
for _, rule := range corsConfig.CORSRules {
for _, o := range rule.AllowedOrigins {
if o == string(origin) || o == wildcard {
if o == string(origin) || o == wildcard || (strings.Contains(o, "*") && match(o, string(origin))) {
Member

I think we should check the count of the wildcards in AllowedOrigins beforehand. For the cases when stored cors configuration is invalid. Then we should throw InternalError for instance. Even though we validate config during PutCors.

I think we should check the count of the wildcards in AllowedOrigins beforehand. For the cases when stored cors configuration is invalid. Then we should throw InternalError for instance. Even though we validate config during `PutCors`.
Owner

This seems reasonable, let's do this with low priority. Seems like the only way to create such object for now is to write to cors container directly with invalid data.

This seems reasonable, let's do this with low priority. Seems like the only way to create such object for now is to write to cors container directly with invalid data.
@ -343,0 +348,4 @@
func match(tmpl, str string) bool {
regexpStr := "^" + regexp.QuoteMeta(tmpl) + "$"
regexpStr = regexpStr[:strings.Index(regexpStr, "*")-1] + "." + regexpStr[strings.Index(regexpStr, "*"):]
reg := regexp.MustCompile(regexpStr)
Member

Shall we panic or return error when AllowedOrigins may be intepreted as incorrect pattern (e.g a pattern like *example\)

Shall we panic or return error when AllowedOrigins may be intepreted as incorrect pattern (e.g a pattern like `*example\`)
Member

I suppose we must not panic. Let's fix it. Probably in s3-gw we should do the same

I suppose we must not panic. Let's fix it. Probably in s3-gw we should do the same
Author
Member

Why shall be a panic here with *example\ origin?

Why shall be a panic here with `*example\` origin?
Member

trailing backslash in the end. Also it may be invalid control character (\c, for example) or ?,+ at the beginning

trailing backslash in the end. Also it may be invalid control character (`\c`, for example) or `?`,`+` at the beginning
Author
Member

regexp.QuoteMeta escapes all characters for exact string match, except wildcard (escaping is replaced by dot in the line below)

`regexp.QuoteMeta` escapes all characters for exact string match, except wildcard (escaping is replaced by dot in the line below)
dkirillov approved these changes 2025-04-09 06:22:32 +00:00
alexvanin approved these changes 2025-04-09 13:54:08 +00:00
alexvanin added this to the v0.33.0 milestone 2025-04-09 13:54:13 +00:00
alexvanin merged commit 273459e090 into master 2025-04-09 13:54:19 +00:00
alexvanin deleted branch feature/cors_matching 2025-04-09 13:54:20 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-http-gw#225
No description provided.