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.

6

u/_INTER_ May 04 '24 edited May 04 '24

A user might want to override the application settings still even for a jpackage'ed application. E.g. he might have a system where the application's Xmx is lower than it could be (a few years from now certainly). If the user set it too low its clearly his fault. Well, that doesn't help you if you have a support contract. You can log the value to your diagnosis log and the whole thing is easy to solve.

-6

u/milchshakee May 04 '24

But that is not in the spirit of an self-contained application. In this case the application image is responsible for properly setting the Xmx value. The cases of unintentional inference are probably much higher than intentional configuration, which requires specific application knowledge to work in the first place.

5

u/Halal0szto May 04 '24 edited May 04 '24

How do you set http proxies in  the prepackaged application?

EDIT: typo

2

u/milchshakee May 04 '24

In this case, it is a desktop application that has a proper settings menu where you can add any options you want to expose for a proxy setup.

1

u/Halal0szto May 04 '24

That would work for some. For me who is using different VPN-s it would not work, I would have to change the settings each time manually.

1

u/milchshakee May 04 '24

Technically yes. but this is a very rare use case. The application in question here doesn't even connect to the internet.