Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid instantiating arbitrary classes #758

Merged

Conversation

raboof
Copy link
Contributor

@raboof raboof commented Feb 1, 2022

This PR avoids the use of Class#newInstance, which is
deprecated in Java 9.

In particular, previously you could set the config.strategy
system to an arbitrary class that would get instantiated even
if it was not a subclass of ConfigLoadingStrategy. This is
now checked before instantiating the class.

The previous behavior could arguably be considered a security
concern when an attacker has write access to system properties,
though in such a scenario there are likely many other ways to
load arbitrary code.

Thanks to @vlsi for identifying this issue.

@raboof raboof changed the base branch from master to main February 1, 2022 13:57
This PR avoids the use of `Class#newInstance`, which is
deprecated in Java 9.

In particular, previously you could set the `config.strategy`
system to an arbitrary class that would get instantiated even
if it was not a subclass of `ConfigLoadingStrategy`. This is
now checked before instantiating the class.

The previous behavior could arguably be considered a security
concern when an attacker has write access to system properties,
though in such a scenario there are likely many other ways to
load arbitrary code.
@raboof raboof force-pushed the avoid-instantiating-arbitrary-classes branch from 74bbcff to fe85a7d Compare February 1, 2022 13:58
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause == null) throw new ConfigException.BugOrBroken("Failed to load strategy: " + className, e);
else throw new ConfigException.BugOrBroken("Failed to load strategy: " + className, cause);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ unwrapping InvocationTargetException is great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants