Attack Vectors

Last modified by Eleni Cojocariu on 2026/12/04 14:27

The threats an XWiki instance faces, from the server's operating system down to a reader's browser, and what reduces each one.

Explanation

Perfect security is out of reach. A server that only returns static HTML comes close, and makes a useless wiki. What an administrator can do is know which attacks an XWiki instance actually faces and what reduces each one.

The threats below are grouped by the access a successful attack gains, the widest first. That order is the reverse of how often they happen: reaching the whole server is rare and hard, reaching a single reader's browser is frequent and cheap.

The Server's Operating System

An attacker who gains root owns the machine and every wiki on it. Stopping a user from ascending privilege is the operating system's job rather than XWiki's, so there is nothing to configure in the wiki for this one. It is also the least common of these attacks. What reduces it is hardening the host: automatic patching, an account of its own for the Java process, and a firewall that answers on nothing else.

The Java Virtual Machine

XWiki runs scripts, and a script running with Programming right has the full run of the Java Virtual Machine: it can reach any part of the running system, and through it native code. Whoever can save such a script gains everything the JVM's own user has.

That takes a registered account holding Programming right, which is what makes this right the one to guard. Granting it on the main wiki to serve a subwiki is a mistake: a subwiki is not insulated from this attack, and Programming right also reads any document in any wiki without a rights check. The rights themselves are described in Right Types.

Stored user passwords are hashed, with argon2 by default, so reaching the database does not hand over credentials in clear.

What reduces it:

  • Grant Programming right to as few accounts as possible, and never to a subwiki administrator.
  • Keep a dedicated account for saving the pages that carry approved scripts, so that an everyday administrator account cannot be used to introduce one.
  • Disable Groovy altogether where no page needs it.

Database Injection

Database injection comes from inside a script that builds a query out of user input, and makes the database give up data the script never meant to expose. Unlike the two above it often needs no registered account at all: a public search form is enough when the script behind it is unsafe.

XWiki queries through Hibernate, which blocks the worst of it. Hibernate refuses several commands in one call and does not accept the -- comment syntax, so the classic Embarrassing Mistake'); DROP TABLE xwikidoc;-- does not work. Some versions can be made to accept it, so this is a floor and not a guarantee.

What reduces it:

  • Configure the database to log its comment syntaxes, or to reject them outright. There are three: --, /* */ and the number sign. Hibernate itself never uses comments, and they are central to the more dangerous injections.
  • Keep scripts from concatenating user input into queries, as the last section describes.

Whether an injected SELECT can be followed by a second statement depends on the database. Where stacked queries are unsupported, an injection into a SELECT can only produce more SELECTs. This script reports which case you are in:

{{groovy}}
try {
  session = xcontext.getContext().getWiki().getHibernateStore().getSessionFactory().openSession();
  session.connection().createStatement().execute("begin transaction; rollback;");
  println("Your database supports stacked queries.")
} catch (Exception e) {
  println("Your database does not support stacked queries.");
} finally {
  try {
    session.close()
  } catch (Exception e) {}
}
{{/groovy}}

It needs Programming right, and it reports the unsupported case for any SQL error, so a database that spells the transaction keyword differently answers "does not support" for the wrong reason.

Cross-Site Scripting

Cross-site scripting does the least damage to the server and happens the most often. It runs the attacker's JavaScript in a reader's browser, which is enough to change pages as that reader, to copy their authentication cookies, or to hand their browser an exploit.

It takes two shapes. Persistent injection saves the script in the wiki, in page content or in a comment, and waits for a reader to open it; it is the more dangerous of the two because it sits there. Reflective injection crafts a link that makes a page generate the script as it renders, and needs the reader to follow it.

Saving content that runs as script takes an account that may edit or comment, so the exposure follows the wiki's rights: a wiki open to anonymous editing or commenting is open to anonymous persistent injection. Wiki Access Configurations describes the choice.

What reduces it:

  • Keep editing and commenting rights deliberate rather than inherited by accident.
  • Rely on the rights the content itself declares. The HTML macro cleans its content by default, and turning that cleaning off requires Script right; a scripting macro requires Script right and can require Programming right. A page states what its content needs through required rights, which is also how an administrator sees which pages hold privileged content.
  • Escape the user input that reaches a page, as the last section describes.

The first two do nothing against reflective injection, which saves nothing in the wiki and needs only a reader who follows a crafted link: escaping is what closes it.

Cross-Site Request Forgery

A foreign site can build a link or a form aimed at an action on your wiki. A reader who is logged in and follows it performs that action without meaning to, saving or deleting a page under their own name.

XWiki defends against this with its own CSRF token: an action that changes something is refused unless it carries a token tied to the user making it. The CSRF module implements it, and Configure the CSRF Tokens covers how long a token lives, what a cluster has to share and what a custom form has to carry.

What to Require of Script Authors

Most of what is left is in the hands of whoever writes scripts on the wiki. An administrator who grants Script right is trusting these habits, so they are worth stating.

Never concatenate user input into a query. Written this way, the input becomes part of the query:

#set($x = $xwiki.searchDocuments("where doc.fullName = '${userContent}'"))

A reader who enters ' or doc.hidden = 1 or doc.fullName = ' turns it into where doc.fullName = '' or doc.hidden = 1 or doc.fullName = '', and far worse is available. Passing the value as a parameter instead keeps it out of the query:

#set($x = $xwiki.searchDocuments("where doc.fullName = ?", [$userContent]))

Escape user content before it is displayed. Content that has to be shown rather than interpreted is made inert by Velocity's EscapeTool:

{{html}}$escapetool.html($userContent){{/html}}

The same applies to anything read from the request into a form field. Written this way, the value is interpreted:

<input type="text" value="$request.get('name')" />

Escaped, it is not:

<input type="text" value="$escapetool.html($request.get('name'))" />

Prefer the public API. A script that has to pass the context into every call is reaching past the API it should be using, and past the rights checks that come with it. The XWiki API Reference lists what is public.

The developer security documentation covers the rest of what a script author needs.

FAQ

Does XWiki protect against these attacks out of the box?

Against some of them. Hibernate limits database injection, the CSRF token is on by default, and content declares the rights it needs. The operating system and the discipline of script authors are yours.

Why is Programming right missing from a subwiki's rights editor?

It is a farm-level right and can only be set on the main wiki. A subwiki administrator cannot grant it, deliberately.

Related

Get Connected