Skip to content

Avoid instantiating arbitrary classes#758

Merged
raboof merged 1 commit intolightbend:mainfrom
raboof:avoid-instantiating-arbitrary-classes
Feb 1, 2022
Merged

Avoid instantiating arbitrary classes#758
raboof merged 1 commit intolightbend:mainfrom
raboof:avoid-instantiating-arbitrary-classes

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