+3  A: 

They could, but the issue here is not in the specification: it's in running untrusted code. If you allow a jar that you don't trust to load and run, then it could potentially do things that are a lot worse than surfacing a servlet.

GaryF
+3  A: 

Maybe, maybe not. (I don't know for sure). But if you are worried about things that unscrupulous providers might do in their JARs, there are a whole bunch of other nasty things they could do plain old Java. If you are worried about this kind of thing, you really need to insist on getting source code, and do a thorough audit of the code before you let it onto your production servers.

Stephen C
Agreed. What's stopping any JAR from opening a socket and providing a backdoor? Or even injecting a virus in the system! This doesn't have to be web server.
Thierry-Dimitri Roy
Nothing, but any reasonable firewall would prevent anything to connect to a separate listening socket or the malicious JAR to make any unexpected outbound network connections. If the malicious JAR is allowed to add servlet filters, it can hook itself into the processing chain of any HTTP request and provide a backdoor through obviously sane and expected HTTP traffic.
jarnbjo
+2  A: 

You can use an <absolute-ordering> element in the main web.xml deployment descriptor to list only the jar files in WEB-INF/lib, which you want to be automatically analyzed for annotations and web-fragment.xml descriptors during deployment.

If you do so, the content of web-fragments or annotated classes in other JAR files are not deployed automatically.

jarnbjo
+1  A: 

You will be able to control this process, quote from here:

The Servlet 3.0 specification also provides an option for instructing the Web Container, whether the container should process the annotations defined on the web components. The name of the element is metadata-complete and it is a child element of web-app element. The metadata-complete element indicates whether the meta-data information available in the deployment descriptor is complete. So, if the value for the metadata-complete element is set to a value of true, then it means that the meta information found in the deployment descriptor is complete and eventually the annotations defined on the web components will be ignored by the Servlet Container. If the value for metadata-complete is set to false, then it means that the information in the deployment descriptor is not complete and web components decorated with annotations, if any, should be scanned and processed by the Web Container.

ZloiAdun