I want to show a warning if a file is read that is not owned by the user that started the JVM.
In my application, this file can make the program write arbitrary files. So I want to reduce the risk of a privilege escalation attack, if an admin processes this file.
Files.getOwner(path)
retruns a UserPrincipal
that represents the file owner. But I can't find a platform independent way to check if this UserPrincipal
matches the current user.
I could use
System.getProperty("user.name")
to get the current user and try to match the names. But these properties can be manipulated and this doesn't work if the file owner is a group, for example.