From version < 5.4 >
edited by Caleb James DeLisle
on 2010/04/01
To version < 6.1 >
edited by Caleb James DeLisle
on 2010/05/03
Change comment: Merged with dev:Drafts.SecuringXWiki



Page properties
... ... @@ -1,13 +1,12 @@
1 1  {{box cssClass="floatinginfobox" title="**Contents**"}}{{toc/}}{{/box}}
2 2  
3 -It's important you spend some time understanding the different settings you can modify to protected your wiki.
3 += Security related features =
4 +XWiki offers some features for protecting security and some features which have security implications.
4 4  
5 -= Admin password =
6 +== Admin password ==
7 +The default password for the Admin user is admin. Make sure you either change the password or remove that user.
6 6  
7 -Make sure you either change its password or remove that user.
8 -
9 -= Superadmin account =
10 -
9 +== Superadmin account ==
11 11  XWiki provides a superadmin account. It is special, because:
12 12  
13 13  * It is not stored in the database
... ... @@ -18,19 +18,186 @@
18 18  Because it is so powerful, it is not safe to leave it enabled for a long time.
19 19  {{/warning}}
20 20  
21 -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##.
20 +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## .
22 22  
23 23  {{info}}
24 24  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.
25 25  {{/info}}
26 26  
27 -= Cookie Encryption Keys =
26 +== Cookies ==
27 +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.
28 28  
29 -When a user chooses to be remembered when he logs in, a cookie is saved on his machine. The cookie is encrypted so that nobody having access to it 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>>AdminGuide.Installation]] for where it's installed).
29 +=== Cookie Encryption Keys ===
30 +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>>AdminGuide.Installation]] for where it's installed).
31 +It's important you edit the //[[xwiki.cfg>>AdminGuide.Configuration#HSamplexwikiproperties]]// 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:
30 30  
31 -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 decode the username/password. To prevent this change the following 2 configuration parameters:
32 -
33 33  * //xwiki.authentication.validationKey//
34 34  * //xwiki.authentication.encryptionKey//
35 35  
36 +See: [[AdminGuide.Authentication#HAuthenticationparameters]]
37 +
36 36  In future versions we'd like to generate random and host-dependent key pairs at installation time (see the following [[issue>>http://jira.xwiki.org/jira/browse/XWIKI-542]] for details).
39 +
40 +=== Encrypt cookies using IP address ===
41 +Even if the password cannot be extracted from the cookie, the cookies might be stolen See: [[XSS>>#Hcrosssitescripting]] and used as they are.
42 +By setting the //[[xwiki.cfg>>AdminGuide.Configuration#HSamplexwikiproperties]]// parameter ##xwiki.authentication.useip## to true you can block the cookies from being used except by the same ip address which got them.
43 +
44 += Discussion of attack vectors =
45 +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.
46 +
47 +== Server root attacks ==
48 +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.
49 +
50 +=== Likelihood / Known Issues ===
51 +Not a very common attack method.
52 +
53 +=== Mitigation Methods ===
54 +* Run a decent operating system
55 +* Run the Java VM with XWiki under it's own username, only give this user permissions to files needed for the operation of XWiki, make sure this user doesn't have sudo access.
56 +* Don't run extraneous processes on the server
57 +* Run services on non-standard ports (ssh)
58 +* Firewall all ports not explicitly needed
59 +
60 +== Java VM attacks ==
61 +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.
62 +
63 +=== Likelihood / Known Issues ===
64 +* XWiki requires reflection of private fields and variables for the [[component module>>code:Modules.ComponentModule]] 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: http://jira.codehaus.org/browse/GROOVY-1875
65 +** This attack method requires the use of a registered username which has programming permission.
66 +
67 +=== Mitigation Methods ===
68 +* Enable a SecurityManager which peeks at the calling stack and only allows unchecked reflection if called by the component manager.
69 +* Disable Groovy entirely.
70 +* Guard programming rights closely, have a special username just for saving documents which contain approved Groovy scripts.
71 +
72 +== Database Injection attacks ==
73 +Such an attack happens from inside of unsafe scripting and results in unintended information being given up by the database.
74 +
75 +=== Likelihood / Known Issues ===
76 +{{error}}
77 +Versions older than [[Enterprise-2.2.6>>xwiki:Main.ReleaseNotesXWikiEnterprise226]] and [[Enterprise-2.3.0>>xwiki:Main.ReleaseNotesXWikiEnterprise23]] are susceptible to SQL injection through the $xwiki.search and $xwiki.searchDocuments functions. This means that logged in users are able to finish a query with native SQL and run other queries if the database supports stacked queries. See: the [[patch>>attach:XWIKI%2D4755%2DescapeBackslashes.patch]] which was used to fix this issue and the [[security advisory>>http://lists.xwiki.org/pipermail/users/2010-April/020481.html]]
78 +{{/error}}
79 +
80 +* 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.
81 +** This attack method may often be performed without a registered username.
82 +
83 +=== Mitigation Methods ===
84 +* 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.
85 +
86 +{{code language=java}}
87 +{{groovy}}
88 +try {
89 + session = xcontext.getContext().getWiki().getHibernateStore().getSessionFactory().openSession();
90 + session.connection().createStatement().execute("begin transaction; rollback;");
91 + println("Your database supports stacked queries.")
92 +} catch (Exception e) {
93 + println("Your database does not support stacked queries.");
94 +} finally {
95 + try {
96 + session.close()
97 + } catch (Exception e) {}
98 +}
99 +{{/groovy}}
100 +{{/code}}
101 +
102 +* 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.
103 +
104 +* When designing scripts avoid the temptation to concatenate user input into database queries.
105 +
106 +**WRONG:**
107 +
108 +{{code}}
109 +#set($x = $xwiki.searchDocuments("where doc.fullName = '${userContent}'"))
110 +{{/code}}
111 +
112 +If the user enters: {{code}} ' or doc.hidden = 1 or doc.fullName = ' {{/code}}
113 +Your code will create the Hibernate query:
114 +
115 +{{code language=sql}}
116 +where doc.fullName = '' or doc.hidden = 1 or doc.fullName = ''
117 +{{/code}}
118 +
119 +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.
120 +Fortunately Hibernate itself protects against the worst type of injection such as:
121 +
122 +{{code language=sql}}
123 +Embarrassing Mistake'); DROP TABLE xwikidoc;--
124 +{{/code}}
125 +
126 +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.)
127 +
128 +**THE RIGHT WAY:**
129 +
130 +{{code}}
131 +## We are passing a ? in the query and then passing the parameter as a list (Velocity notation for list is [element, element] )
132 +#set($x = $xwiki.searchDocuments("where doc.fullName = ?", [$userContent]))
133 +{{/code}}
134 +
135 +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.
136 +
137 +* Avoid "Privileged API" whenever possible and only use non API when absolutely necessary. If your each of your calls to require you to pass the context as a parameter, your doing it wrong.
138 +
139 +The API for reference:
140 +http://platform.xwiki.org/xwiki/bin/download/DevGuide/API/xwiki-core-2.0.5-javadoc.jar/index.html
141 +
142 +== Cross Site Scripting ==
143 +Cross site scripting or XSS is the least harmful to the server of all attack methods, however it is the most common.
144 +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.
145 +
146 +=== Attack vectors (persistent injection) ===
147 +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.
148 +
149 +1. Persistent injection through XWiki document content by editing the document.
150 +2. Persistent injecting through comments.
151 +
152 +==== Likelihood / Known Issues ====
153 +* XWiki syntax 1.0 does not filter out HTML so script injection is possible
154 +* 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: http://jira.xwiki.org/jira/browse/XWIKI-3953
155 +** This attack method requires the attacker have a registered username (unless anonymous editing or commenting is allowed.)
156 +
157 +==== Mitigation Methods ====
158 +* 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.
159 +
160 +{{code}}
161 +{{html}}
162 +$escapetool.html($userContent)
163 +{{/html}}
164 +{{/code}}
165 +
166 +There are however some methods to minimize the risk:
167 +* 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
168 + syntax 2.0, otherwise they must have edit permission locked down so that only authorized users may edit them.
169 +* 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.
170 +* Set up ObservationManager to scan all page content and object property updates for HTML macro invocation, alert moderator.
171 +
172 +=== Attack vectors (reflective injection) ===
173 +Reflective injection is characterized by convincing a user to click on a specially crafted link which causes a page to generate javascript.
174 +
175 +1. Reflective injection through form fields.
176 +
177 +==== Mitigation Methods ====
178 +Advise admins to use addons such as [[noscript>>https://addons.mozilla.org/en-US/firefox/addon/722]] which will detect reflective injection attacks and warn the user when it suspects foul play, also avoid clicking on suspicious links.
179 +
180 +* when content is loaded from request parameters into a form field, make sure it is escaped using [[$escapetool.html>>http://velocity.apache.org/tools/devel/generic/EscapeTool.html]]
181 +
182 +**WRONG:**
183 +
184 +{{code language=xml}}
185 +<input type=text value="$request.get('name')" />
186 +{{/code}}
187 +
188 +**RIGHT:**
189 +
190 +{{code language=xml}}
191 +<input type=text value="$escapetool.html($request.get('name'))" />
192 +{{/code}}
193 +
194 +== Cross site request forgery (CSRF) ==
195 +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.
196 +
197 +=== Likelihood / Known Issues ===
198 +* 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]]
199 +
200 +=== Mitigation Methods ===
201 +Advise admins to use addons such as [[noscript>>https://addons.mozilla.org/en-US/firefox/addon/722]] which will help prevent automatic form submission by an attack site, also avoid clicking on suspicious links.
202 +
... ... @@ -1,1 +1,1 @@
1 -2010-03-31 10:28:25.136
1 +2010-03-31 10:28:25.0
... ... @@ -1,1 +1,1 @@
1 -2010-04-01 04:52:17.660
1 +2010-04-01 04:52:17.0

Get Connected