Skip to content

Prevent possible XSS via changeDebugUrl #519

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

Merged
merged 9 commits into from
Aug 9, 2022
Merged

Conversation

AltamashShaikh
Copy link
Contributor

Description:

Changes to fix possible XSS via changeDebugUrl

Review

@AltamashShaikh AltamashShaikh marked this pull request as ready for review July 27, 2022 04:47
Copy link
Contributor

@snake14 snake14 left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Which issue is this for again? I don't see the issue number in the PR description or any of the commit messages. Did you do that for a specific reason?

@AltamashShaikh
Copy link
Contributor Author

The changes look good to me. Which issue is this for again? I don't see the issue number in the PR description or any of the commit messages. Did you do that for a specific reason?

@snake14 This was a fix for XSS vulnerability report which I have shared in the slack channel you can check that

@snake14
Copy link
Contributor

snake14 commented Jul 28, 2022

@snake14 This was a fix for XSS vulnerability report which I have shared in the slack channel you can check that

@AltamashShaikh Thank you. I see it now.

API.php Outdated
{
$this->accessValidator->checkWriteCapability($idSite);
if (!filter_var($url, FILTER_VALIDATE_URL)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm actually wondering if using FILTER_VALIDATE_URL only might cause problems here. It does not check if the protocol is "safe". It could also be ssh:// or similar. So we could additionally check preg_match('/^https?:\/\//'), or do you think other protocols are needed there as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sgiehl Added stripos($url, 'http') check to ensure valid protocol is present.

Copy link
Member

Choose a reason for hiding this comment

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

the problem with stripos === false is, that you don't check if it's in the beginning. So something like ssh://http.webhost.com would pass here... So guess you would need to compare with !== 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated and added few testcases too

API.php Outdated
{
$this->accessValidator->checkWriteCapability($idSite);
if (!filter_var($url, FILTER_VALIDATE_URL) || stripos($url, 'http') !== 0) {
Copy link
Member

Choose a reason for hiding this comment

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

fyi @AltamashShaikh does it make sense to also look at UrlHelper::isLookLikeSafeurl("") here additionally? it includes a few additional checks. There's also isLookLikeurl("") which may be interesting too not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tsteur Ideally the 'stripos($url, 'http') === 0' should fix most of the cases but adding both the methods makes no harm.

Copy link
Member

Choose a reason for hiding this comment

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

👍 that's what I thought. Better be safe. Also in the future someone might add more changes to core and we won't remember to add them here as well meaning then we're covered.

@AltamashShaikh AltamashShaikh merged commit 2edec7e into 4.x-dev Aug 9, 2022
@AltamashShaikh AltamashShaikh deleted the xss-fix-debug-url branch August 9, 2022 02:35
@justinvelluppillai justinvelluppillai changed the title Changes to fix possible XSS via changeDebugUrl Prevent possible XSS via changeDebugUrl Aug 30, 2022
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.

4 participants