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

fix: ui path validation #297

Merged
merged 2 commits into from
Nov 23, 2023
Merged

Conversation

m-ildefons
Copy link
Contributor

@m-ildefons m-ildefons commented Nov 23, 2023

Fix validation of the UI application path by removing it.

This removes the buggy regex that tries in vain to validate that the user configured a correct path. This is a must-have for v0.23 as it otherwise breaks Longhorn integration.

Fixes: https://github.com/aquarist-labs/s3gw/issues/834

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • CHANGELOG.md has been updated should there be relevant changes in this PR

@m-ildefons m-ildefons added kind/bug Something isn't working area/ui User Interface priority/0 Needs to go into the next release or force a patch labels Nov 23, 2023
@m-ildefons m-ildefons added this to the v0.23.0 milestone Nov 23, 2023
@m-ildefons m-ildefons requested review from jecluis and votdev November 23, 2023 09:19
@m-ildefons m-ildefons self-assigned this Nov 23, 2023
@m-ildefons m-ildefons force-pushed the fix/ui-path-validation branch from 578f798 to 2b87a0f Compare November 23, 2023 09:25
Fix validation of the UI application path.

Signed-off-by: Moritz Röhrich <[email protected]>
@m-ildefons m-ildefons force-pushed the fix/ui-path-validation branch from 2b87a0f to d979ab1 Compare November 23, 2023 09:53
Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (eb05116) 98.86% compared to head (2217c95) 98.68%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #297      +/-   ##
==========================================
- Coverage   98.86%   98.68%   -0.19%     
==========================================
  Files          15       15              
  Lines        1061     1061              
==========================================
- Hits         1049     1047       -2     
- Misses         12       14       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -120,7 +120,7 @@ def get_ui_path() -> str:
def post_process(key: str, value: str | None) -> str:
if value is None or value == "/":
return "/"
match = re.fullmatch(r"/?[\w./-]+(?:[\w]+)/?", value)
match = re.fullmatch(r"[\w/-]+[\w/]+", value)
Copy link
Contributor

Choose a reason for hiding this comment

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

this still doesn't look right, because it will validate to true something like /-///. What about something like /?\w[\w-]+(?:/[\w-]+/?)$ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Is /-/// not a valid path in this context?
  2. Your regex allows something like /fooobar-//, which wouldn't be so great either.

I don't think we should be validating paths with regexes at all (ever tried to validate anything else remotely complex with regexes? Like an email address?).
But I couldn't find a library that can just tell me if something is a valid URL path.
What I'm trying to do with this commit is not excluding all possible invalid paths, but soften up the rules enough that valid paths don't fail validation anymore, as this will otherwise be a real problem with the Longhorn integration (see the error log in the linked issue)

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Is /-/// not a valid path in this context?

From the test you provided, I'm assuming it's not. Generally speaking, it wouldn't be, but we also don't have a definition of what is expected. 🤷

2. Your regex allows something like `/fooobar-//`, which wouldn't be so great either.

True, it can certainly see some more thinking and a few more iterations.

I don't think we should be validating paths with regexes at all (ever tried to validate anything else remotely complex with regexes? Like an email address?).

Well, yes. Regular expressions may be annoying, but they are incredibly powerful.

What I'm trying to do with this commit is not excluding all possible invalid paths, but soften up the rules enough that valid paths don't fail validation anymore, as this will otherwise be a real problem with the Longhorn integration (see the error log in the linked issue)

What's the cutoff for how much we soften this validation? Because I'd be more comfortable removing it altogether, rather than have a validation that does a half-baked job. At least by not validating we know that we are not validating, rather than have the false sense of security from a validation check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I'd be more comfortable removing it altogether, rather than have a validation that does a half-baked job

That's fine with me, I'll take the axe to the code then.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, please, leave a note on the code saying that needs to be validated, and file an issue for it.

Disable UI path validation completely.

Signed-off-by: Moritz Röhrich <[email protected]>
@jecluis
Copy link
Contributor

jecluis commented Nov 23, 2023

codecov is being annoying and I haven't been able to figure out how to reduce the threshold to something more reasonable. Merging without having it passing.

@jecluis jecluis merged commit 667e85b into s3gw-tech:main Nov 23, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui User Interface kind/bug Something isn't working priority/0 Needs to go into the next release or force a patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] UI: path validation broken
2 participants