Skip to content
OAuth / SSO Write-up Intermediate

How I hacked Altervista.org

The OAuth redirect_uri parameter was insufficiently validated, allowing an attacker to craft a link that redirects the authorization code to an attacker-controlled server. An attacker could steal the authorization code and use it to log in as the victim.

Jacopo Tediosi Follow

Published on medium.com

The original lives on medium.com

We do not hold its text, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Altervista is an Italian web platform where you can open a website for free, with PHP, MySQL database and FTP access. Use of the space is free, but some additional services are subject to charges. Altervista was bought by Mondadori spa in 2016, and today it hosts about 3 million sites. Users manage their website through a web panel after logging in, and there is also a forum where people ask programming questions and take part in community life.

The Altervista Forum From the original on medium.com

The Altervista Forum

The feature at the centre of this write-up is the single sign-on between the administration panel and the forum. If you have already logged in to the administration panel of your site, logging in on the forum only requires clicking the "Login" button, without retyping your credentials. That button is a simple link to:

Text
https://aa.altervista.org/?client_id=altervista&response_type=code&redirect_uri=http://forum.it.altervista.org/

If the user has already authenticated, that page does nothing more than generate an authorization_code and then redirect them to:

Text
http://forum.it.altervista.org/login.php?do=login-[redacted]%3D%3D&authorization_code=XXXXXXXXXXXXXXXXXXX

The do parameter contains the word login followed by the link http://forum.it.altervista.org/forum.php encoded in base64, which the author calls an odd choice. The authorization_code parameter carries the code generated before. If the user has not authenticated yet, the flow first asks for username and password and then redirects the same way.

Setup

This was the author's first bug bounty and first write-up in English. No special tooling, accounts or versions are described beyond a browser and manual fuzzing of the redirect_uri parameter. The precondition for the interesting behaviour is a user who is already authenticated to the Altervista administration panel, so that the authorisation endpoint issues a code without prompting for credentials.

Finding it

The author spent some time on Altervista and noticed the credential-free forum login described above, then studied how the Login button works. The reasoning was straightforward: if the value of the redirect_uri GET parameter can be changed, one can craft a link that, when clicked, redirects the user to an attacker-controlled server instead of the Altervista server. The authorization_code appended at the end of the URL would then land on the attacker's side, and the attacker could log in with it.

A filter stood in the way: the parameter appeared to accept only subdomains of it.altervista.org. The author then recalled a LiveOverflow video, "HOW FRCKN' HARD IS IT TO UNDERSTAND A URL?!", which shows that programmers often make mistakes when parsing URLs, especially when the input is not compliant with specifications. That set the direction: rather than fighting the filter directly, look for a URL shape that the filter reads one way and the redirect logic reads another.

Exploitation

Step 1: bypass the redirect_uri filter

The author started fuzzing until a bypass was found:

Text
https://aa.altervista.org/?client_id=altervista&response_type=code&redirect_uri=http://google.it/http://it.altervista.org/

The redirect_uri value here is http://google.it/http://it.altervista.org/, and the endpoint redirects to it. The endpoint redirects as follows:

We can steal access token From the original on medium.com

We can steal access token

Step 2: point the redirect at an attacker server

With the bypass confirmed, the attacker replaces google.it with the address of their own malicious server. The victim who clicks the crafted link is sent to that server with the authorization_code attached, and the attacker can then use the stolen code to log in as the victim:

Logging in with another person’s account From the original on medium.com

Logging in with another person's account

The do parameter is the base64-encoded forum URL as seen in the legitimate flow, and authorization_code is the code captured from the victim's redirect.

Root cause

The report says a filter on redirect_uri accepted only subdomains of it.altervista.org, and that the crafted value bypassed it. The crafted value http://google.it/http://it.altervista.org/ was accepted and the endpoint redirected to it. The report does not show the server-side code or explain the exact parsing behaviour.

Impact

An attacker who can get an authenticated Altervista user to open a crafted link receives that user's authorization_code on a server they control, and can then log in to the forum as that user. The author frames it as stealing the access token and logging in with another person's account.

Fix

Altervista fixed the issue almost immediately after the report. The report does not describe the change that was made. The general remedy is to parse redirect_uri and compare the resulting scheme and host against an exact allow-list, rather than searching the raw string for a permitted substring.

Timeline

  • 02 January 2018: Started looking for vulnerabilities on Altervista.org
  • 03 January 2018: Discovered the vulnerability and sent a PoC to their Security Team
  • 04 January 2018: Patch went online and the author's name was added to the thanks list

The author reported the discovery through the appropriate form, and as a reward Altervista added the name to their thanks list:

Thanks list screenshot From the original on medium.com

Thanks list screenshot

Variants to test

  1. Host confusion in redirect_uri. Try values where a permitted host appears as a path, query or userinfo component, for example http://attacker.example/http://allowed.example/. A positive result is a redirect to attacker.example while the parameter is accepted.
  2. Userinfo trick. Try http://[redacted]/. A positive result is a redirect to attacker.example rather than to the permitted host.
  3. Subdomain suffix matching. Try hosts such as allowed.example.attacker.example. A positive result is acceptance of a host that merely ends with the permitted string.
  4. Scheme-relative and backslash forms. Try //attacker.example and http:\\attacker.example. A positive result is a redirect off-site after the parameter passes validation.
  5. Encoded and double-encoded separators. Try %2f, %5c and double-encoded variants inside the value. A positive result is a redirect whose final host differs from the one the filter inspected.
  6. Code reuse after redirect. Where an authorisation code is issued, check whether it is bound to the client and redirect URI and whether it is single-use. A positive result is a code that can be redeemed from a different client or reused after the first exchange.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

Altervista is an Italian web platform where anyone can open a website for free. You get PHP, a MySQL database and FTP access, and you manage your site through a web panel after logging in. Some extra services cost money. Altervista was bought by Mondadori spa in 2016 and hosts about 3 million sites. Besides the panel, there is a forum where people ask programming questions and take part in community life.

The Altervista Forum From the original on medium.com

The Altervista Forum

The interesting part is how you log in to the forum. If you are already logged in to the administration panel of your site, you do not have to type your username and password again on the forum: you just click a "Login" button. That button is a plain link to a special Altervista address. That address is part of a login system that hands out a pass, called an authorization_code, to a user who is already logged in.

The author noticed this convenience and asked a simple question: what happens if I change the address the login page sends me back to? If that address can be swapped for one the attacker controls, the pass would be delivered to the attacker instead of to the forum. The attacker could then use the pass to log in as the victim. This kind of flaw is called an open redirect: a site that takes a destination from the URL and sends the user there without properly checking that the destination is one of its own.

A filter tried to stop this by accepting only addresses under it.altervista.org. The author found a way around the filter by crafting an address that contains the allowed name but actually points somewhere else. Altervista fixed it almost immediately after the report.

About Altervista.org

From Wikipedia:

AlterVista is an Italian web platform where you can open a website for free. On AlterVista, you can create a website with PHP, MySQL database, and FTP access. Use of the space is free, but some additional services are subject to charges. Altervista was bought by Mondadori spa in 2016, and today it hosts about 3 million sites.

Altervista allows you to manage your website via a comfortable web panel after logging in.

It also has a forum where people can ask programming questions and participate in community life:

The Altervista Forum From the original on medium.com

The Altervista Forum

How the Altervista login system works

The author wandered on Altervista for a while until noticing that, if you had already logged in to the administration panel of your site, to log in on the forum you just have to click on the "Login" button without retyping your credentials. So the author started studying how that button works.

It was a simple link to:

Text
https://aa.altervista.org/?client_id=altervista&response_type=code&redirect_uri=http://forum.it.altervista.org/

This is a URL with a question mark in the middle. Everything after the ? is a list of parameters, written as name=value pairs joined by &. Servers read these to decide what to do. Here is what each one means:

  • client_id=altervista tells the login service which application is asking. Think of it as the name on a form: "this request comes from Altervista".
  • response_type=code says what kind of answer is wanted. code means: do not give me the user's password, give me a short one-time pass instead. That pass is the authorization_code.
  • redirect_uri=http://forum.it.altervista.org/ is the address the user should be sent back to once the pass has been issued. It is the "return address" written on the envelope.

This pattern, where one site asks another site to confirm who the user is and hands back a code, is called single sign-on (SSO). The everyday comparison: you show your ID once at the entrance of a building, and every desk inside trusts the stamp you got at the door instead of asking for your ID again.

If a user has already authenticated, that page does nothing more than generate an authorization_code and then redirect them to:

Line by line:

  • http://forum.it.altervista.org/login.php is the forum's login script. It is the page that will accept the pass and start a session.
  • do=login-[redacted]%3D%3D is a parameter whose value starts with the word login, then a hyphen, then a long string of letters and digits. That long string is the address http://forum.it.altervista.org/forum.php written in base64, a way of encoding text using only letters, digits and a few symbols so it can travel safely inside a URL. The author calls this an odd choice, because the address could simply have been written normally. The %3D%3D at the end is how the two = padding characters of base64 are written inside a URL.
  • authorization_code=XXXXXXXXXXXXXXXXXXX is the pass itself. The Xs stand for the real value, which the report does not show.

If the user has not authenticated yet, the flow first asks for username and password and then redirects the same way.

How I came to discover the vulnerability

The reasoning was: suppose we can change the value of the redirect_uri GET parameter. In that case, we can create a particular link that, when clicked, redirects the user to our servers instead of the Altervista server, allowing us to steal the authorization_code added at the end of the URL, and then log in with that.

Why does this work? Because the pass is appended to whatever address the login service sends the user to. If that address is the attacker's, the pass arrives at the attacker's server as part of the URL. The attacker receives the pass on their own server, then uses it to log in as the victim. The victim only has to click the link.

Unfortunately, there seemed to be a filter on the parameter, which accepted only subdomains of it.altervista.org. A filter here is a check on the server that inspects the value and rejects it if it does not look right. A subdomain is the part in front of a domain name: in forum.it.altervista.org, forum is a subdomain of it.altervista.org.

At this point, the author remembered a video by LiveOverflow:

Video: "HOW FRCKN' HARD IS IT TO UNDERSTAND A URL?!"

It shows that programmers often make mistakes when they have to parse URLs, especially when the input is not compliant with specifications. Parsing means breaking a string into its parts: scheme (http), host (forum.it.altervista.org), path (/login.php), and so on. The everyday comparison: two people reading the same address label can disagree about which line is the street and which is the flat number, and each delivers the parcel to a different door.

So the author started fuzzing, which means trying many variations of an input quickly to see which one behaves differently, until a way to bypass the filter was found:

Text
https://aa.altervista.org/?client_id=altervista&response_type=code&redirect_uri=http://google.it/http://it.altervista.org/

Line by line:

  • https://aa.altervista.org/ is the login service, the same one as before.
  • client_id=altervista and response_type=code are unchanged: same application, same kind of answer.
  • redirect_uri=http://google.it/http://it.altervista.org/ is the crafted value. It contains the allowed text it.altervista.org, and the address that comes first is http://google.it/. The rest, http://it.altervista.org/, looks like a path on google.it to a browser.

It redirects as follows:

We can steal access token From the original on medium.com

We can steal access token

So, if we put our malicious server address there instead of google.it, we can steal the access token and then log in with it:

This is the same forum login URL as in the legitimate flow. The do parameter is the base64-encoded forum address, and authorization_code is the pass captured from the victim's redirect. The attacker uses this URL with the captured pass to log in as the victim.

Logging in with another person’s account From the original on medium.com

Logging in with another person's account

Epilogue

The author immediately reported the discovery to Altervista via the appropriate form, and they fixed it almost instantly. As a reward, they added the author's name to their thanks list:

Thanks list screenshot From the original on medium.com

Thanks list screenshot

Timeline

  • 02 January 2018: Started looking for vulnerabilities on Altervista.org
  • 03 January 2018: Discovered the vulnerability and sent a PoC to their Security Team
  • 04 January 2018: Patch went online and the author's name was added to thanks list

A PoC, or proof of concept, is a small demonstration that shows the problem is real, usually a link or a few steps that reproduce it.

Glossary

  • API: a way for one program to talk to another, like a counter where you hand in a request and get back an answer in a fixed format.
  • authorization_code: a short-lived pass issued by a login service after a user proves who they are, which another application can exchange for access.
  • base64: an encoding that turns arbitrary text into letters, digits and a few symbols so it can travel inside a URL or an email.
  • bug bounty: a programme where a company rewards people who report security problems in its systems.
  • client_id: a parameter that names which application is making a login request.
  • cookie: a small piece of data a website stores in your browser so it can recognise you on the next request.
  • CVSS: a scoring system for the severity of a security flaw.
  • filter: a server-side check that inspects an input and rejects it if it does not look right.
  • fuzzing: trying many variations of an input quickly to find one that behaves unexpectedly.
  • GET parameter: a name=value pair placed after the ? in a URL, sent to the server with the request.
  • host: the part of a URL that names the server, such as forum.it.altervista.org.
  • open redirect: a flaw where a site takes a destination from the URL and sends the user there without properly checking that the destination belongs to the site.
  • parameter: a name=value pair in a URL or request that the server reads to decide what to do.
  • parsing: breaking a string into its parts, such as scheme, host and path in a URL.
  • patch: a change to software that fixes a problem.
  • PoC (proof of concept): a small demonstration that a security problem is real.
  • redirect: an instruction from a server telling the browser to go to a different address.
  • redirect_uri: the parameter that tells a login service where to send the user back after issuing a pass.
  • response_type: a parameter that says what kind of answer the login service should give, such as a code.
  • scheme: the first part of a URL, such as http or https, which says how to talk to the server.
  • single sign-on (SSO): a setup where logging in once lets you use several related sites without typing your password again.
  • subdomain: a name in front of a domain, such as forum in forum.it.altervista.org.
  • token: a piece of data that stands in for your identity or permission, so you do not have to send your password every time.
  • URL: the address of a resource on the web, made of scheme, host, path and optional parameters.
  • userinfo: the optional user:password@ part before the host in a URL, which browsers and servers sometimes interpret differently.
  • vulnerability: a weakness in software that someone can abuse to do something the owner did not intend.
  • write-up: a public description of a security finding, usually explaining how it was found and fixed.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.