| 1 |
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 5 |
<title>Web Service Security</title> |
| 6 |
<link href="axis.css" rel=stylesheet type=text/css> |
| 7 |
<!-- |
| 8 |
authors: |
| 9 |
Steve Loughran |
| 10 |
--> |
| 11 |
</head> |
| 12 |
<body> |
| 13 |
|
| 14 |
<center> |
| 15 |
<h1> |
| 16 |
<img SRC="images/axis.jpg" height=96 width=176></h1></center> |
| 17 |
|
| 18 |
<h1>Web Service Security</h1> |
| 19 |
|
| 20 |
|
| 21 |
<h2>The challenge of server security</h2> |
| 22 |
A standard attack on a web site is usually that of identifying and |
| 23 |
abusing badly written CGI scripts. Anything that gives read access to |
| 24 |
the file system is a security hole, letting people get at the code |
| 25 |
behind the site, often including database passwords and other sensitive |
| 26 |
data, plus of course there are the core parts of the underlying |
| 27 |
platform, which may contain important information: passwords, credit |
| 28 |
card lists, user-private information, and the like. Unauthorized access |
| 29 |
to this data can be embarrasing and expensive. |
| 30 |
|
| 31 |
<p> |
| 32 |
|
| 33 |
Having write access to the system leads to even greater abuses; defaced |
| 34 |
web sites may be created, spoof endpoints written to capture caller's |
| 35 |
data, or the database directly manipulated. |
| 36 |
|
| 37 |
<h2>Is SOAP fundamentally insecure?</h2> |
| 38 |
|
| 39 |
Some people, such as <a |
| 40 |
href="http://www.counterpane.com/crypto-gram-0006.html"> |
| 41 |
Bruce Schneier<a>, have claimed that SOAP is a |
| 42 |
security disaster in the making, because of its ability to punch |
| 43 |
through firewalls. However, because in SOAP over HTTP the client can |
| 44 |
only make SOAP calls, not receive them, SOAP is no more insecure than |
| 45 |
any other application which POSTs XML files to a web server. The clients |
| 46 |
are safe unless the server (or its DNS address) have been subverted; the |
| 47 |
server is vulnerable, and does need to be secured. |
| 48 |
|
| 49 |
<p> |
| 50 |
Similarly, |
| 51 |
<a href="http://webservices.xml.com/pub/a/ws/2003/03/04/security.html"> |
| 52 |
Bilal Siddiqui |
| 53 |
</a> makes the claim that <i> |
| 54 |
|
| 55 |
SOAP cannot distinguish between sensitive and non-sensitive web services |
| 56 |
and cannot perform user authentication, authorization, and access |
| 57 |
control.</i> |
| 58 |
|
| 59 |
<p> |
| 60 |
|
| 61 |
|
| 62 |
Again, this is another example of excess panic, perhaps combined with a |
| 63 |
lack of knowledge of how SOAP servers are implemented. |
| 64 |
You do not need to follow this author's advice and have |
| 65 |
separate SOAP servers for every level of sensitivity, or XML and SOAP |
| 66 |
aware firewalls, any more than you need separate Web Servers for |
| 67 |
different users, or require HTTP aware routers to restrict parts of a |
| 68 |
web server to different IP addresses. |
| 69 |
|
| 70 |
|
| 71 |
<h2>Common Attack Types</h2> |
| 72 |
|
| 73 |
<ul> |
| 74 |
<li>Denial of Service to a server |
| 75 |
<li>Interception and manipulation of messages |
| 76 |
<li>Forged client requests |
| 77 |
<li>Forged server responses |
| 78 |
<li>attempts to read the server file system/database |
| 79 |
<li>Attempts to write to the server file system/database |
| 80 |
</ul> |
| 81 |
|
| 82 |
The most significant security risk comes from the fact that you are |
| 83 |
writing code to provide functionality to calling programs. If that |
| 84 |
functionality is offered to the wrong people, or if the code you wrote |
| 85 |
creates a security hole, "unexpected functionality", then you have a |
| 86 |
problem. |
| 87 |
<p> |
| 88 |
|
| 89 |
There is a large body of literature which covers securing web sites, such |
| 90 |
as the |
| 91 |
<A href="http://www.owasp.org/">Open Web Application Security Project</A> |
| 92 |
Top Ten List of vulnerabilities, and their Guide to Building Secure Web |
| 93 |
Applications. |
| 94 |
|
| 95 |
<h3>Special XML attacks</h3> |
| 96 |
XML messages have a few intrinsic weakness, that Web Service creators |
| 97 |
should know about. None of these problems are unique to SOAP; anyone |
| 98 |
processing incoming XML needs to know and resist these. |
| 99 |
|
| 100 |
<ol> |
| 101 |
<li>Large XML Documents<br> |
| 102 |
Have a client post an XML doc of |
| 103 |
extreme length/depth |
| 104 |
<foo><foo><foo>...</foo></foo></foo> |
| 105 |
This does bad things to DOM parsers and memory consumption on the |
| 106 |
server: a DoS attack. The issue here is that the costs of handling a |
| 107 |
large XML document are much greater than the cost of generating one. |
| 108 |
|
| 109 |
<li>Entity Expansion Attacks.<be> |
| 110 |
If an XML doc header declares some |
| 111 |
recursive entity declarations, and the file refers to them, then bad |
| 112 |
things happen. Axis became immune to this between versions 1.0 and 1.1. |
| 113 |
|
| 114 |
<li>Entities referring to the filesystem. <br> |
| 115 |
Here you declare an entity referring to a local file, then expand it. |
| 116 |
Result: you may be able to probe for files, perhaps even get a copy of |
| 117 |
it in the error response. As Axis does not support entities any more, it |
| 118 |
resists this. If your code has any way of resolving URLs from incoming |
| 119 |
messages, you may recreate this problem. |
| 120 |
</ol> |
| 121 |
|
| 122 |
The other thing to know about XML is that string matching is not |
| 123 |
enough to be sure that the content is safe, because of the many ways to |
| 124 |
reformat the same XML. |
| 125 |
|
| 126 |
<h2>Authenticating the caller</h2> |
| 127 |
|
| 128 |
The new Web Service security proposals offer to authenticate your |
| 129 |
callers to your end point, and vice-versa. Axis does not yet implement |
| 130 |
these, but we do support XML signatures via |
| 131 |
<a href="http://xml.apache.org/security/index.html"> |
| 132 |
a sister project.</a> |
| 133 |
|
| 134 |
<p> |
| 135 |
|
| 136 |
The other approach is to validate at the transport level, using HTTPS. |
| 137 |
Configuring your web server to support https is definitely beyond the |
| 138 |
scope of Axis documentation: consult your server docs. To support https |
| 139 |
in the Axis client, you need to ensure the client has https support in |
| 140 |
the runtime. This is automatic for Java1.4+; older versions need to add |
| 141 |
JSSE support through Sun or an alternate provider. |
| 142 |
|
| 143 |
<p> |
| 144 |
|
| 145 |
Once you have HTTPS working at both ends you need to have the client |
| 146 |
trust the server certificate -usually automatic for those signed by central |
| 147 |
certification authorities, a manual process for home rolled |
| 148 |
certificates. |
| 149 |
|
| 150 |
<p> |
| 151 |
|
| 152 |
Clients can authenticate themselves with client certificates, or HTTP |
| 153 |
basic authentication. The latter is too weak to be trustable on a |
| 154 |
non-encrypted channel, but works over HTTPS. The <tt>MessageContext</tt> |
| 155 |
class will be configured with the username and password of the sender |
| 156 |
when SOAP messages are posted to the endpoint; use the appropriate |
| 157 |
getters to see these values. Note that Axis does not <i>yet</i> |
| 158 |
integrate with the servlet API authentication stuff. Although the forms |
| 159 |
authentication is literally off-axis when it comes to SOAP calls, the |
| 160 |
UserPrincipal notion and integration with server configuration gives |
| 161 |
some incentive for integration. (this is a hint to developers out there) |
| 162 |
|
| 163 |
<p> |
| 164 |
|
| 165 |
Axis does not (yet) support HTTP1.1 Digest Authentication; if it does get added |
| 166 |
it will be via the |
| 167 |
<a href="http://jakarta.apache.org/commons/httpclient/">HttpClient</a> |
| 168 |
libraries. |
| 169 |
|
| 170 |
|
| 171 |
<h2>Securing your Services</h2> |
| 172 |
|
| 173 |
One of the key security holes in any Web Service is the code you write |
| 174 |
yourself. It won't have as many eyes examining it as the Axis source |
| 175 |
gets, deadlines get in the way of rigorous testing, and a complex web |
| 176 |
service will bind to the valued items: private data, databases, other |
| 177 |
servers, etc, that you want to defend against. |
| 178 |
|
| 179 |
<p> |
| 180 |
|
| 181 |
The key to this is not to trust the caller: their identity, their IP |
| 182 |
address and most of all, their data. Here are some attacks to consider. |
| 183 |
|
| 184 |
<h3>XML attacks</h3> |
| 185 |
|
| 186 |
We listed these attacks earlier. If your service takes XML from an |
| 187 |
attachment, or in a base-64 encoded string, parsing it as a standalone |
| 188 |
document, then you are exposed to all these attacks. Also watch out for |
| 189 |
standard XML syntaxes that integrate xlink or other ways of describing |
| 190 |
URLs to fetch -such as SVG. You need to ensure the renderer only fetches |
| 191 |
approved URLs. |
| 192 |
|
| 193 |
<h3>Session Theft</h3> |
| 194 |
|
| 195 |
Axis uses a good random number generator to generate session IDs, but |
| 196 |
someone listening to an unencrypted conversation could hijack a session |
| 197 |
and send in new messages. Recording sender info, such as the originating |
| 198 |
IP address helps, though beware of proxied systems (e.g. AOL) that may |
| 199 |
change the apparent origin of calls mid-session. |
| 200 |
|
| 201 |
<h3>DOS attacks via load-intensive operations</h3> |
| 202 |
|
| 203 |
Any request that takes time to process is a DOS attack target, as it |
| 204 |
ties up the CPUs. Authenticate before long requests, and consider |
| 205 |
watchdog threads to track really long execution times. If any bug causes |
| 206 |
a request to spin forever. |
| 207 |
|
| 208 |
<h3>Parameter Attacks</h3> |
| 209 |
|
| 210 |
If any parameter in the XML is fed straight into a database query, or |
| 211 |
some other routine that depends on valid data, then that data |
| 212 |
<i>must</i> be validated. Otherwise someone malicious could send a |
| 213 |
database update request, or some other string which lets a malicious |
| 214 |
user manipulate the system. This could even be as simple as changing |
| 215 |
their UserID in a request from that they set up in the session. Database |
| 216 |
attacks come from any situation where a parameter is inserted into an |
| 217 |
SQL query; the insertion of a semicolon ";" often permits the caller to |
| 218 |
append a whole new SQL command to the end of the first, and have it |
| 219 |
executed with the rights of the Web Service. |
| 220 |
|
| 221 |
<p> |
| 222 |
|
| 223 |
The key to defending against malicious parameters is to validate all |
| 224 |
data. Only accept a string containing only the characters/regular |
| 225 |
expression expected, and check its length. Better yet apply any other |
| 226 |
higher level checks 'userID==session.userID' that you can. Prepared |
| 227 |
Statements are the followon way of defending against SQL injection, as the |
| 228 |
JDBC runtime handles escaping of things. Don't try and build SQL strings |
| 229 |
by hand; it is a recipe for security holes. |
| 230 |
|
| 231 |
<p> |
| 232 |
|
| 233 |
Note that this would seem to argue strongly against mapping Session EJB |
| 234 |
objects to SOAP Endpoints. This is not the case. The Session bean must |
| 235 |
merely assume that all incoming data is untrusted, and so validate it |
| 236 |
all before processing further. This is exactly the kind of task a |
| 237 |
<a href="http://martinfowler.com/eaaCatalog/serviceLayer.html"> |
| 238 |
<i>Service Layer</i></a> should be doing. |
| 239 |
|
| 240 |
<h3>Cross Site Scripting</h3> |
| 241 |
|
| 242 |
In theory, a pure Web Service should be immune to XSS attacks, at least |
| 243 |
those that rely on having uploaded script displayed in an HTML Web Page |
| 244 |
server-side, script that is executed when the client views it. But the |
| 245 |
moment one takes Axis and integrates with one's own webapplication, any |
| 246 |
loopholes in the rest of the webapp expose this exact problem. We don't |
| 247 |
think Axis itself is vulnerable, because although it may include |
| 248 |
supplied data in a SOAPFault, this is displayed as XML, not HTML. |
| 249 |
Clients which don't distinguish the two could be an issue, as could |
| 250 |
anything we missed, especially in GET handling. |
| 251 |
|
| 252 |
<h2>Securing Axis</h2> |
| 253 |
|
| 254 |
A core philosophy is 'defend in depth', with monitoring for trouble. |
| 255 |
|
| 256 |
<h3>Disguise</h3> |
| 257 |
|
| 258 |
One tactic here is to hide the fact that you are running Axis...look at |
| 259 |
all the headers that we send back to describe the service, and if any |
| 260 |
identify Axis, edit that constant in the source. While obscurity on its |
| 261 |
own is inadequate; it can slow down attacks or make you seem less |
| 262 |
vulnerable to known holes. |
| 263 |
|
| 264 |
<h3>Cut down the build</h3> |
| 265 |
|
| 266 |
Rebuild Axis without bits of it you don't need. This is a very paranoid |
| 267 |
solution, but keeps the number of potential attack points down. One area |
| 268 |
to consider is the 'instant SOAP service' feature of JWS pages. They, |
| 269 |
along with JSP pages, provide anyone who can get text files onto the web |
| 270 |
application with the ability to run arbitrary Java code. |
| 271 |
|
| 272 |
<h3>Rename things</h3> |
| 273 |
|
| 274 |
The AxisServlet, the AdminService, even happyaxis.jsp are all in well |
| 275 |
known locations under the webapp, which is called 'axis' by default. |
| 276 |
Rename all of these, by editing web.xml for the servlet, |
| 277 |
server-config.wsdd for the AdminService; the others are just JSP and WAR |
| 278 |
files you can rename. You may not need the AdminService once you have |
| 279 |
generated the server config on a development machine. |
| 280 |
|
| 281 |
<h3>Stop AxisServlet listing services</h3> |
| 282 |
|
| 283 |
To do this, set the Axis global configuration property |
| 284 |
<tt>axis.enableListQuery</tt> to false. |
| 285 |
|
| 286 |
<h3>Keep stack traces out of the responses </h3> |
| 287 |
|
| 288 |
By default, Axis ships in <i>production</i> mode; stack traces do not |
| 289 |
get sent back to the caller. If you set |
| 290 |
<tt>axis.development.system</tt> to true in the configuration, stack |
| 291 |
traces get sent over the wire in faults. This exposes internal |
| 292 |
information about the implementation that may be used in finding |
| 293 |
weaknesses. |
| 294 |
|
| 295 |
<h3>Stop autogenerating WSDL</h3> |
| 296 |
|
| 297 |
Trusted partners can still be given a WSDL file through email, or other |
| 298 |
means; there is no need to return the WSDL on a production server. How |
| 299 |
do you stop Axis returning WSDL? Edit the .wsdd configuration file, as |
| 300 |
described in the <a |
| 301 |
href="reference.html#individual_service">reference</a>, to return a |
| 302 |
WSDL resource which is simply an empty <wsdl/> tag. |
| 303 |
|
| 304 |
<h3>Servlets2.3: use filters for extra authentication</h3> |
| 305 |
|
| 306 |
Servlets 2.3 lets you use filters to look at all incoming requests and |
| 307 |
filter them however you like -including validating IP address, caller |
| 308 |
credentials, etc. Caller address validation is useful for securing admin |
| 309 |
services and pages, even when other endpoints are public. Of course, |
| 310 |
router configuration is useful there too. |
| 311 |
|
| 312 |
<h3>Log things</h3> |
| 313 |
|
| 314 |
Although full logs are a DoS attack tactic in themselves, logging who |
| 315 |
sends messages is often useful, for auditing and keeping track of what |
| 316 |
is going on. Add more log4j tags to whatever bit of Axis appeals to you |
| 317 |
to do this. |
| 318 |
|
| 319 |
<h3>Run Axis with reduced Java rights</h3> |
| 320 |
|
| 321 |
Java has a powerful and complex security system. Use it to configure |
| 322 |
Axis with reduced rights. Axis tries to write to |
| 323 |
WEB-INF/server-config.wsdd when updating the server config; and |
| 324 |
somewhere else (its configurable) when saving compiled .jws pages. |
| 325 |
|
| 326 |
<h3>Run the web server with reduced rights</h3> |
| 327 |
|
| 328 |
On Unix this is pretty much a given, but even on Windows NT and |
| 329 |
successors you can run a service as a different user. Make it one with |
| 330 |
limited rights. Make sure the core of the system has its access |
| 331 |
permissions tightened up so that the restricted-rights user can not |
| 332 |
get at things it shouldn't. |
| 333 |
|
| 334 |
<h3>Monitor Load</h3> |
| 335 |
|
| 336 |
To track DoS attacks, a load monitor is useful. <tt>AxisBaseServlet</tt> |
| 337 |
tracks the number of callers inside its subclasses at any point in time; |
| 338 |
the <tt>AdminServlet</tt> shows how to get at this data. |
| 339 |
|
| 340 |
<h3>Consider 'tripwire' and 'honeypot' endpoints</h3> |
| 341 |
|
| 342 |
With the core endpoints moved, why not create tripwire implementations |
| 343 |
of the admin endpoint, or a spoof endpoint listing under Axis/AdminServlet |
| 344 |
pointing to a honeypot endpoint that does nothing but send an alert when |
| 345 |
anyone sends a SOAP message to it. You then need a policy to act on the |
| 346 |
alerts, of course. A real honeypot would emulate an entire back end |
| 347 |
service -it would be an interesting little experiment to build and play |
| 348 |
with. |
| 349 |
|
| 350 |
<h3>Monitor the Mailing Lists</h3> |
| 351 |
|
| 352 |
We tend to discuss security on Axis-Dev, whenever it is an issue, but if |
| 353 |
demand is high we may add an axis-announce mailing list for important |
| 354 |
announcements. |
| 355 |
|
| 356 |
<h2>What to do if you find a security hole in Axis</h2> |
| 357 |
|
| 358 |
These days a lot of people love to make a name for themselves by finding |
| 359 |
security holes, and Axis, as part of the Apache product family, is a |
| 360 |
potential target. A hole in Axis could make many Web Services |
| 361 |
vulnerable, so could be serious indeed. So far we have only found a few |
| 362 |
of these, primarily in quirks of XML parsing rather than anything else. |
| 363 |
|
| 364 |
<ol> |
| 365 |
|
| 366 |
<li> Don't Panic. We have a process in place for verifying and fixing |
| 367 |
holes. |
| 368 |
|
| 369 |
<li> Don't rush to issue the press release to BugTraq. It is polite to |
| 370 |
let us know, and even verify that you are correct. |
| 371 |
|
| 372 |
<li> Test against the latest CVS version, not the (older) release |
| 373 |
builds. We may like already have fixed it, hacker dudes :-) |
| 374 |
|
| 375 |
<li> Email [email protected]. Not the public axis-dev list, not |
| 376 |
bugzilla. The security alias list is a list with representives from all |
| 377 |
Apache projects, so your report will be taken seriously. |
| 378 |
|
| 379 |
<li> Let us do a fix if possible, so we can announce that a fix is ready |
| 380 |
when you announce your finding. This doesn't take any of the credit way |
| 381 |
from the finder, just stops people panicing. |
| 382 |
|
| 383 |
</ol> |
| 384 |
|
| 385 |
<h2> Automate Security Tests</h2> |
| 386 |
|
| 387 |
If you find a security problem, write a test for it, such as a JUnit or |
| 388 |
HttpUnit test, so that you can regression test the application and |
| 389 |
installations for the problem. This is particularly important where it |
| 390 |
is a configuration problem that creates the hole; it is almost |
| 391 |
inevitable the same problem will re-occur on future installations. |
| 392 |
|
| 393 |
|
| 394 |
<h2>Conclusions</h2> |
| 395 |
|
| 396 |
We have shown some of the issues with Web Service security, things |
| 397 |
you need to think of in your own service, and how to harden Axis itself. |
| 398 |
Securing a system is much harder than getting a system to work, as |
| 399 |
'work' usually means 'one or two non-critical bugs are OK'. From a |
| 400 |
security perspective, no security holes can exist for a system to be |
| 401 |
secure: no matter how obscure it is, someone may find it and exploit it. |
| 402 |
Be paranoid: you know it makes sense. |
| 403 |
|
| 404 |
<p> |
| 405 |
|
| 406 |
Finally, don't get put off writing SOAP services through a fear of the |
| 407 |
security implications. Any CGI-BIN or ASP/JSP page that takes parameters |
| 408 |
is as much of a security risk as a SOAP endpoint. For some reason, |
| 409 |
SOAP attracts dramatic press stories about infinite risk, perhaps |
| 410 |
because it is new and unknown. It isn't: it is XML posted to a web |
| 411 |
application, that's all. Only if you are scared of that, should you |
| 412 |
not write a SOAP service. |
| 413 |
|
| 414 |
</body> |
| 415 |
</html> |