Wiki source code of Security

Last modified by Eleni Cojocariu on 2026/08/10 23:36

Hide last authors
Eleni Cojocariu 38.1 1
Simon Urli 34.1 2 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>>Documentation.DevGuide.Security.WebHome]].
3
Ricardo Rodríguez 9.1 4 {{box cssClass="floatinginfobox" title="**Contents**"}}
5 {{toc/}}
6 {{/box}}
Silvia Macovei 5.1 7
Simon Urli 26.1 8 = Security Policy =
9
10 XWiki security policy [[is detailed here>>dev:Community.SecurityPolicy.WebHome]].
11
Caleb James DeLisle 6.1 12 = Security related features =
Ricardo Rodríguez 9.1 13
Caleb James DeLisle 6.1 14 XWiki offers some features for protecting security and some features which have security implications.
vmassol 1.2 15
Caleb James DeLisle 6.1 16 == Admin password ==
Ricardo Rodríguez 9.1 17
Eleni Cojocariu 37.5 18 If you've [[installed a Standalone (Demo) Distribution>>documentation.xs.admin.installation.methods.install-standalone-demo-distribution.WebHome]], then a default administration user is pre-created for you:
Thomas Mortagne 29.2 19
Vincent Massol 26.2 20 * Username: ##Admin##
21 * Password: ##admin##
Vincent Massol 2.1 22
Vincent Massol 26.2 23 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).
Thomas Mortagne 13.1 24
Vincent Massol 26.2 25 If you've used any other packaging to install XWiki, the [[Distribution Wizard>>Documentation.UserGuide.Features.DistributionWizard]] asks you to create an administration account and you get to choose the username and password.
26
Caleb James DeLisle 6.1 27 == Superadmin account ==
Ricardo Rodríguez 9.1 28
Vincent Massol 13.2 29 XWiki provides a ##superadmin## account. It is special, because:
Thomas Mortagne 13.1 30
Sergiu Dumitriu 1.3 31 * It is not stored in the database
32 * It cannot be modified in any way
33 * It always has full access, regardless of the rights settings
34
Silvia Macovei 5.1 35 {{warning}}
Manuel Smeria 12.5 36 Because the Superadmin account is so powerful, it is not safe to leave it enabled for a long time.
Silvia Macovei 5.1 37 {{/warning}}
Sergiu Dumitriu 1.5 38
Manuel Smeria 12.5 39 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##.
Sergiu Dumitriu 1.3 40
Silvia Macovei 5.1 41 {{info}}
42 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.
43 {{/info}}
Vincent Massol 1.4 44
Caleb James DeLisle 6.1 45 == Cookies ==
Ricardo Rodríguez 9.1 46
Vincent Massol 29.1 47 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.
vmassol 1.1 48
Vincent Massol 29.1 49 === Cookies List ===
50
51 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).
52
Vincent Massol 36.1 53 |= Cookie name|=Content|=Path|=Domain|=Max age|=Is Secure?|=Http Only?|=Usage
54 |##JSESSIONID##|Unique number representing the Session|##/##|Web site domain|Session duration (30mn by default, can be configured in ##web.xml##)|Yes if request is using HTTPS (can depend on Servlet Container)|Yes if request is using HTTPS (can depend on Servlet Container)|Session cookie created by the Servlet Container
Vincent Massol 36.5 55 |##ckCsrfToken##|Unique number (CSRF Token)|##/##|Web site domain|Session duration (30mn by default, can be configured in ##web.xml##)|Yes|Yes|Created 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.
Vincent Massol 36.2 56 |##language##|Current user locale|##/##|Not set|10 years|No|No|Remember the locale used
Vincent Massol 36.3 57 |##interfacelanguage##|The interface language used for the current user|##/##|Not set|10 years|No|No|Remember the UI language used
Vincent Massol 36.4 58 |##visitid##|Random alphanumeric value of 32 characters|##/##|A value from the comma-separated list from the ##xwiki.authentication.cookiedomains## config parameter, if it matches the server name|Difference between 1 Jan 2030 and current date|No|No|To uniquely recognize the user when computing visit stats. Note that the stats feature is deprecated and turned off.
Vincent Massol 36.1 59 |##[xwiki.authentication.cookieprefix]username##|The 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 checked|Yes if request is using HTTPS|Yes|Remember 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.
60 |##[xwiki.authentication.cookieprefix]password##|The 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 checked|Yes if request is using HTTPS|Yes|Remember 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.
61 |##[xwiki.authentication.cookieprefix]rememberme##|True 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 checked|Yes if request is using HTTPS|Yes|Remember 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.
62 |##[xwiki.authentication.cookieprefix]validation##|MD5 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 checked|Yes if request is using HTTPS|Yes|Remember 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.
Vincent Massol 29.1 63
64 Legend help:
Thomas Mortagne 29.2 65
Vincent Massol 29.1 66 * If "Is Secure?" is true, it means that the cookie is only sent when HTTPS is used.
67
Vincent Massol 37.1 68 === Session Cookie Security ===
69
70 In general, Servlet Containers create the ##JSESSIONID## cookie as ##secure## only when the connexion is made on HTTPS (i.e. on an HTTP connexion the cookie is NOT ##secure## and is thus sent client-side). Some Servlet Containers always set ##httpOnly## but some don't.
71
72 You can configure your Servlet Container to never send the ##JSESSIONID## cookie, at the level of the Servlet Container's configuration files (e.g. in Tomcat's ##web.xml## file). You could also edit XWiki's ##web.xml## file and use:
73
74 {{code language="xml"}}
75 <session-config>
76 <cookie-config>
77 <http-only>true</http-only>
78 <secure>true</secure>
79 </cookie-config>
80 </session-config>
81 {{/code}}
82
Thomas Mortagne 29.2 83 === Cookie Encryption Keys ===
Ricardo Rodríguez 9.1 84
Eleni Cojocariu 37.4 85 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 WAR guide>>Documentation.AdminGuide.Installation.InstallationWAR.WebHome]] for where it's installed).
Thomas Mortagne 29.2 86
87 {{version before="15.9, 15.5.4, 14.10.19"}}
Ecaterina Moraru (Valica) 21.4 88 It's important you edit the //[[xwiki.cfg>>Documentation.AdminGuide.Configuration#HSamplexwiki.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:
Thomas Mortagne 13.1 89
Silvia Macovei 5.1 90 * //xwiki.authentication.validationKey//
91 * //xwiki.authentication.encryptionKey//
Thomas Mortagne 29.2 92 {{/version}}
vmassol 1.1 93
Eleni Cojocariu 38.1 94 See the [[Authentication Parameters>>documentation.xs.admin.authentication.parameters.WebHome]] page for more details.
Caleb James DeLisle 6.1 95
96 === Encrypt cookies using IP address ===
Ricardo Rodríguez 9.1 97
Vincent Massol 23.2 98 Even if the password cannot be extracted from the cookie, the cookies might be stolen (see [[XSS>>Documentation.AdminGuide.Security#HCrossSiteScripting]]) 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.
Caleb James DeLisle 6.1 99
Vincent Massol 23.2 100 You can disable this by setting the [[##xwiki.cfg##>>Documentation.AdminGuide.Configuration#HSamplexwiki.cfg]] parameter ##xwiki.authentication.useip## to false.
101
nickless 7.1 102 == Override version information ==
103
Ecaterina Moraru (Valica) 20.1 104 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.
nickless 7.1 105
Simon Urli 23.3 106 You can change the version string shown in the footer using the [[Administration Application>>extensions:Extension.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.
nickless 7.1 107
Manuel Smeria 12.5 108 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: {{code}}version=your version string here{{/code}}.
nickless 7.1 109
Vincent Massol 33.1 110 = Antivirus =
111
112 There's an [[Antivirus Application>>https://store.xwiki.com/xwiki/bin/view/Extension/AntivirusApplication/]] developed by a sponsoring company offering scanning for antivirus when attaching files to wiki pages.
113
Caleb James DeLisle 6.1 114 = Discussion of attack vectors =
Ricardo Rodríguez 9.1 115
Caleb James DeLisle 6.1 116 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.
117
118 == Server root attacks ==
Ricardo Rodríguez 9.1 119
Caleb James DeLisle 6.1 120 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.
121
122 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 123
Caleb James DeLisle 6.1 124 Not a very common attack method.
125
126 === Mitigation Methods ===
Ricardo Rodríguez 9.1 127
Caleb James DeLisle 6.1 128 * Run a decent operating system
Manuel Smeria 12.5 129 * 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
Caleb James DeLisle 6.1 130 * Don't run extraneous processes on the server
131 * Run services on non-standard ports (ssh)
132 * Firewall all ports not explicitly needed
133
134 == Java VM attacks ==
Ricardo Rodríguez 9.1 135
Caleb James DeLisle 6.1 136 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.
137
138 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 139
Manuel Smeria 12.5 140 * XWiki requires reflection of private fields and variables for the [[component module>>extensions:Extension.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>>http://jira.codehaus.org/browse/GROOVY-1875]] for more details.
141 ** This attack method requires the use of a registered username which has programming rights
Caleb James DeLisle 6.1 142
143 === Mitigation Methods ===
Ricardo Rodríguez 9.1 144
Manuel Smeria 12.5 145 * Enable a SecurityManager which peeks at the calling stack and only allows unchecked reflection if called by the component manager
146 * Disable Groovy entirely
147 * Guard programming rights closely, have a special username just for saving documents which contain approved Groovy scripts
Caleb James DeLisle 6.1 148
149 == Database Injection attacks ==
Ricardo Rodríguez 9.1 150
Caleb James DeLisle 6.1 151 Such an attack happens from inside of unsafe scripting and results in unintended information being given up by the database.
152
153 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 154
Caleb James DeLisle 6.1 155 * 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.
156 ** This attack method may often be performed without a registered username.
157
158 === Mitigation Methods ===
Ricardo Rodríguez 9.1 159
Thomas Mortagne 13.1 160 * You can use this groovy snippet to test your database to see if it supports [[stacked queries>>http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/#StackingQueries]]. If your database does not support stacked queries, injection in a SELECT query can only lead to additional arbitrary SELECT queries:(((
Ricardo Rodríguez 9.1 161 {{code language="java"}}
Caleb James DeLisle 6.1 162 {{groovy}}
163 try {
164 session = xcontext.getContext().getWiki().getHibernateStore().getSessionFactory().openSession();
165 session.connection().createStatement().execute("begin transaction; rollback;");
166 println("Your database supports stacked queries.")
167 } catch (Exception e) {
168 println("Your database does not support stacked queries.");
169 } finally {
170 try {
171 session.close()
172 } catch (Exception e) {}
173 }
174 {{/groovy}}
175 {{/code}}
Manuel Smeria 12.5 176 )))
177 * Configure your database to log or if possible disable comment syntax {{code language="none"}} -- /* */ and # {{/code}}. Comments are not used by Hibernate and are central to most of the more dangerous SQL injection.
178 * When designing scripts avoid the temptation to concatenate user input into database queries
Caleb James DeLisle 6.1 179
180 **WRONG:**
181
182 {{code}}
183 #set($x = $xwiki.searchDocuments("where doc.fullName = '${userContent}'"))
184 {{/code}}
185
Manuel Smeria 12.5 186 If the user enters: {{code}} ' or doc.hidden = 1 or doc.fullName = ' {{/code}} your code will create the Hibernate query: {{code language="sql"}}where doc.fullName = '' or doc.hidden = 1 or doc.fullName = ''{{/code}}.
Caleb James DeLisle 6.1 187
188 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.
189 Fortunately Hibernate itself protects against the worst type of injection such as:
190
Ricardo Rodríguez 9.1 191 {{code language="sql"}}
Caleb James DeLisle 6.1 192 Embarrassing Mistake'); DROP TABLE xwikidoc;--
193 {{/code}}
194
Manuel Smeria 12.5 195 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).
Caleb James DeLisle 6.1 196
Manuel Smeria 12.5 197 **RIGHT:**
Caleb James DeLisle 6.1 198
199 {{code}}
200 ## We are passing a ? in the query and then passing the parameter as a list (Velocity notation for list is [element, element] )
201 #set($x = $xwiki.searchDocuments("where doc.fullName = ?", [$userContent]))
202 {{/code}}
203
204 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.
205
Manuel Smeria 12.5 206 * 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.
Caleb James DeLisle 6.1 207
Thomas Mortagne 27.1 208 For more information check the [[XWiki API Reference>>Documentation.DevGuide.API]].
Caleb James DeLisle 6.1 209
210 == Cross Site Scripting ==
Ricardo Rodríguez 9.1 211
Caleb James DeLisle 6.1 212 Cross site scripting or XSS is the least harmful to the server of all attack methods, however it is the most common.
Manuel Smeria 12.5 213 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.
Caleb James DeLisle 6.1 214
215 === Attack vectors (persistent injection) ===
Ricardo Rodríguez 9.1 216
Caleb James DeLisle 6.1 217 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.
218
219 1. Persistent injection through XWiki document content by editing the document.
220 2. Persistent injecting through comments.
221
222 ==== Likelihood / Known Issues ====
Ricardo Rodríguez 9.1 223
Caleb James DeLisle 6.1 224 * XWiki syntax 1.0 does not filter out HTML so script injection is possible
Thomas Mortagne 17.1 225 * 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>>https://jira.xwiki.org/browse/XWIKI-3953]] for more information.
Manuel Smeria 12.5 226 ** This attack method requires the attacker to have a registered username (unless anonymous editing or commenting is allowed).
Caleb James DeLisle 6.1 227
228 ==== Mitigation Methods ====
Ricardo Rodríguez 9.1 229
Thomas Mortagne 13.1 230 * 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:(((
Caleb James DeLisle 6.1 231 {{code}}
232 {{html}}
233 $escapetool.html($userContent)
234 {{/html}}
235 {{/code}}
Thomas Mortagne 13.1 236 )))There are however some methods to minimize the risk:
Manuel Smeria 12.5 237 * 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.
238 * 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.
239 * Set up ObservationManager to scan all page content and object property updates for HTML macro invocation and alert a moderator.
Ricardo Rodríguez 9.1 240
Caleb James DeLisle 6.1 241 === Attack vectors (reflective injection) ===
Ricardo Rodríguez 9.1 242
Caleb James DeLisle 6.1 243 Reflective injection is characterized by convincing a user to click on a specially crafted link which causes a page to generate javascript.
244
245 1. Reflective injection through form fields.
246
247 ==== Mitigation Methods ====
Ricardo Rodríguez 9.1 248
Manuel Smeria 12.5 249 Advise admins to use addons such as [[noscript>>https://addons.mozilla.org/en-US/firefox/addon/noscript/]] which will detect reflective injection attacks and warn the user when it suspects foul play and also avoid clicking on suspicious links.
Caleb James DeLisle 6.1 250
Manuel Smeria 12.5 251 * when content is loaded from request parameters into a form field, make sure it is escaped using [[EscapeTool>>http://velocity.apache.org/tools/devel/generic/EscapeTool.html]]
Caleb James DeLisle 6.1 252
253 **WRONG:**
254
Ricardo Rodríguez 9.1 255 {{code language="xml"}}
Caleb James DeLisle 6.1 256 <input type=text value="$request.get('name')" />
257 {{/code}}
258
259 **RIGHT:**
260
Ricardo Rodríguez 9.1 261 {{code language="xml"}}
Caleb James DeLisle 6.1 262 <input type=text value="$escapetool.html($request.get('name'))" />
263 {{/code}}
264
265 == Cross site request forgery (CSRF) ==
Ricardo Rodríguez 9.1 266
Caleb James DeLisle 6.1 267 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.
268
269 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 270
Manuel Smeria 12.5 271 Currently there is no system implemented to prevent form submission from external sites. See discussion in mailing list about implementing [[secret tokens>>http://lists.xwiki.org/pipermail/devs/2010-March/017727.html]].
Caleb James DeLisle 6.1 272
273 === Mitigation Methods ===
Ricardo Rodríguez 9.1 274
Manuel Smeria 12.5 275 Advise admins to use addons such as [[noscript>>https://addons.mozilla.org/en-US/firefox/addon/noscript/]] which will help prevent automatic form submission by an attack site and also avoid clicking on suspicious links.
Vincent Massol 19.1 276
Vincent Massol 19.2 277 = Advisory Notices =
Vincent Massol 19.1 278
279 Here's a list of sites offering security advisory notices about XWiki:
Ecaterina Moraru (Valica) 20.1 280
slauriere 35.1 281 * [[nvd.nist.gov>>https://nvd.nist.gov/vuln/search/results?form_type=Basic&results_type=overview&query=xwiki&search_type=all&isCpeNameSearch=false]]
Vincent Massol 19.1 282 * [[www.cvedetails.com>>http://www.cvedetails.com/product/6856/Xwiki-Xwiki.html?vendor_id=3885]]
283 * [[vuldb.com>>https://vuldb.com/fr/?search]] (need to search for ##xwiki##)
284 * [[vulners.com>>https://vulners.com/search?query=xwiki]]

Get Connected