Security

Last modified by Simon Urli on 2023/12/26

This page aims at listing the various security aspects an administrator needs to be aware of when dealing with XWiki. For all security decision a developer needs to take when writing scripts and extensions, you should have a look to the security page of the developer guide.

Security Policy

XWiki security policy is detailed here.

Security related features

XWiki offers some features for protecting security and some features which have security implications.

Admin password

If you've used the Standalone/Demo packaging then a defaut administration user is pre-created for you:

  • Username: Admin
  • Password: admin

Note: You could also remove that user but first you need to make sure it's not used as author of any page as it might create issue otherwise (some standard pages require their author to have enough right to be taken into account).

If you've used any other packaging to install XWiki, the Distribution Wizard asks you to create an administration account and you get to choose the username and password.

Superadmin account

XWiki provides a superadmin account. It is special, because:

  • It is not stored in the database
  • It cannot be modified in any way
  • It always has full access, regardless of the rights settings

Because the Superadmin account is so powerful, it is not safe to leave it enabled for a long time.

By default, this account is disabled. To enable it, you have to edit <xwiki-dir>/WEB-INF/xwiki.cfg, uncomment the xwiki.superadminpassword=system line and set a proper password. To disable it, just comment this line. Remember to restart the servlet container after changing xwiki.cfg.

Using this superadmin account is useful when you cannot log in anymore, for example when you forgot your admin user password, if you messed up some rights or if you have deleted your admin user by mistake.

Cookies

XWiki uses several cookies on the user's machines. For example, XWiki identifies users who have already logged in by setting cookies. These can be the target of attacks.

Cookies List

This is the full list of Cookies used by XWiki core (if you install Extensions, they may define their own cookies and you would need to refer to their documentation).

 Cookie nameContentPathDomainMax ageIs Secure?Usage
JSESSIONIDUnique number representing the Session/Web site domainSession duration (30mn by default, can be configured in web.xml)NoSession cookie created by the Servlet Container
ckCsrfTokenUnique number (CSRF Token)/Web site domainSession duration (30mn by default, can be configured in web.xml)YesCreated by CKEditor. The CSRF token can be used to secure the communication between the web browser and the server, i.e. for the file upload feature in the editor. However XWiki doesn't use it as it has its own CSRF token mechanism.
languageCurrent user locale/Not set10 yearsNoRemember the locale used
interfacelanguageThe interface language used for the current user/Not set10 yearsNoRemember the UI language used
visitidRandom alphanumeric value of 32 characters/A value from the comma-separated list from the xwiki.authentication.cookiedomains config parameter, if it matches the server nameDifference between 1 Jan 2030 and current dateNoTo uniquely recognize the user when computing visit stats. Note that the stats feature is deprecated and turned off.
[xwiki.authentication.cookieprefix]usernameThe protected user name (i.e. encrypted using [xwiki.authentication.encryptionKey] if xwiki.authentication.protection is set)[xwiki.authentication.cookiepath] or / if not set[xwiki.authentication.cookiedomains] matching the server name of / if not set or no match[xwiki.authentication.cookielife] (in days) or 15 days if not set, or until browser shutdown if "remember me" is not checkedYes if request is using HTTPSRemember me (if external authentication is used, this cookie may not be used). If xwiki.authentication.cookieprefix is not set, then an empty string is used.
[xwiki.authentication.cookieprefix]passwordThe protected password(i.e. encrypted using [xwiki.authentication.encryptionKey] if xwiki.authentication.protection is set)[xwiki.authentication.cookiepath] or / if not set[xwiki.authentication.cookiedomains] matching the server name of / if not set or no match[xwiki.authentication.cookielife] (in days) or 15 days if not set, or until browser shutdown if "remember me" is not checkedYes if request is using HTTPSRemember me (if external authentication is used, this cookie may not be used). If xwiki.authentication.cookieprefix is not set, then an empty string is used.
[xwiki.authentication.cookieprefix]remembermeTrue if remember me is checked, false otherwise[xwiki.authentication.cookiepath] or / if not set[xwiki.authentication.cookiedomains] matching the server name of / if not set or no match[xwiki.authentication.cookielife] (in days) or 15 days if not set, or until browser shutdown if "remember me" is not checkedYes if request is using HTTPSRemember me (if external authentication is used, this cookie may not be used). If xwiki.authentication.cookieprefix is not set, then an empty string is used.
[xwiki.authentication.cookieprefix]validationMD5 hash based on the protected username, protected password and the IP addres (if xwiki.authentication.useip is set)[xwiki.authentication.cookiepath] or / if not set[xwiki.authentication.cookiedomains] matching the server name of / if not set or no match[xwiki.authentication.cookielife] (in days) or 15 days if not set, or until browser shutdown if "remember me" is not checkedYes if request is using HTTPSRemember me (if external authentication is used, this cookie may not be used). If xwiki.authentication.cookieprefix is not set, then an empty string is used.

Legend help:

  • If "Is Secure?" is true, it means that the cookie is only sent when HTTPS is used.

Cookie Encryption Keys

When a user logs in, three cookies are saved on his machine containing the username, password and a "nothing up my sleeve" hash. The cookies are encrypted so that nobody having access to them can see the username/password. This encryption is done using 2 configuration parameters located in the xwiki.cfg configuration file. This file is located in WEB-INF/ in the XWiki WAR (see the Installation guide for where it's installed).

XWiki <15.9, <15.5.4, <14.10.19 

It's important you edit the xwiki.cfg file to modify the cookie authentication and encryption keys as they use default values when you install XWiki and these predefined values could be used by an attacker to decipher the username and password. To prevent this, change the following 2 configuration parameters:

  • xwiki.authentication.validationKey
  • xwiki.authentication.encryptionKey

See the Authentication parameters section for more details.

Encrypt cookies using IP address

Even if the password cannot be extracted from the cookie, the cookies might be stolen (see XSS) and used as they are. To limit this by default, the cookies are blocked from being used except by the same IP address that was used to create them.

You can disable this by setting the xwiki.cfg parameter xwiki.authentication.useip to false.

Override version information

By default, the exact XWiki version is shown in the footer of every page. This is not harmful by itself, but can provide useful information to the attacker, who can use known vulnerabilities against this version.

You can change the version string shown in the footer using the Administration Application. Click on the Presentation icon and change the version string in the Version field. Please note that with this solution, the version can still be find through a REST request on the wiki.

If you want to be sure the version is definitely not leaked somewhere else, you can replace the file WEB-INF/version.properties by your own version with the following content: version=your version string here.

Antivirus

There's an Antivirus Application developed by a sponsoring company offering scanning for antivirus when attaching files to wiki pages.

Discussion of attack vectors

Perfect security is generally considered impossible. With simple static HTML servers we can have near perfect security but those are not very useful. This document discusses different threat models and how to fortify against each. These attacks are grouped by type of access gained if successful. More dangerous attacks are near the top yet the most common attacks are less dangerous (and easier to perform) and will be seen at the bottom.

Server root attacks

This attack is characterized by assent of power in the operating system and is largely beyond the scope of this document as it is the responsibility of the operating system to prevent users ascending power.

Likelihood / Known Issues

Not a very common attack method.

Mitigation Methods

  • Run a decent operating system
  • Run the Java VM with XWiki under its own username, only give this user permissions to files needed for the operation of XWiki and make sure this user doesn't have sudo access
  • Don't run extraneous processes on the server
  • Run services on non-standard ports (ssh)
  • Firewall all ports not explicitly needed

Java VM attacks

This attack is characterized by the attacker running arbitrary code on Java and perhaps using Java level security flaws to execute native code thus gaining access in the user level of the Java VM process.

Likelihood / Known Issues

  • XWiki requires reflection of private fields and variables for the component module This means that jsr223 scripts such as Groovy and Python are able to read and write any field or variable in the system which may lead to execution of native code via Java Native Access. Virtual wikis are not insulated against this attack method and as such virtual wiki administrators cannot be given programming permission (note that there is another reason for not giving wiki admin programming rights in a farm, it is because you may access any document without rights being checked, even in another wiki). This flaw could lead to dumping of connected databases, however user passwords are SHA-512 hashed (see this issue for more details.
    • This attack method requires the use of a registered username which has programming rights

Mitigation Methods

  • Enable a SecurityManager which peeks at the calling stack and only allows unchecked reflection if called by the component manager
  • Disable Groovy entirely
  • Guard programming rights closely, have a special username just for saving documents which contain approved Groovy scripts

Database Injection attacks

Such an attack happens from inside of unsafe scripting and results in unintended information being given up by the database.

Likelihood / Known Issues

  • XWiki uses Hibernate as a database controller so some of the injection methods are mitigated. XWiki gives you the capability to create safe scripts and unsafe scripts.
    • This attack method may often be performed without a registered username.

Mitigation Methods

  • You can use this groovy snippet to test your database to see if it supports stacked queries. If your database does not support stacked queries, injection in a SELECT query can only lead to additional arbitrary SELECT queries:
    {{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}}
  • Configure your database to log or if possible disable comment syntax  -- /* */ and # . Comments are not used by Hibernate and are central to most of the more dangerous SQL injection.
  • When designing scripts avoid the temptation to concatenate user input into database queries

WRONG:

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

If the user enters: ' or doc.hidden = 1 or doc.fullName = '  your code will create the Hibernate query: where doc.fullName = '' or doc.hidden = 1 or doc.fullName = ''.

This may not be a horrible outcome but it is not what you wanted and others surely can invent far more dangerous injections than this.
Fortunately Hibernate itself protects against the worst type of injection such as:

Embarrassing Mistake'); DROP TABLE xwikidoc;--

This is because it does not allow multiple commands in one call and does not allow the -- comment syntax (can be bypassed in some versions; see above).

RIGHT:

## We are passing a ? in the query and then passing the parameter as a list (Velocity notation for list is [element, element] )
#set($x = $xwiki.searchDocuments("where doc.fullName = ?", [$userContent]))

Your code will now instruct Hibernate to name the userContent parameter and pass it to the database separately from the query. The above injection trick will not work.

  • Avoid "Privileged API" whenever possible and only use non API when absolutely necessary. If each of your calls requires you to pass the context as a parameter, you're doing it wrong.

For more information check the XWiki API Reference.

Cross Site Scripting

Cross site scripting or XSS is the least harmful to the server of all attack methods, however it is the most common.
XSS can lead to users altering documents which they didn't want to or having their authentication cookies copied. XSS can also lead to exploitation of web browsers and plugins such as pdf or ActiveX. Such exploits often install malware.

Attack vectors (persistent injection)

Persistent injection is characterized by saving content in the system which when loaded by the unwitting user, executes as javascript in their browser. This is the more dangerous variety because it sits in a page waiting for a victim.

  1. Persistent injection through XWiki document content by editing the document.
    2. Persistent injecting through comments.

Likelihood / Known Issues

  • XWiki syntax 1.0 does not filter out HTML so script injection is possible
  • XWiki syntax 2.0 contains html macro which when invoked allows injection of raw html and script. There is still no safe way to disable this (see this issue for more information.
    • This attack method requires the attacker to have a registered username (unless anonymous editing or commenting is allowed).

Mitigation Methods

  • The only way to be sure that script cannot be injected in content (xwiki/1.0 or xwiki/2.0) is to make that content completely passive as follows:
    {{html}}
    $escapetool.html($userContent)
    {{/html}}
    There are however some methods to minimize the risk:
  • Disable creation of syntax 1.0 pages. NOTE: Pages which are already written in syntax 1.0 can still be altered and should be updated to syntax 2.0, otherwise they must have edit permission locked down so that only authorized users may edit them.
  • Force unauthorized users to post through a script which escapes {{ (double squigly brackets) because there is currently no way to prevent injection of html macro for unauthorized users.
  • Set up ObservationManager to scan all page content and object property updates for HTML macro invocation and alert a moderator.

Attack vectors (reflective injection)

Reflective injection is characterized by convincing a user to click on a specially crafted link which causes a page to generate javascript.

  1. Reflective injection through form fields.

Mitigation Methods

Advise admins to use addons such as noscript which will detect reflective injection attacks and warn the user when it suspects foul play and also avoid clicking on suspicious links.

  • when content is loaded from request parameters into a form field, make sure it is escaped using EscapeTool

WRONG:

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

RIGHT:

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

Cross site request forgery (CSRF)

The basis of this attack is that a foreign website can craft a malicious link or form which points to the save action in your system and when clicked by a logged in user will cause the user to save the page.

Likelihood / Known Issues

Currently there is no system implemented to prevent form submission from external sites. See discussion in mailing list about implementing secret tokens.

Mitigation Methods

Advise admins to use addons such as noscript which will help prevent automatic form submission by an attack site and also avoid clicking on suspicious links.

Advisory Notices

Here's a list of sites offering security advisory notices about XWiki:

Tags:
   

Get Connected