While ESAPI doesn't offer a lot of help for these, that is not to say that #1 or #2 are impossible to address.
In Nginx (or the corresponding Apache HTTPD web server), you'd pretty much have to write a web server extension to all ESAPI code, since AFAIK, neither of those can call Java code directly. However, you probably could use their SDK to write an extension and call Java through a reverse JNI. 20+ years ago, I worked on a project where we did something similar with Netscape IPlanet web server and NSAPI calling a static Java method via a reverse-JNI of sorts. It's an ugly kludge, but we made it work.
In the case of Tomcat, it likely would be less complicated. You probably could do it by implementing a Tomcat Valve, and possibly even a Java EE / Jakarta Servlet Filter, depending on what you're trying to do.
If you are trying to address #2, often there are ways to extend the web application framework (or "application stack", as Matt refers to it), but the details would be specific to the framework / version you are working with. Matt is right in that ESAPI offer a lot with these cases though.
That said, the
Validator.getValidDirectory is probably your best bet. If there's something else that you wished that it would cover that it doesn't presently do, please consider writing up a new GitHub issue.
-kevin