Add support for Jakarta Servlet API Specification #768
Replies: 21 comments 56 replies
-
It's been a LONG TIME since I set up a Spring application, but IIRC the issue is that ESAPI codes against the servlet-api but it isn't packaged with it. I would first ensure that your application dependencies are explicit. https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api Some application servers have their own methods for supplying the servlet-api, I know with WebSphere we deployed it as a web app server library so applications didn't need to include it as their own dependency. We Code against the specification only so there is no need for any explicit support for Jakarta, Websphere, etc. You supply your own implementation. It is 100% supported, you just need to fix your dependencies. |
Beta Was this translation helpful? Give feedback.
-
Thanks for commenting back so quickly. Unfortunately the newest version of Spring and Spring Boot are using Jakarta Servlet API specification and no longer using Java Servlet API specification hence the new package for Jakarta's servlet api is starting with jakarta.servlet and not java.servlet. Also the newest versions of Tomcat and Jetty are now using this new Servlet API specification so I imagine other folks will be experiencing our pain soon. |
Beta Was this translation helpful? Give feedback.
-
@guadgarcia, it looks like jakarta.servlet-api changed this between their 4.x releases (when it was using We have to support older versions of javax.servlet-api because many ESAPI clients are still running older versions of Java application servers and (at least originally) that was what the Glassfish reference model used as well as WebLogic server. And since it is the app server that generally decides that, maybe you need to switch to a different default app server. (I think you use an embedded version of Jetty, right?) That's the only thing I can think of beyond forking ESAPI and making those changes in your fork. (Come to think of it, the ServiceMix folks put an OSGI wrapper around ESAPI. Maybe you could get that to work? See https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.esapi.) However, if you can come up with some other suggestion that will allow us to support clients using application servers that use javax.servlet-api as jakarta.servlet-api that doesn't require significant code changes to those ESAPI clients, I'm all ears and will gladly reopen this and we can consider working on something. In the meantime, I'm going to convert this issue to a Discussion and hopefully get some more ESAPI community eyes on it. |
Beta Was this translation helpful? Give feedback.
-
The timing here was great. We are just looking into the same issue with our projects. This is an issue with the new Servlet API version. The new API comes with package names like
This is frustrating because it looks like the servlet API is only used to output the local server IP and port, and we aren't even using that functionality. It looks like as a workaround, you can manully create the Servlet API classes in your own codebase. For example, a bunch of empty class/interface files like this: package javax.servlet;
public interface ServletResponse extends jakarta.servlet.ServletResponse { } And then do the same thing for ServeltRequest/HttpServletRequest/HttpServletResponse/HttpSession. You also have to do the same for Cookie and ServletException (and include all the constructors for those, calling the corresponding But... we definitely shouldn't have to do this... (and it likely breaks other 3rd party JARs that are properly detecting what version of Servlet API is on the classpath) |
Beta Was this translation helpful? Give feedback.
-
This isn't a fix, but I wonder about this as a workaround. In the stack trace I posted above for our use case, it blows up on line 54 of of This is the first line of a block that looks like this: HttpServletRequest request = ESAPI.currentRequest();
if (request != null && logServerIP) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
} We below up on that first line when we call I think that would both alleviate the exception for our use case (since we aren't logging server IPs) if we refactor this slightly: if (logServerIP) {
HttpServletRequest request = ESAPI.currentRequest();
if (request != null) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
}
} This moves the line that blows up into the if block and it only gets processed in the use case where it needs to be processed. Again, not a fix for the overarching issue, but perhaps a fix/workaround for certain use cases where this IP information is not needed? |
Beta Was this translation helpful? Give feedback.
-
This is an off-the-wall idea (hey, I resemble that remark), but one possibility might be to provide a tool that would go through the byte code in the ESAPI jar and convert all the javax.servlet references to jakarta.servlet references and create an esapi-jakarta version of the jar. Anyone think that would have a prayer? I've never done anything like that so I have no idea of how much effort it might involve, who knows, maybe someone already as a tool similar to that, or better, a Maven plugin. |
Beta Was this translation helpful? Give feedback.
-
I think the Maven shade plugin might be able to help here…
Steps…
1) include javax.servlet in a copy of the esapi jar file
This is the copy we would modify
See the <filter> bit below
2) relocate javax.servlet to jakarta.servlet
This would change all references to those methods in ESAPI code
See the <relocation> bit below
3) delete javax.servlet classes from our jar
Would probably require some other maven plugin
Can’t be that hard
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>javax.servlet:javax.servlet-api</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>javax.servlet</pattern>
<shadedPattern>jakarta.servlet</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Not pretty but beats writing the code to modify the ASM (which I can do if this doesn’t work)
…--Jeff
From: Kevin W. Wall ***@***.***>
Date: Thursday, January 12, 2023 at 7:17 PM
To: ESAPI/esapi-java-legacy ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [ESAPI/esapi-java-legacy] Add support for Jakarta Servlet API Specification (Discussion #768)
This is an off-the-wall idea (hey, I resemble that remark), but one possibility might be to provide a tool that would go through the byte code in the ESAPI jar and convert all the javax.servlet references to jakarta.servlet references and create an esapi-jakarta version of the jar. Anyone think that would have a prayer? I've never done anything like that so I have no idea of how much effort it might involve, who knows, maybe someone already as a tool similar to that, or better, a Maven plugin.
—
Reply to this email directly, view it on GitHub<#768 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAUUFTDTA5X35EW7P4BOWJTWSCNH5ANCNFSM6AAAAAATZQU6JI>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
If we're going to make the attempt to support a new dependency version I'd much rather make a branch that I can test and review over trying to allow extension of the current bundled jar. I have no doubt that we can make the jar/class swapping work, I contend that we should not. If we explicitly support swapping this jar out then we will be receiving bugs and feedback based on that configuration. We have enough difficulty getting feedback with flat-file property configurations, and I do not think that this solution will be at all maintainable or sustainable. If we're going to support this then I believe the only long term option is to branch and re-version. At that point we have a consistent way of determining what each client is using by having them provide the version of the artifact in the environment. |
Beta Was this translation helpful? Give feedback.
-
Reading this bug reports makes me slump into my chair. I'm thinking about the problem it is going to cause for thousands of development teams. Sigh... Is it possible to tune the behavior of ESAPI with a command line option? The option would control whether ESAPI uses (This is another one of those times I wish Java had |
Beta Was this translation helpful? Give feedback.
-
After a little hunting it looks like this change was initiated back in 2018. I have no explanation as to why I haven't heard of it yet. I'm guessing that Spring is just now getting to enforcing this perhaps? I left a question over on another github asking why "javax" couldn't be used... it was dropped offhandedly. |
Beta Was this translation helpful? Give feedback.
-
My preference is that we should just update to the latest dependencies for the project, and keep up-to-date. The most recent ESAPI should use the most recent versions of all its dependencies (accounting for the java 8 requirement). If someone requires an older reference to one of our dependencies, then they should use the version of ESAPI compatible with their needs -- until they can update. Keep rolling forward with the expectation that everyone is coming with us. |
Beta Was this translation helpful? Give feedback.
-
@jeremiahjstacey - I will email you and @xeno6696 about removing the Apache Commons File Upload dependency that you mentioned in #768 (reply in thread). I don't want to clutter up this discussion with that side note. That said, it would be useful if all 3 of us could do a quick 30 minute or so virtual meeting sometime soon. I think the pros and cons need to be well understood and discussed before we make any major moves. Because once we commit to Jakarta Servlet API, there's no turning back and I think we have to commit to both at that point. So let's plan to discuss this. |
Beta Was this translation helpful? Give feedback.
-
Which esapi version support jakarta.*? |
Beta Was this translation helpful? Give feedback.
-
If you support 2 versions, is the only difference going to be the package names? If that's true, can you make future changes in one branch and then merge everything, except package name differences, to the other branch? This doesn't seem like a ton of effort and you may only need to do it a few times since it appears changes are made roughly every 6 months and, in a year or 2, it seems reasonable to drop support for the javax.* version completely. Thanks... I appreciate the work you guys do on this project. |
Beta Was this translation helpful? Give feedback.
-
I think this 2-part write-up is relevant to this discussion, so I am dropping a couple of links here: |
Beta Was this translation helpful? Give feedback.
-
Hello ESAPI team, Is there a plan to provide a jakarta compliant jar in future? |
Beta Was this translation helpful? Give feedback.
-
@kwwall I've submitted PR #799 as a starting point for getting this project up-to-date with the Jakarta namespace changes. It just creates another JAR in the target directory with the classifier of <dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.5.3.0-SNAPSHOT</version>
<classifier>jakarta</classifier>
</dependency> Happy to help get this over the finish line in whatever way I can. |
Beta Was this translation helpful? Give feedback.
-
@jcputney - One more thing to add... I did a quick look at the contents of the target/esapi-2.5.3.0-SNAPSHOT-jakarta-javadoc.jar file that PR #799 created by extracting all the comments into a tmp directory. I then did a recursive grep for |
Beta Was this translation helpful? Give feedback.
-
Hi @kwwall and congrats on the PR merge @JosephWitthuhnTR I noticed that #776 was merged in Feb. Does that mean that the 2.5.2.0 release contains the changes? Thanks for helping the open source community! |
Beta Was this translation helpful? Give feedback.
-
So, good news. ESAPI 2.5.3.0 is now released and is available (shows up at https://central.sonatype.com/artifact/org.owasp.esapi/esapi/2.5.3.0, but not yet visible at https://mvnrepository.com/artifact/org.owasp.esapi/esapi when I just checked). Along with esapi-2.5.3.0.jar though, it seems to have also updated esapi-2.53.0-jakarta.jar which ought to work with the Jakarta Servlet API Specification that uses That said, I'm not sure exactly how to request it as a dependency in Maven or Gradle, etc. Perhaps @jcputney would be so kind as to illustrate how that would work in this discussion before I close this discussion. |
Beta Was this translation helpful? Give feedback.
-
I just documented how to use the Jakarta version of ESAPI on our ESAPI GitHub wiki page: Therefore I am marking this discussion as closed. |
Beta Was this translation helpful? Give feedback.
-
We are in the process of upgrading our Spring Boot application to use Spring Boot 3.0.1 and we are getting an error related to ESAPI. The issue is happening because ServletResponse is now located in a different package.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: java.lang.NoClassDefFoundError: javax/servlet/ServletResponse] with root cause","context":"","exception":"java.lang.ClassNotFoundException: javax.servlet.ServletResponse\n\tat java.base/java.net.URLClassLoader.findClass(Unknown Source)\n\tat java.base/java.lang.ClassLoader.loadClass(Unknown Source)\n\tat org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:149)\n\tat java.base/java.lang.ClassLoader.loadClass(Unknown Source)\n\tat java.base/java.lang.Class.forName0(Native Method)\n\tat java.base/java.lang.Class.forName(Unknown Source)\n\tat org.owasp.esapi.util.ObjFactory.loadClassByStringName(ObjFactory.java:158)\n\tat org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:81)\n\tat org.owasp.esapi.ESAPI.httpUtilities(ESAPI.java:123)\n\tat org.owasp.esapi.ESAPI.currentRequest(ESAPI.java:70)\n\tat
Beta Was this translation helpful? Give feedback.
All reactions