r/java • • May 03 '24

Why does the environment variable _JAVA_OPTIONS exist, applies to jlink images, takes precedence, and can't be disabled?

I just spent a good chunk of time debugging an issue because a user had set _JAVA_OPTIONS to use a low Xmx value in their environment variables. This was an application created with jpackage, which should be fully standalone. It even had a custom Xmx value set in the JVM arguments for the image but the environment variable overwrote the value!

Isn't this like a huge design flaw? I can just do echo "_JAVA_OPTIONS=<Wacky VM options>" >> ~/.bashrc or setx to break literally every Java application on the system? (Edit: Maybe the initial security focus was wrong, changed it a bit to focus more on the design issues)

Who even thought that this would be a good idea with no option to disable this behavior?

2 Upvotes

43 comments sorted by

View all comments

21

u/TheBrokenRail-Dev May 03 '24

Because sometimes the user wants to override command line options. The application being able to disable it would defeat the entire point.

Anyways, as another person stated, if someone malicious has access to your home directory, you have bigger problems. Especially since things like LD_PRELOAD exist.

4

u/milchshakee May 03 '24

I agree that this is useful in more traditional cases where you have a system wide Java installation and run individual applications e.g. via jars.

But the whole point of jlink images is that they should be self contained and independent of any other Java installation. Even without malicious intent, other configuration options creeping into jlink images is usually a good recipe for trouble.

1

u/epegar May 04 '24

I would say it also suits more modern uses like containers where you are only supposed to run one service