Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

The following table lists the APIs that should be used with care [SCG 2009].

APIs That Mirror Language Checks

java.lang.Class.newInstance()

java.lang.reflect.Constructor.newInstance()

java.lang.reflect.Field.get*()

java.lang.reflect.Field.set*()

java.lang.reflect.Method.invoke()

java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater()

java.util.concurrent.atomic.AtomicLongFieldUpdater.newUpdater()

java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater()

Because the setAccessible() and getAccessible() methods of class java.lang.reflect.Field are used to instruct the JVM to override the language access checks, they perform standard (and more restrictive) security manager checks and consequently lack the vulnerability discussed in this rule. Nevertheless, these methods should be used only with extreme caution. The remaining set*() and get*() field reflection methods perform only the language access checks and are vulnerable.

...

Misuse of APIs that perform language access checks only against the immediate caller can break data encapsulation, leak sensitive information, or permit privilege escalation attacks.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

SEC05-J

High

Probable

Medium

P12

L1

Automated Detection

ToolVersionCheckerDescription
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

JAVA.CLASS.ACCESS.BYPASS
JAVA.CLASS.ACCESS.MODIFY

Reflection Bypasses Member Accessibility (Java)
Reflection Modifies Member Accessibility (Java)

Parasoft Jtest
Include Page
Parasoft_V
Parasoft_V
CODSTA
CERT.
BP.ARM
SEC05.ARMAvoid using reflection methods
SonarQube
Include Page
SonarQube_V
SonarQube_V

S3011

Changing or bypassing accessibility is security-sensitive
SpotBugs

Include Page
SpotBugs_V
SpotBugs_V

REFL_REFLECTION_INCREASES_ACCESSIBILITY_OF_CLASSImplemented (since 4.5.0)
Implemented

Related Guidelines

Secure Coding Guidelines for Java SE, Version 5.0

Guideline 9-10 / ACCESS-10: Be aware of standard APIs that perform Java language access checks against the immediate caller

Android Implementation Details

Reflection can be used on Android, so this rule is applicable. Also, the use of reflection may allow a developer to access private Android APIs and so requires caution.

Bibliography

[Chan 1999]

java.lang.reflect AccessibleObject

...


...