Skip to content
RCE Write-up Intermediate

What was the issue?

The Widget Connector macro in Confluence Server allowed an attacker to supply a _template parameter that was used to render HTML, enabling path traversal and remote code execution. An attacker could exploit this to read files or execute code on vulnerable Confluence servers.

Vignesh C Follow

Published on medium.com

Long story short, I have created my Hackerone/Bugcrowd profiles a way back in 2016 but I have never reported a bug there. I have never thought of doing a bug hunting but this vulnerability has made me do it.

Vignesh C, on medium.com

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

Context

The target in this write-up is Atlassian Confluence Server (and Data Center), specifically the Widget Connector macro. The macro exists so that authors can embed online videos, slideshows, photostreams and similar content directly into a page by supplying a URL. The report lists the sites the macro was designed to support: YouTube, Vimeo, MySpace Video, Flickr, Twitter, Slide Rocket, Google Calendar and others.

The vulnerability described is CVE-2019-3396, summarised in the report as SSTI and RCE in Confluence Server via Widget Connector: an attacker can exploit it to achieve path traversal and remote code execution on systems running a vulnerable version of Confluence Server or Data Center. The advisory referenced was released on 2019-04-17.

The author notes at the start that the profiles on HackerOne and Bugcrowd were created back in 2016 but no bug had ever been reported there, and that this vulnerability is what prompted the first report.

Setup

The only tool named is Burp, used to capture a request against the vulnerable Confluence page and send it to Repeater. The captured request can be a GET or a POST. No specific Confluence version, account role or configuration is given beyond the requirement that the instance runs a vulnerable version.

Two preconditions are stated for the request to work:

  1. The path of the request may need to be changed.
  2. A Referer: header may need to be added. The author says this was mandatorily expected in most of the cases tested, and that omitting it can produce the error XSRF check failed.

Finding it

The report explains the mechanism rather than describing a discovery process. The Widget Connector defines a set of renderers, one per supported content source. The example given is FriendFeedRenderer:

Java
public class FriendFeedRenderer implements WidgetRenderer{...public String getEmbeddedHtml(String url, Map<String, String> params) {params.put("_template", "com/atlassian/confluence/extra/widgetconnector/templates/simplejscript.vm");return this.velocityRenderService.render(getEmbedUrl(url), params);}}

The renderer puts a _template entry into the parameter map, pointing at a Velocity template inside the application, and then passes the URL and the parameters to the velocity render service. Because the parameters come from the request, an attacker can supply their own _template value, and the backend will use those params to render.

From the original on medium.com

Exploitation

The author calls this the simplest PoC, and it is a single modified request.

Step 1: Capture the request

Capture the vulnerable Confluence page request in Burp, GET or POST, and send it to Repeater.

Step 2: Modify and send

Change the captured request as shown below and parse it. Remember the note about the path and the Referer: header, without which the server may answer XSRF check failed.

HTTP
POST /rest/tinymce/1/macro/preview HTTP/1.1Host: confluence.victim.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X; rv:52.0) Gecko/20100101 Firefox/52.0Accept: application/json, text/javascript, */*; q=0.01Accept-Language: en-US,en-GB;q=0.8,ach;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: https://confluence.victim.com/Content-Type: application/json;charset=UTF-8X-Requested-With: XMLHttpRequestUpgrade-Insecure-Requests: 1Content-Length: 163Connection: close{"contentId":"65601","macro":{"name":"widget","params":{"url":"https://www.youtube.com/watch?v=2aK8hy50fS4","width":"1000","height":"1000","_template":"../web.xml"},"body":""}}

The important parts:

  • The request goes to the macro preview endpoint, /rest/tinymce/1/macro/preview, as a JSON POST.
  • Referer is set to the Confluence host, which satisfies the XSRF check described above.
  • The body names the widget macro and supplies its parameters: a YouTube url, a width and a height, and a _template value of ../web.xml.
  • The _template parameter is the injection point: it overrides the template path the renderer would normally set itself, and ../web.xml is a relative path traversal payload.
From the original on medium.com

Step 3: Escalate

The report says that instead of ../web.xml you can try file:///etc/passwd (path traversal payloads) or remote code execution to increase the severity of the finding. No further request or payload for the RCE case is shown; the report links to an external repository for it.

Root cause

The renderer writes _template into the parameter map before rendering, and an attacker can supply their own _template value which the backend uses to render. That lets an attacker choose the template used for rendering, which the report links to path traversal and remote code execution.

The report does not analyse why the request-level defences were insufficient beyond the XSRF note; the Referer header is what gets the request past that check.

Impact

On a vulnerable Confluence Server or Data Center instance, the advisory quoted says an attacker can achieve path traversal and remote code execution. The author used the same issue against many internet-facing instances found through search engines: about 100 Confluence links from one dork, of which 21 were vulnerable, and around 300+ links from further dorks, of which 50+ companies were vulnerable. None of the bounty programme sites were targeted. The author reports receiving recognition from various companies in dollars and Euros, and swags from others.

Fix

In the fixed versions, doSanitizeParameters is called before rendering the HTML, and it removes _template from the parameters. In fixed versions, doSanitizeParameters is called before rendering the HTML and removes _template from the parameters.

Variants to test

  • Other renderers on the same macro. The report shows FriendFeedRenderer as the example; any renderer that merges request parameters into the map passed to the template engine is worth checking.

  • Path traversal targets. Swap ../web.xml for other relative paths or for file:///etc/passwd.

  • Template injection for RCE. The report points to an external PoC for this rather than showing a payload; a positive result is code execution on the Confluence host.

  • Finding instances at scale. The author used Google dorks to locate exposed Confluence installations, starting with intitle:dashboard-confluence and then these keywords:

    The observation behind the wider set is that a Confluence instance does not have to live at confluence.companyname.com.

How to get other companies who are affected by this? From the original on medium.com
Or watch on YouTube

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

What happened, in plain words

A security researcher had signed up to two bug bounty platforms, HackerOne and Bugcrowd, back in 2016, but had never actually reported a bug on either of them. This particular vulnerability is what finally made him do it.

The bug is in a product called Confluence Server, made by Atlassian. Confluence is a piece of software that companies install on their own servers. The bug is catalogued as CVE-2019-3396, and the researcher describes it as SSTI and RCE in Confluence Server via Widget Connector. Those three acronyms are explained as we go, but in short: the report describes path traversal and remote code execution on vulnerable systems.

The affected feature is the Widget Connector macro. A macro, in Confluence, is a small building block you drop into a page to add something extra, like a table of contents or an embedded video. The Widget Connector macro lets a page author paste a link to an online video, slideshow or photo stream and have it appear embedded in the page. The report lists the sites the macro was built to support: YouTube, Vimeo, MySpace Video, Flickr, Twitter, Slide Rocket, Google Calendar and others.

The advisory quoted in the report was released on 2019-04-17.

How the Widget Connector goes wrong

When you paste a link into the macro, Confluence has to turn that link into a piece of embeddable HTML. It does this with a small helper called a renderer, one per supported site. The report shows one of them, FriendFeedRenderer, as the example of the vulnerable pattern:

Java
public class FriendFeedRenderer implements WidgetRenderer{...public String getEmbeddedHtml(String url, Map<String, String> params) {params.put("_template", "com/atlassian/confluence/extra/widgetconnector/templates/simplejscript.vm");return this.velocityRenderService.render(getEmbedUrl(url), params);}}

Line by line, in plain words:

  • public class FriendFeedRenderer implements WidgetRenderer declares a class, that is, a named block of code, which promises to behave like a widget renderer. Think of it as a worker whose job is "take a link, produce embed HTML".
  • public String getEmbeddedHtml(String url, Map<String, String> params) is the worker's one task. It receives the link (url) and a Map<String, String> params. A map is a lookup table of key and value pairs, like a form where each field has a label and a filled-in answer. Here both labels and answers are text.
  • params.put("_template", "com/atlassian/confluence/extra/widgetconnector/templates/simplejscript.vm"); writes one entry into that table: the key _template gets the value of a file path inside the application. A .vm file is a Velocity template. A template is a text file with placeholders in it; a template engine, here Velocity, fills in the placeholders and produces the final HTML. The everyday comparison is a mail merge: the letter is written once with blanks, and the software fills the blanks per recipient.
  • return this.velocityRenderService.render(getEmbedUrl(url), params); hands the link and the whole table to the template engine and returns whatever HTML comes back.

The problem is the _template entry: an attacker can provide their own _template value, and the backend will use the params to render. So an attacker can send their own _template value, and the backend will use the attacker's parameters to render. In mail-merge terms: the attacker gets to choose which letter template the office uses, not just what goes in the blanks.

From the original on medium.com

The image sits right after the code and the sentence about attacker-supplied _template values, illustrating the vulnerable rendering path described there.

Reproducing it

The researcher calls this the simplest proof of concept you could dream of. A proof of concept, or PoC, is the smallest concrete demonstration that a bug is real: not a description, but something you can run and watch work.

Step 1: capture the request

Open the vulnerable Confluence page in a browser, with a tool called Burp sitting between the browser and the server. Burp is a proxy: it is a program that all your web traffic passes through, so it can record every request your browser sends and every response that comes back. Capture the request the page makes, whether it is a GET or a POST, and send it to Burp's Repeater. Repeater is the part of Burp that lets you edit a captured request by hand and send it again as many times as you like, watching the response each time. This step exists because you need a real, working request to start from; editing a request the application already accepts is far easier than writing one from scratch.

Step 2: modify and send

Change the captured request as shown below, then send it. Two things may need adjusting first. The path of the request may need to be changed, and a Referer: header may need to be added. A header is a line of extra information attached to a request, separate from the body; the Referer header tells the server which page the request came from. The researcher says this header was mandatorily expected in most of the cases he tested, and that leaving it out can produce the error XSRF check failed. XSRF, also written CSRF, stands for cross-site request forgery: a class of attack where a malicious site quietly makes your browser send a request to another site using your logged-in session. Applications defend against it by checking that a request really came from their own pages, and the Referer header is one of the things they check. That is why the header matters here: without it, the server may throw an error, XSRF check failed.

HTTP
POST /rest/tinymce/1/macro/preview HTTP/1.1Host: confluence.victim.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X; rv:52.0) Gecko/20100101 Firefox/52.0Accept: application/json, text/javascript, */*; q=0.01Accept-Language: en-US,en-GB;q=0.8,ach;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: https://confluence.victim.com/Content-Type: application/json;charset=UTF-8X-Requested-With: XMLHttpRequestUpgrade-Insecure-Requests: 1Content-Length: 163Connection: close{"contentId":"65601","macro":{"name":"widget","params":{"url":"https://www.youtube.com/watch?v=2aK8hy50fS4","width":"1000","height":"1000","_template":"../web.xml"},"body":""}}

Line by line:

  • POST /rest/tinymce/1/macro/preview HTTP/1.1 is the first line of the request. POST is the method, meaning "I am sending data". The path /rest/tinymce/1/macro/preview is the address on the server being called. An API is simply a set of addresses like this that a program offers so other programs can talk to it; here it is the endpoint the page editor uses to preview a macro before you publish it. HTTP/1.1 is the version of the web protocol being spoken.
  • Host: confluence.victim.com names the server being contacted. victim.com is a placeholder for the real company's domain.
  • User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X; rv:52.0) Gecko/20100101 Firefox/52.0 identifies the browser. Servers often behave differently for different browsers, so keeping a normal browser string avoids standing out.
  • Accept: application/json, text/javascript, */*; q=0.01 says which response formats the client understands. JSON is a plain-text way of writing structured data, using curly braces, quoted names and colons, much like the body below.
  • Accept-Language: en-US,en-GB;q=0.8,ach;q=0.5,en;q=0.3 lists preferred languages, with q values ranking them.
  • Accept-Encoding: gzip, deflate says the client can accept compressed responses.
  • Referer: https://confluence.victim.com/ is the header discussed above: it claims the request came from the Confluence site itself, which is what gets it past the XSRF check.
  • Content-Type: application/json;charset=UTF-8 announces that the body is JSON text.
  • X-Requested-With: XMLHttpRequest is a header browsers add to background requests made by page scripts. Its presence makes the request look like ordinary in-page activity.
  • Upgrade-Insecure-Requests: 1 is a standard browser header asking the server to prefer secure connections.
  • Content-Length: 163 states the size of the body in bytes, so the server knows where the body ends.
  • Connection: close asks the server to close the connection after replying.
  • The body, {"contentId":"65601","macro":{"name":"widget","params":{...},"body":""}}, is the JSON. contentId identifies the page being edited. macro.name is widget, so the Widget Connector is the macro being previewed. macro.params is the parameter table that ends up in the renderer. Inside it, url is an ordinary YouTube link, width and height are 1000, and _template is ../web.xml.
  • ../web.xml is the injection point. In a file path, .. means "go up one folder". So ../web.xml means: step up one level from the current folder and read web.xml. This is called path traversal: using relative path pieces to walk out of the directory you were meant to stay in. The everyday comparison is a filing cabinet where every drawer is supposed to hold one folder, and someone writes "../payroll" on a slip so the clerk fetches from the drawer next door.
From the original on medium.com

Both images follow the request and the note about swapping in other payloads, showing the request being sent and the result coming back.

Step 3: escalate

The report says that instead of ../web.xml you can try file:///etc/passwd, which is another path traversal payload, or remote code execution, to increase the severity of the finding. file:///etc/passwd is a URL that means "read this file from the server's own disk"; on Linux systems /etc/passwd is a well-known file listing user accounts. Remote code execution, RCE, means getting the server to run commands you supply, which is the most serious outcome a web bug can have. The report does not show a request or payload for the RCE case; it links to an external repository instead.

Why it works

The renderer writes _template into the parameter table before rendering, and an attacker can supply their own _template value which the backend uses to render. That lets an attacker choose the template used for rendering, which the report links to path traversal and remote code execution. Server-side template injection, SSTI, means user input is treated as part of the template itself rather than as data to be inserted into it. The everyday comparison is a mail merge where the recipient's name is not just typed into a blank, but the recipient is allowed to rewrite the letter. Because templates can contain expressions the engine evaluates, SSTI is the route to remote code execution.

The report does not analyse why the request-level defences were insufficient beyond the XSRF note; the Referer header is what gets the request past that check.

Impact

On a vulnerable Confluence Server or Data Center instance, the advisory quoted says an attacker can achieve path traversal and remote code execution. The researcher then applied the same issue to many internet-facing instances found through search engines. A search engine can be asked to return pages matching patterns in their titles, addresses or text; such a crafted query is called a Google dork. From one dork he found about 100 Confluence links, of which 21 were vulnerable. From further dorks he found around 300+ links, of which 50+ companies were vulnerable. He did not target any of the bounty programme sites. He reports receiving recognition from various companies in dollars and Euros, and swags from others.

The fix

In the fixed versions, doSanitizeParameters is called before the HTML is rendered, and it removes _template from the parameters. To sanitise means to clean input by removing or neutralising the dangerous parts. In fixed versions, doSanitizeParameters is called before rendering the HTML and removes _template from the parameters.

Variants to test

  • Other renderers on the same macro. The report shows FriendFeedRenderer as the example; any renderer that merges request parameters into the table passed to the template engine is worth checking.

  • Path traversal targets. Swap ../web.xml for other relative paths or for file:///etc/passwd.

  • Template injection for RCE. The report points to an external PoC for this rather than showing a payload; a positive result is code execution on the Confluence host.

  • Finding instances at scale. The researcher used Google dorks to locate exposed Confluence installations, starting with intitle:dashboard-confluence and then these keywords:

    The observation behind the wider set is that a Confluence instance does not have to live at confluence.companyname.com.

How to get other companies who are affected by this? From the original on medium.com

The image follows the "Now What?" heading, where the report asks how to find other companies affected by the same issue.

Or watch on YouTube
From the original on medium.com

Glossary

  • API: a set of addresses a program offers so other programs can talk to it.
  • Burp: a proxy tool that sits between browser and server, recording and letting you edit web requests.
  • CVE: a public catalogue number for a known security vulnerability, here CVE-2019-3396.
  • Confluence Server / Data Center: Atlassian's wiki software, installed and run on a company's own servers.
  • CSRF / XSRF: cross-site request forgery, an attack that makes your browser send a request to another site using your logged-in session; applications check for it and may answer XSRF check failed.
  • GET / POST: the two common request methods; GET asks for something, POST sends data.
  • Google dork: a search query crafted to find pages matching specific patterns, such as a product name in the title or a path in the address.
  • Header: a line of extra information attached to a request or response, such as Referer or Content-Type.
  • JSON: a plain-text format for structured data using braces, quoted names and colons.
  • Macro: a small building block added to a Confluence page, such as an embedded video.
  • Map: a lookup table of key and value pairs.
  • Path traversal: using relative path pieces such as .. to reach files outside the intended folder.
  • PoC (proof of concept): the smallest concrete demonstration that a bug is real.
  • RCE (remote code execution): getting a server to run commands supplied by an attacker.
  • Referer: a request header saying which page the request came from.
  • Renderer: the helper that turns a pasted link into embeddable HTML.
  • Repeater: the part of Burp that lets you edit and resend a captured request repeatedly.
  • Sanitise: clean input by removing or neutralising dangerous parts.
  • SSTI (server-side template injection): user input treated as part of a template rather than as data, letting the attacker influence what the template engine evaluates.
  • Template / template engine: a text file with placeholders, and the software that fills them in to produce final output, like a mail merge.
  • Velocity: the template engine Confluence uses here; its template files end in .vm.
  • Widget Connector: the Confluence macro that embeds videos, slideshows and photo streams from a pasted URL.
  • XSRF check failed: the error a server returns when a request fails its cross-site request forgery check, for example because the Referer header is missing.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.