Closed Bug 1735159 Opened 5 years ago Closed 4 years ago

reflected xss at https://firefox-ci-tc.services.mozilla.com/ -1 user click required only‏‏

Categories

(Websites :: Other, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: versx39, Assigned: pmoore)

References

()

Details

(Keywords: reporter-external, sec-moderate, wsec-xss, Whiteboard: [reporter-external] [web-bounty-form])

Attachments

(2 files, 1 external file)

hello mozilla sec team today when i was analyzing ur website
https://firefox-ci-tc.services.mozilla.com
i came across reflected value at
https://firefox-ci-tc.services.mozilla.com/auth/scopes/expansions?scopes[0]=
i put simple payload for Ex:
"><img src=x onerror=alert(document.domain)>
and the xss didnt trigger then i realse i should to click on expand scope button`
then the xss was triggered
Check the video

Flags: sec-bounty?

Thanks for the report. I can confirm as follows:

  1. Log into https://firefox-ci-tc.services.mozilla.com/
  2. Visit https://firefox-ci-tc.services.mozilla.com/auth/scopes/expansions?scopes%5B0%5D=%22%3E%3Cimg%20src%3Dx%20onerror%3Dalert%28document.domain%29%3E
  3. Click the expand scopes button in the bottom right. This makes the request:
curl 'https://firefox-ci-tc.services.mozilla.com/graphql' -X POST -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://firefox-ci-tc.services.mozilla.com/' -H 'content-type: application/json' -H 'Authorization: Bearer <redacted>' -H 'Origin: https://firefox-ci-tc.services.mozilla.com' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Cookie: connect.sid=<redacted>' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'TE: trailers' --data-raw '{"operationName":"Scopeset","variables":{"scopes":["\"><img src=x onerror=alert(document.domain)>"]},"query":"query Scopeset($scopes: [String]!) {\n  expandScopes(scopes: $scopes)\n}\n"}'
{"data":{"expandScopes":["\"><img src=x onerror=alert(document.domain)>"]},"extensions":{"tracing":{"version":1,"startTime":"2021-10-11T14:27:50.486Z","endTime":"2021-10-11T14:27:50.495Z","duration":8396044,"execution":{"resolvers":[{"path":["expandScopes"],"parentType":"Query","fieldName":"expandScopes","returnType":"[String]!","startOffset":640234,"duration":7709687}]}}}}
Status: UNCONFIRMED → NEW
Type: task → defect
Ever confirmed: true
Keywords: wsec-xss
Whiteboard: [reporter-external] [web-bounty-form] [verif?] → [reporter-external] [web-bounty-form]

https://firefox-ci-tc.services.mozilla.com/auth/scopes/expansions?scopes[0]= returns CSP with script-src including unsafe-eval and unsafe-inline sources.

cvalaas or bwells: not sure who the security contacts are for TC these days, can you redirect this to the relevant devs?

There are a few things to fix that come to mind:

  • the expanded scope output should be inserted as text and not html. If it has to be inserted as HTML it should be escaped with the HTML sanitizer API or dompurify
  • the graphql endpoint should perform stricter validation on the scope input e.g. for allowed chars and max length
  • CSP for the page should not include unsafe-* sources
Flags: needinfo?(cvalaas)
Flags: needinfo?(bwells)

hello mr.greg
i am not that match good at English can i share the poc video to email of
bugzilla@mozilla.org?
i share the bug and video to
security@mozilla.org and the forwarded me to submit it here

(In reply to saad alhrby from comment #4)

Hi Saad, Mozilla will use this bug to discuss how to fix the issue with the site operators and developers. I started that discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1735159#c2 and https://bugzilla.mozilla.org/show_bug.cgi?id=1735159#c3 . I will use the need info feature if I need to request more information from you. Thanks!

aha now i got it thanks Mr Greg for clarifying Things

Benson's team are the devs for TC, I'll leave it to him to triage.

Flags: needinfo?(cvalaas)
Flags: needinfo?(bwong)
Flags: needinfo?(bwells)
Flags: needinfo?(bwong) → needinfo?(pmoore)
Flags: needinfo?(pmoore)

It looks like the "Expand Scopes" UI feature was added in taskcluster-web PR #81 and now lives in the monorepo here.

FTR, there are a few places dangerouslySetInnerHTML is used, we should probably check them all (unless I'm barking up the wrong tree):

pmoore@pmoore-laptop:~/git/taskcluster main $ git grep -il dangerouslysetinnerhtml
ui/src/components/ClientForm/index.jsx
ui/src/components/Code/index.jsx
ui/src/components/Markdown/index.jsx
ui/src/components/RoleForm/index.jsx
ui/src/utils/scopeUtils.js
ui/src/views/Scopes/ScopesetExpander/index.jsx

It looks like we can test changes to the CSP without adversely affecting behaviour by means of the Content-Security-Policy-Report-Only header. Well that's cool!

(In reply to Greg Guthe [:g-k] [:gguthe] from comment #3)

  • the expanded scope output should be inserted as text and not html. If it has to be inserted as HTML it should be escaped with the HTML sanitizer API or dompurify

I believe the escaping needs to occur here and will have a go at doing it.

  • the graphql endpoint should perform stricter validation on the scope input e.g. for allowed chars and max length

It turns out scopes are any valid ASCII string that does not end in more than one asterisk, so the exploit string would currently qualify as a valid scope.

  • CSP for the page should not include unsafe-* sources

I tried removing the unsafe-* entries, which csp-evaluator also warns against, in a local deployment. Unfortunately I wasn't able to test this in a local deployment. TLDR; I suspect the headers are managed by nginx in production, and this isn't included in the local deployment.

Following the Hacking on the UI Guide, I could get my UI deployment running, however when inspecting the CSP header of my local deployment of the exploit URL, the CSP header (and others too) were not present:

HTTP/1.1 304 Not Modified
X-Powered-By: Express
Accept-Ranges: bytes
ETag: W/"209-uvHzhbKDDG6Iod0q/Nb95PlyHnY"
Date: Wed, 13 Oct 2021 14:21:04 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Since I was getting a cached response, I also tried with curl from the command line, but also didn't see the CSP header:

$ curl -v -L 'http://localhost:5080/auth/scopes/expansions?scopes%5B0%5D=%22%3E%3Cimg%20src%3Dx%20onerror%3Dalert%28document.domain%29%3E'
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 5080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5080 (#0)
> GET /auth/scopes/expansions?scopes%5B0%5D=%22%3E%3Cimg%20src%3Dx%20onerror%3Dalert%28document.domain%29%3E HTTP/1.1
> Host: localhost:5080
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Content-Length: 521
< ETag: W/"209-uvHzhbKDDG6Iod0q/Nb95PlyHnY"
< Date: Wed, 13 Oct 2021 14:27:59 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1"></head>
    <body>
        <script src="/static/env.js"></script>
        <div id="root"></div>
    <script src="/assets/runtime.js"></script><script src="/assets/vendors~docs~index.js"></script><script src="/assets/docs~index.js"></script><script src="/assets/index.js"></script></body>
</html>
* Connection #0 to host localhost left intact
* Closing connection 0

I do see the CSP header in the production deployment:

HTTP/2 200 OK
server: openresty
date: Wed, 13 Oct 2021 14:20:29 GMT
content-type: text/html; charset=utf-8
content-length: 580
last-modified: Wed, 28 Apr 2021 14:59:33 GMT
etag: "60897855-244"
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: origin
content-security-policy: default-src 'none'; connect-src 'self' https: wss:; media-src data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' https:; font-src 'self' data:; img-src 'self' https: data:; style-src https: 'unsafe-inline'; object-src 'none'; frame-ancestors 'self'; frame-src 'self' https://auth.mozilla.auth0.com; base-uri 'none'; form-action 'none'
strict-transport-security: max-age=31536000
accept-ranges: bytes
via: 1.1 google
alt-svc: clear
X-Firefox-Spdy: h2

This leads me to believe that the "dev setup" operates differently enough to a production deployment, that I might need a cloud deployment to test changes to the CSP header, which I will set about doing.

Hello Pete,

I am still able to reproduce this issue, is there an update on the CSP configuration?

I am also wondering if it would be possible to validate the scopes parameter, for example, check it against a list of allowed values and reject the request if it's using an invalid value.

Thanks,
Frida

Flags: needinfo?(pmoore)
Flags: needinfo?(pmoore)

Hi Frida,

I'm afraid I haven't made any changes since my previous comments. I've just discussed with my teammates, and they noticed that this code was introduced for a cosmetic improvement in https://github.com/taskcluster/taskcluster/pull/974 so our preferred course of action will be to revert the changes from this PR and make a new release. We can then review if there is a safer way to achieve the same changes in a future PR.

To complicate things, I think we may be in a Christmas/New Year deployment code freeze at the moment, it might not be trivial for us to have the change landed before the new year, although if this is considered high priority, it may be possible.

Thanks,
Pete

It's quite an old change, so some merge conflicts have crept in. I'll have a closer look tomorrow...

$ git revert 8bf75678626567ec2fdae3889dff2f6d86235958
Auto-merging ui/src/views/Scopes/ScopesetExpander/index.jsx
CONFLICT (content): Merge conflict in ui/src/views/Scopes/ScopesetExpander/index.jsx
Removing ui/src/utils/scopeUtils.js
Auto-merging ui/src/components/RoleForm/index.jsx
CONFLICT (content): Merge conflict in ui/src/components/RoleForm/index.jsx
Auto-merging ui/src/components/ClientForm/index.jsx
CONFLICT (content): Merge conflict in ui/src/components/ClientForm/index.jsx
error: could not revert 8bf756786... [UI] Give special characters in scopes more emphasis (#974)
Attached file GitHub Pull Request —
Assignee: nobody → pmoore
Status: NEW → ASSIGNED

This screenshot demonstrates the issue on a local deployment, before the fix from PR #5019 is applied.

This screenshot demonstrates the issue on a local deployment, after the fix from PR #5019 is applied.

Hello Pete,

Thank you for the update. The solution looks good, I am curious how regular input looks like using the original method of expanding the scopes, would reverting those changes break anything?

There is also a library that could help sanitize the input, https://github.com/cure53/DOMPurify, but of course this method is not a sure way to protect against XSS, the best way is to rely on the output encoding provided by React, and this is bypassed when using dangerouslySetInnerHTML.

Thanks,
Frida

From the original PR which introduced this exploit, it looked like there may be a similar exploit for:

since both of these appear to use the same dangerouslySetInnerHTML feature.

However, using the same escape string ("><img src=x onerror=alert(document.domain)>) in the above forms, I wasn't able to trigger the same behaviour (perhaps a different escape pattern is required). But since I've reverted the entire PR, even if they did introduce an exploit through use of this function, that should also be gone now too.

Note there, are still two outstanding uses of dangerouslySetInnerHTML that originate from another source:

$ git grep -il dangerouslysetinnerhtml
ui/src/components/Code/index.jsx
ui/src/components/Markdown/index.jsx

Before closing this bug, we should investigate these too.

(In reply to Frida Kiriakos [:frida] from comment #21)

Hello Pete,

Thank you for the update. The solution looks good, I am curious how regular input looks like using the original method of expanding the scopes, would reverting those changes break anything?

The change in the offending PR was intended just to emphasize individual characters in the html rendering:

// Given a scope, this utility returns a string with the special characters
// wrapped in <strong /> elements to provide more emphasis.
// Note: dangerouslySetInnerHTML will be required to render the string as jsx
exports.formatScope = scope =>
  scope.replace(/^assume:|\*$|<..>/g, match => `<strong>${match}</strong>`);

so we just lose the <strong/> for scopes that match, which shouldn't break anything.

There is also a library that could help sanitize the input, https://github.com/cure53/DOMPurify, but of course this method is not a sure way to protect against XSS, the best way is to rely on the output encoding provided by React, and this is bypassed when using dangerouslySetInnerHTML.

Yes, agreed, I'm not sure why dangerouslySetInnerHTML was chosen, it seems a very surprising choice given the security implications it entails. I will endeavor to eradicate its usage, and prevent it returning. If we are to have it anywhere, it should only be if we can guarantee with 100% certainty that the particular implementation is not subject to any present or future exploits, we have explicit approval from the security team, it is decided there is no alternative solution which is safer, and the feature is absolutely needed. Using it is tantamount to playing with fire, so I'd like to avoid it at all costs! :-)

(In reply to Pete Moore [:pmoore][:pete] from comment #22)

Note there, are still two outstanding uses of dangerouslySetInnerHTML that originate from another source:

$ git grep -il dangerouslysetinnerhtml
ui/src/components/Code/index.jsx
ui/src/components/Markdown/index.jsx

Before closing this bug, we should investigate these too.

I checked the code but could not tell for sure whether, for example, the code parameter on this line https://github.com/taskcluster/taskcluster/blob/main/ui/src/components/Code/index.jsx#L46 includes external input that could be set by users, if we can be sure that no external input is being used here then it might be ok. I agree with you though that if there is a safer way to do the same thing, then we should avoid using dangerouslySetInnerHTML.

It looks to me like the Code element is for rendering yaml/json and the Markdown is for rendering markdown as HTML.

I'm hoping the render function of the markdown library is safe (i.e. does necessary escaping so that markdown cannot be crafted to cause an exploit).

I'm going to look into whether the yaml/json rendering takes a JS object and converts it to a textual json/yaml representation of the object, or whether it takes a json/yaml representation, and renders it as HTML. If it is the former, I suspect we don't need to use dangerouslySetInnerHTML, but if it is the latter, maybe it is needed.

I've created PR #5020 to play around and test the impact of escaping inputs, to see if we get double-escaping in either case. If we get double escaping, I'll check the underlying libraries, to see what measures they take to ensure generated HTML is safe against exploits (i.e. suitably escapes inputs). Since I'm not sure at this point if it will be needed or not, I've made it a draft PR.

Hello Pete,

I see that the PR https://github.com/taskcluster/taskcluster/pull/5019/files was merged, however, the issue is still reproducible. Were the changes released on the affected instance https://firefox-ci-tc.services.mozilla.com?

Thanks,
Frida

Flags: needinfo?(pmoore)

Hi Frida,

I'm afraid not yet, although we have a project kickoff today, to instigate a fortnightly release/deployment cycle, and therefore this should reach production in February.

Let me know if you have any concerns.

Many thanks,
Pete

Flags: needinfo?(pmoore)
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Flags: sec-bounty? → sec-bounty+

Hello Saad,

We had a chance to discuss the bounty for this report and we decided to pay you for an XSS vulnerability, since it requires a user to click on the payload, we rated this issue as sec-moderate.

Please let us know how you would like to be mentioned in our hall of fame.

Thanks again for your valuable report.

Regards,
Frida

Flags: needinfo?(versx39)

Hello firda
would mention like this

' saad alhrby @lazysaad'

And may i know if bug eligible for bounty? And if yes can i know payment will be throught hackerone nor bugcrowd or where?
Thanks, saad

Flags: needinfo?(versx39)

Hello Saad,

We already posted the bug bounty as attachment, you can see it at the top of the bug. We paid $2500 as bounty.

Someone from our team will contact you in the coming weeks to get your financial details and send you the money.

Thanks,
Frida

Thanks frida and really appricated the huge amount of bounty🙏

(In reply to Pete Moore [:pmoore][:pete] from comment #24)

I've created PR #5020 to play around and test the impact of escaping inputs, to see if we get double-escaping in either case. If we get double escaping, I'll check the underlying libraries, to see what measures they take to ensure generated HTML is safe against exploits (i.e. suitably escapes inputs). Since I'm not sure at this point if it will be needed or not, I've made it a draft PR.

I wasn't able to find anything.

Boris, Yarik, Chris, Aki,

Do any of you see a reason not to disclose this bug, now that the fix has been rolled out to staging, community and firefox-ci? Are there any open issues you think we need to address before making this information public?

Many thanks.

Flags: needinfo?(ykurmyza)
Flags: needinfo?(mboris)
Flags: needinfo?(cvalaas)
Flags: needinfo?(aki)

I was checking the code right now.
It looks like that unsafe html is currently only used in <Markdown> component, and I couldn't notice any user input passed to those components.
But it is being used to render description field of task/action. (And those require authentication already)
Checked some possible xss attack vectors on task description, but it seems to be tackled correctly by markdown component, so js-specific parts are not executed.

This is ok to be disclosed, especially because taskcluster is open source

Flags: needinfo?(ykurmyza)
Flags: needinfo?(mboris)
Flags: needinfo?(aki)
Flags: needinfo?(cvalaas)

Thanks Pete and Yarik for the information.

Group: websites-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: