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 page tree node slug validation to prevent URL encoded characters #2229

Merged
merged 10 commits into from
Jan 15, 2025

Conversation

fichtnerma
Copy link
Contributor

@fichtnerma fichtnerma commented Jul 1, 2024


Improve the Slug validation to filter out url escaped special characters to prevent path traversal attacks

PR Checklist

  • Verify if the change requires a changeset. See CONTRIBUTING.md
  • Link to the respective task if one exists: COM-788
  • Provide screenshots/screencasts if the change contains visual changes

@auto-assign auto-assign bot requested a review from johnnyomair July 1, 2024 10:28
@dkarnutsch
Copy link
Contributor

dkarnutsch commented Jul 1, 2024

This would be very suitable for a unit test

@nsams
Copy link
Member

nsams commented Jul 1, 2024

Please write a description for your PR

@johnnyomair
Copy link
Collaborator

@nsams
Copy link
Member

nsams commented Jul 22, 2024

  • you are removing url encoded special characters (%ab)

But you are also:

  • you are removing ~ and . from the allowed chars
  • you are not allowing uppercase letters anymore
  • not allowing - or _ a at the beginning (eg. -abc is not allowed)
  • not allowing more than one - or _ (eg. abc--123 is not allowed)
  • not allowing - or _ a the and (eg. abc- is not allowed)

(at least that is what I observed by looking at your regex)

That should all have been explained in the description, together with reasons for the change.


And as support for encoded special chars was explicitly implemented, are we really sure we can remove it? What was it originally inteded for?

@johnnyomair
Copy link
Collaborator

And as support for encoded special chars was explicitly implemented, are we really sure we can remove it? What was it originally inteded for?

Was this explicitly implemented?

Background: In a recent pen test it was concerned that certain characters in the slug input aren't allowed, but that the url-encoded variants of those characters are allowed.

@johnnyomair
Copy link
Collaborator

Was this explicitly implemented?

@fichtnerma could you please check when and why this was originally implemented?

Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

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

We still need to check why this was added and if it can be removed.

.changeset/blue-flies-compete.md Outdated Show resolved Hide resolved
@johnnyomair johnnyomair changed the title Improve Slug validation Fix page tree node slug validation to prevent URL encoded characters Sep 17, 2024
@fichtnerma
Copy link
Contributor Author

Was this explicitly implemented?

@fichtnerma could you please check when and why this was originally implemented?

This validation was added before this repository was moved over to github and as far as i can tell this was not implemented for a specific reason other than the regex supporting all allowed chars in a URI according to https://tools.ietf.org/html/rfc3986#section-2.1

@johnnyomair
Copy link
Collaborator

@fichtnerma please address this concern: #2229 (comment). IMO we should only remove the URL encoded characters here.

@fichtnerma
Copy link
Contributor Author

  • you are removing url encoded special characters (%ab)

But you are also:

  • you are removing ~ and . from the allowed chars
  • you are not allowing uppercase letters anymore
  • not allowing - or _ a at the beginning (eg. -abc is not allowed)
  • not allowing more than one - or _ (eg. abc--123 is not allowed)
  • not allowing - or _ a the and (eg. abc- is not allowed)

(at least that is what I observed by looking at your regex)

That should all have been explained in the description, together with reasons for the change.

And as support for encoded special chars was explicitly implemented, are we really sure we can remove it? What was it originally inteded for?

I have adjusted the validator to only fail if a slash was provided.
The rest of your examples do now work again and were added as tests.

@johnnyomair
Copy link
Collaborator

In the linked task it also mentions ".". Wouldn't it be better to remove URL encoding altogether?

@johnnyomair
Copy link
Collaborator

@fichtnerma we discussed this in last week's meeting: Please remove support for URL encoded characters in general (as it's supposedly a security issue).

johnnyomair
johnnyomair previously approved these changes Oct 30, 2024
Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

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

LGTM. @dkarnutsch @nsams please review.

Copy link
Contributor

@dkarnutsch dkarnutsch left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Daniel Karnutsch <dkarnutsch@users.noreply.github.com>
Co-authored-by: Daniel Karnutsch <dkarnutsch@users.noreply.github.com>
@johnnyomair johnnyomair self-requested a review January 14, 2025 11:10
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@johnnyomair johnnyomair merged commit 64173b5 into main Jan 15, 2025
12 of 13 checks passed
@johnnyomair johnnyomair deleted the COM-788-slug-validation-improvements branch January 15, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants