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

Paths with multiple slashes /// should be treated as one slash / #12354

Open
slonka opened this issue Dec 20, 2024 · 2 comments
Open

Paths with multiple slashes /// should be treated as one slash / #12354

slonka opened this issue Dec 20, 2024 · 2 comments
Labels
kind/bug A bug triage/accepted The issue was reviewed and is complete enough to start working on it

Comments

@slonka
Copy link
Contributor

slonka commented Dec 20, 2024

What happened?

Right now we're responding with 404 on things like:

curl --location --request PUT 'http://localhost:5681//meshes/new5'

We should collapse the // and respond accordingly.


RFC 3986 defines the syntax for Uniform Resource Identifiers (URIs) but does not explicitly state that multiple consecutive slashes in paths should be treated as a single slash. Here's how RFC 3986 addresses this topic:

Path Syntax: Section 3.3 of RFC 3986 defines the path component of a URI and permits consecutive slashes:

path          = path-abempty    ; begins with "/" or is empty
              / path-absolute   ; begins with "/" but not "//"
              / path-noscheme   ; begins with a non-colon segment
              / path-rootless   ; begins with a segment
              / path-empty      ; zero characters

path-abempty  = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]

This explicitly allows for multiple slashes in the path (e.g., /foo//bar) without stating that they must be treated as equivalent to a single slash.

but it seems to be a common implem:

The behavior of collapsing multiple consecutive slashes into a single slash in URLs is commonly implemented in web servers like Apache and Nginx. This process, known as path normalization, ensures consistent and secure handling of URL paths.

Apache HTTP Server:

In Apache HTTP Server version 2.4.49, a function called ap_normalize_path was introduced to handle path normalization. This function processes incoming URL paths to remove unnecessary components, such as multiple slashes, ensuring a standardized format. However, it's important to note that improper implementation of this function led to vulnerabilities like CVE-2021-41773, highlighting the critical role of path normalization in security. 

Nginx:

Nginx also performs path normalization to manage URL paths effectively. By default, Nginx normalizes URIs, which includes collapsing multiple consecutive slashes into a single slash. This behavior ensures that URLs are processed in a consistent manner, enhancing both security and performance. For instance, in proxy configurations, Nginx normalizes the URI before passing it to the backend server, unless explicitly configured otherwise. 
ECOSTACK

It's important to recognize that while both Apache and Nginx implement path normalization, the specifics can vary between versions and configurations. Administrators should be aware of these behaviors to ensure that URL handling aligns with their application's requirements and security policies.

https://www.hackthebox.com/blog/cve-2021-41773-explained
https://ecostack.dev/posts/nginx-rewrite-path-without-normalizing-uri-using-proxy-pass

@slonka slonka added triage/pending This issue will be looked at on the next triage meeting kind/bug A bug labels Dec 20, 2024
@lahabana lahabana added triage/accepted The issue was reviewed and is complete enough to start working on it and removed triage/pending This issue will be looked at on the next triage meeting labels Dec 23, 2024
@lahabana
Copy link
Contributor

triage: Could be interesting to support however, looks like our http server doesn't do this, it's also the server that k8s uses, if it's a thing that exists on k8s too, we shouldn't bother fixing.

@slonka
Copy link
Contributor Author

slonka commented Dec 24, 2024

I confirmed that it does not work for k8s API as well :|

curl --cert ./client.crt --key ./client.key -k https://10.43.0.1:443/api/v1/namespaces/default//pods

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "the server could not find the requested resource",
  "reason": "NotFound",
  "details": {},
  "code": 404
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug triage/accepted The issue was reviewed and is complete enough to start working on it
Projects
None yet
Development

No branches or pull requests

2 participants