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

Allow double slashes in the path according to the RFC3986 #77

Closed

Conversation

marcelthole
Copy link
Contributor

Q A
Documentation no
Bugfix yes
BC Break maybe
New Feature no
RFC no
QA no

Description

This resolves #74
maybe it could be a BC break, because the behavior of the getPath has changed.
its since this commit: 68fc742

Signed-off-by: Marcel Thole <marcel@marcelthole.de>
@@ -546,13 +546,6 @@ public function testFragmentIsNotDoubleEncoded()
$this->assertSame($expected, $uri->getFragment());
}

public function testProperlyTrimsLeadingSlashesToPreventXSS()
Copy link
Member

Choose a reason for hiding this comment

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

The "to prevent XSS" is the scariest bit here - I would suggest @weierophinney to look at it, considering the original 68fc742 commit.

I don't know the context for that initial commit myself, sorry :-\

The original text for the release:

## 1.0.4 - 2015-06-23

This is a security release.

A patch has been applied to `Zend\Diactoros\Uri::filterPath()` that ensures that
paths can only begin with a single leading slash. This prevents the following
potential security issues:

- XSS vectors. If the URI path is used for links or form targets, this prevents
  cases where the first segment of the path resembles a domain name, thus
  creating scheme-relative links such as `//example.com/foo`. With the patch,
  the leading double slash is reduced to a single slash, preventing the XSS
  vector.
- Open redirects. If the URI path is used for `Location` or `Link` headers,
  without a scheme and authority, potential for open redirects exist if clients
  do not prepend the scheme and authority. Again, preventing a double slash
  corrects the vector.

If you are using `Zend\Diactoros\Uri` for creating links, form targets, or
redirect paths, and only using the path segment, we recommend upgrading
immediately.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think the PSR-7 integration tests need to be updated to reflect this security fix.

@Ocramius
Copy link
Member

I've added this to the 2.9.0 milestone to prevent an accidental release that sails out without this, waiting for feedback first.

@boesing boesing removed this from the 2.9.0 milestone Mar 2, 2022
@Ocramius Ocramius requested a review from weierophinney April 6, 2022 16:21
@Ocramius
Copy link
Member

@laminas/technical-steering-committee I don't know what to do with this one: can I get an opinion, please?

@weierophinney
Copy link
Member

I'd consider the PSR-7 test suite in error here, as it leads to an XSS vulnerability, and I recommend providing them our security test instead.

@weierophinney
Copy link
Member

The part that particularly concerns me is the removal of the security related test - this would be not just a BC break, but reintroduction of a previously patched vulnerability.

@lcobucci
Copy link
Member

lcobucci commented May 23, 2022

I'd consider the PSR-7 test suite in error here, as it leads to an XSS vulnerability, and I recommend providing them our security test instead.

I think the tricky thing here is context since the XSS vulnerability happens depending on the usage.
A URI that looks like https://example.org//google.com is completely fine according to the RFC but might introduce the vulnerability if only the path is used to redirect users.

My question, though, is: should a low-level component such as a PSR-7 implementation be responsible for preventing those redirection vulnerabilities? If so, we should probably look at solving this on the specification level IMHO.

@weierophinney
Copy link
Member

should a low-level component such as a PSR-7 implementation be responsible for preventing those redirection vulnerabilities? If so, we should probably look at solving this on the specification level IMHO.

I think it should, as:

  • A URI instance can be used to make client requests; if the HTTP client is not robust, we've created a vulnerability for them.
  • The string representation is often used to create URIs for API payloads and/or web pages; again, if we spit these out without normalization, we create a vulnerability for them.

This latter is exactly what was reported, and the CVE was not limited to Diactoros, but was also reported against a number of libraries that generate/represent URIs.

In terms of solving it at the specification level, that's absolutely do-able (we recently did it for a class of vulnerabilities related to multi-line headers); I think we can still push a patch now to the upstream PSR-7 test suite with the test we created when patching the vulnerability reported against us.

weierophinney added a commit to weierophinney/psr7-integration-tests that referenced this pull request Jul 28, 2022
Per an [issue created for Diactoros](laminas/laminas-diactoros#74) its [related pull request](laminas/laminas-diactoros#77), and the discussion to that pull request, this patch does the following:

- It modifies `testPathWithMultipleSlashes()` to only validate that multiple slashes _not at the beginning_ of a path are retained intact.
- It adds `testProperlyTrimsLeadingSlashesToPreventXSS()`, which validates that when multiple leading slashes are present in a path, they are reduced to a single slash.

This approach is done to mitigate [ZF2015-05](https://framework.zend.com/security/advisory/ZF2015-05.html) which was also reported as [CVE-2015-3257](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-3257).
While RFC 3986 allows for multiple slashes anywhere in the path, when security conflicts with a specification, security concerns win.
Without the mitigation, an implementation is vulnerable to XSS and open redirects if only the path portion of a URI is used within HTML content (common!) or within headers (also common).

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@Ocramius
Copy link
Member

Maybe handled by #128 ? Unsure 🤔

@weierophinney
Copy link
Member

Maybe handled by #128 ? Unsure

Yes - #128 provides the correct solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSR-7 Integration Tests Failing
6 participants