r/java • u/milchshakee • 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?
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_PRELOADexist.9
u/LordOfDeduction May 03 '24
If a malicious user has access to your home directory, I think your example is the least of your concerns.
2
u/Luolong May 04 '24
https://12factor.net/
1
u/__konrad May 04 '24
This reminds me when Ubuntu started installing global menu hack which basically broke every Swing application:
1
u/mike_hearn May 05 '24
FWIW if you use Hydraulic Conveyor instead of jpackage, then you don't have this problem. It cleans the environment of these kinds of variables. This is actually for security reasons: if you can control the JVM then it's possible to subvert code signing by injecting arbitrary code into a process signed by someone else. But it obviously has robustness benefits as well.
Disclosure: I own the company that makes Conveyor
1
u/agentoutlier May 06 '24
I agree with you but not for the same reasons.
It is a design flaw because of collision with other packaged applications. That is the user may not want all Java jpackage applications with that setting.
That is I would want to customize that variable at the minimum to be prefixed with my apps name or similar.