Wiki source code of Security

Version 21.4 by Ecaterina Moraru (Valica) on 2017/09/06

Hide last authors
Ricardo Rodríguez 9.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Silvia Macovei 5.1 4
Caleb James DeLisle 6.1 5 = Security related features =
Ricardo Rodríguez 9.1 6
Caleb James DeLisle 6.1 7 XWiki offers some features for protecting security and some features which have security implications.
vmassol 1.2 8
Caleb James DeLisle 6.1 9 == Admin password ==
Ricardo Rodríguez 9.1 10
Vincent Massol 13.2 11 The default password for the ##Admin## user is ##admin##. Make sure you change the password.
Vincent Massol 2.1 12
Thomas Mortagne 13.1 13 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).
14
Caleb James DeLisle 6.1 15 == Superadmin account ==
Ricardo Rodríguez 9.1 16
Vincent Massol 13.2 17 XWiki provides a ##superadmin## account. It is special, because:
Thomas Mortagne 13.1 18
Sergiu Dumitriu 1.3 19 * It is not stored in the database
20 * It cannot be modified in any way
21 * It always has full access, regardless of the rights settings
22
Silvia Macovei 5.1 23 {{warning}}
Manuel Smeria 12.5 24 Because the Superadmin account is so powerful, it is not safe to leave it enabled for a long time.
Silvia Macovei 5.1 25 {{/warning}}
Sergiu Dumitriu 1.5 26
Manuel Smeria 12.5 27 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 28
Silvia Macovei 5.1 29 {{info}}
30 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.
31 {{/info}}
Vincent Massol 1.4 32
Caleb James DeLisle 6.1 33 == Cookies ==
Ricardo Rodríguez 9.1 34
Caleb James DeLisle 6.1 35 By default XWiki (as with most of the web) identifies users who have already logged in by setting cookies. These can be the target of attacks.
vmassol 1.1 36
Caleb James DeLisle 6.1 37 === Cookie Encryption Keys ===
Ricardo Rodríguez 9.1 38
Ecaterina Moraru (Valica) 21.4 39 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>>Documentation.AdminGuide.Installation]] for where it's installed).
40 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 41
Silvia Macovei 5.1 42 * //xwiki.authentication.validationKey//
43 * //xwiki.authentication.encryptionKey//
vmassol 1.1 44
Ecaterina Moraru (Valica) 21.4 45 See the [[Authentication parameters section>>Documentation.AdminGuide.Authentication#HAuthenticationparameters]] for more details.
Caleb James DeLisle 6.1 46
Thomas Mortagne 17.1 47 In future versions we'd like to generate random and host-dependent key pairs at installation time (see the following [[issue>>https://jira.xwiki.org/browse/XWIKI-542]] for details).
Caleb James DeLisle 6.1 48
49 === Encrypt cookies using IP address ===
Ricardo Rodríguez 9.1 50
Ecaterina Moraru (Valica) 21.4 51 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.
52 By setting the //[[xwiki.cfg>>Documentation.AdminGuide.Configuration#HSamplexwiki.cfg]]// parameter ##xwiki.authentication.useip## to true you can block the cookies from being used except by the same IP address which got them.
Caleb James DeLisle 6.1 53
Alex Busenius 7.1 54 == Override version information ==
55
Ecaterina Moraru (Valica) 20.1 56 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.
Alex Busenius 7.1 57
Manuel Smeria 12.5 58 You can change the version string shown in the footer using the [[Administration Application>>extensions:Extension.Administration Application]]. Click on the ##Presentaton## icon and change the version string in the //Version// field.
Alex Busenius 7.1 59
Manuel Smeria 12.5 60 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}}.
Alex Busenius 7.1 61
Caleb James DeLisle 6.1 62 = Discussion of attack vectors =
Ricardo Rodríguez 9.1 63
Caleb James DeLisle 6.1 64 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.
65
66 == Server root attacks ==
Ricardo Rodríguez 9.1 67
Caleb James DeLisle 6.1 68 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.
69
70 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 71
Caleb James DeLisle 6.1 72 Not a very common attack method.
73
74 === Mitigation Methods ===
Ricardo Rodríguez 9.1 75
Caleb James DeLisle 6.1 76 * Run a decent operating system
Manuel Smeria 12.5 77 * 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 78 * Don't run extraneous processes on the server
79 * Run services on non-standard ports (ssh)
80 * Firewall all ports not explicitly needed
81
82 == Java VM attacks ==
Ricardo Rodríguez 9.1 83
Caleb James DeLisle 6.1 84 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.
85
86 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 87
Manuel Smeria 12.5 88 * 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.
89 ** This attack method requires the use of a registered username which has programming rights
Caleb James DeLisle 6.1 90
91 === Mitigation Methods ===
Ricardo Rodríguez 9.1 92
Manuel Smeria 12.5 93 * Enable a SecurityManager which peeks at the calling stack and only allows unchecked reflection if called by the component manager
94 * Disable Groovy entirely
95 * Guard programming rights closely, have a special username just for saving documents which contain approved Groovy scripts
Caleb James DeLisle 6.1 96
97 == Database Injection attacks ==
Ricardo Rodríguez 9.1 98
Caleb James DeLisle 6.1 99 Such an attack happens from inside of unsafe scripting and results in unintended information being given up by the database.
100
101 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 102
Caleb James DeLisle 6.1 103 * 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.
104 ** This attack method may often be performed without a registered username.
105
106 === Mitigation Methods ===
Ricardo Rodríguez 9.1 107
Thomas Mortagne 13.1 108 * 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 109 {{code language="java"}}
Caleb James DeLisle 6.1 110 {{groovy}}
111 try {
112 session = xcontext.getContext().getWiki().getHibernateStore().getSessionFactory().openSession();
113 session.connection().createStatement().execute("begin transaction; rollback;");
114 println("Your database supports stacked queries.")
115 } catch (Exception e) {
116 println("Your database does not support stacked queries.");
117 } finally {
118 try {
119 session.close()
120 } catch (Exception e) {}
121 }
122 {{/groovy}}
123 {{/code}}
Manuel Smeria 12.5 124 )))
125 * 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.
126 * When designing scripts avoid the temptation to concatenate user input into database queries
Caleb James DeLisle 6.1 127
128 **WRONG:**
129
130 {{code}}
131 #set($x = $xwiki.searchDocuments("where doc.fullName = '${userContent}'"))
132 {{/code}}
133
Manuel Smeria 12.5 134 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 135
136 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.
137 Fortunately Hibernate itself protects against the worst type of injection such as:
138
Ricardo Rodríguez 9.1 139 {{code language="sql"}}
Caleb James DeLisle 6.1 140 Embarrassing Mistake'); DROP TABLE xwikidoc;--
141 {{/code}}
142
Manuel Smeria 12.5 143 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 144
Manuel Smeria 12.5 145 **RIGHT:**
Caleb James DeLisle 6.1 146
147 {{code}}
148 ## We are passing a ? in the query and then passing the parameter as a list (Velocity notation for list is [element, element] )
149 #set($x = $xwiki.searchDocuments("where doc.fullName = ?", [$userContent]))
150 {{/code}}
151
152 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.
153
Manuel Smeria 12.5 154 * 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 155
Vincent Massol 21.3 156 For more information check the [[XWiki API Reference>>platform:DevGuide.API]].
Caleb James DeLisle 6.1 157
158 == Cross Site Scripting ==
Ricardo Rodríguez 9.1 159
Caleb James DeLisle 6.1 160 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 161 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 162
163 === Attack vectors (persistent injection) ===
Ricardo Rodríguez 9.1 164
Caleb James DeLisle 6.1 165 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.
166
167 1. Persistent injection through XWiki document content by editing the document.
168 2. Persistent injecting through comments.
169
170 ==== Likelihood / Known Issues ====
Ricardo Rodríguez 9.1 171
Caleb James DeLisle 6.1 172 * XWiki syntax 1.0 does not filter out HTML so script injection is possible
Thomas Mortagne 17.1 173 * 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 174 ** This attack method requires the attacker to have a registered username (unless anonymous editing or commenting is allowed).
Caleb James DeLisle 6.1 175
176 ==== Mitigation Methods ====
Ricardo Rodríguez 9.1 177
Thomas Mortagne 13.1 178 * 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 179 {{code}}
180 {{html}}
181 $escapetool.html($userContent)
182 {{/html}}
183 {{/code}}
Thomas Mortagne 13.1 184 )))There are however some methods to minimize the risk:
Manuel Smeria 12.5 185 * 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.
186 * 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.
187 * 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 188
Caleb James DeLisle 6.1 189 === Attack vectors (reflective injection) ===
Ricardo Rodríguez 9.1 190
Caleb James DeLisle 6.1 191 Reflective injection is characterized by convincing a user to click on a specially crafted link which causes a page to generate javascript.
192
193 1. Reflective injection through form fields.
194
195 ==== Mitigation Methods ====
Ricardo Rodríguez 9.1 196
Manuel Smeria 12.5 197 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 198
Manuel Smeria 12.5 199 * 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 200
201 **WRONG:**
202
Ricardo Rodríguez 9.1 203 {{code language="xml"}}
Caleb James DeLisle 6.1 204 <input type=text value="$request.get('name')" />
205 {{/code}}
206
207 **RIGHT:**
208
Ricardo Rodríguez 9.1 209 {{code language="xml"}}
Caleb James DeLisle 6.1 210 <input type=text value="$escapetool.html($request.get('name'))" />
211 {{/code}}
212
213 == Cross site request forgery (CSRF) ==
Ricardo Rodríguez 9.1 214
Caleb James DeLisle 6.1 215 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.
216
217 === Likelihood / Known Issues ===
Ricardo Rodríguez 9.1 218
Manuel Smeria 12.5 219 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 220
221 === Mitigation Methods ===
Ricardo Rodríguez 9.1 222
Manuel Smeria 12.5 223 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 224
Vincent Massol 19.2 225 = Advisory Notices =
Vincent Massol 19.1 226
227 Here's a list of sites offering security advisory notices about XWiki:
Ecaterina Moraru (Valica) 20.1 228
Vincent Massol 19.1 229 * [[nvd.nist.gov>>https://nvd.nist.gov/vuln/search/results?adv_search=false&form_type=basic&results_type=overview&search_type=all&query=xwiki]]
230 * [[www.cvedetails.com>>http://www.cvedetails.com/product/6856/Xwiki-Xwiki.html?vendor_id=3885]]
231 * [[vuldb.com>>https://vuldb.com/fr/?search]] (need to search for ##xwiki##)
232 * [[vulners.com>>https://vulners.com/search?query=xwiki]]

Get Connected