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

[MCG] Using put-bucket-policy with wrong syntax under Resource results in InternalError instead of MalformedPolicy #8783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vh05
Copy link
Contributor

@vh05 vh05 commented Feb 12, 2025

The malformed syntax should give malformed systax error.

Issue: Square brackets ([ ]) in resource_bucket_part were misinterpreted in regex.

Fix: Escape all regex special characters before inserting into RegExp().

Fixes: https://issues.redhat.com/browse/DFBUGS-1517

@vh05 vh05 force-pushed the DFBUGS-1517 branch 4 times, most recently from f84f57a to 2280c6f Compare February 12, 2025 11:03
@vh05 vh05 requested a review from romayalon February 12, 2025 12:10
Copy link
Contributor

@romayalon romayalon left a comment

Choose a reason for hiding this comment

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

Hey @vh05

  1. Please add unit tests
  2. Initializing regex in a function is unrecommended due to performance issues and it should be pre-compiled as a global variable, read more about it here - Pre-compiled regexp optimization #7110
  3. To me It looks like this issue can happen in every bucket policy field, can you please check if we need this fix in more places?
  4. @nadavMiz since you are the last one to change this area, I would appreciate your review as well.

const resource_regex = RegExp(`^${resource_bucket_part.replace(qm_regex, '.?').replace(ar_regex, '.*')}$`);
const resource_regex = RegExp(
`^${resource_bucket_part
.replace(/[-/^$+?.()|[\]{}]/g, '\\$&')
Copy link
Contributor

Choose a reason for hiding this comment

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

notice that we are modifying the ? character right after your change. did you check it doesn't effect this? worth adding a test as well if one doesn't already exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nadavMiz I think the question mark (?) will be replaced with \? in the 1st part then ? will be replace by \.? . Have limited or no knowledge on this. Checking this

@vh05
Copy link
Contributor Author

vh05 commented Feb 18, 2025

Hey @vh05

1. Please add unit tests

2. Initializing regex in a function is unrecommended due to performance issues and it should be pre-compiled as a global variable, read more about it here - [Pre-compiled regexp optimization #7110](https://github.com/noobaa/noobaa-core/pull/7110)

3. To me It looks like this issue can happen in every bucket policy field, can you please check if we need this fix in more places?

4. @nadavMiz since you are the last one to change this area, I would appreciate your review as well.
  1. Sure, will add unit tests
  2. Storing the regex and global const
  3. sure, will check this

…s in InternalError instead of MalformedPolicy

The malformed syntax should give malformed systax error.

Issue: Square brackets ([ ]) in resource_bucket_part were misinterpreted in regex.

Fix: Escape all regex special characters before inserting into RegExp().

Fixes: https://issues.redhat.com/browse/DFBUGS-1517
Signed-off-by: Vinayakswami Hariharmath <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants