Reliance on Package-level Scope

Incomplete Base
Structure: Simple
Description

This weakness occurs when a Java application mistakenly treats package-level access as a security boundary, assuming it can prevent unauthorized access to code.

Extended Description

In Java, the package-private scope (declared without `public`, `protected`, or `private`) is a development convenience, not a security feature. Its primary role is to organize code and prevent accidental coupling between unrelated parts of the application within the same program. However, because Java packages are not sealed or closed environments, other code can easily be placed in the same package—either intentionally or through classpath manipulation—to bypass this access restriction. Relying on package scope for security creates a false sense of protection. Attackers or malicious code can exploit this by defining classes within the targeted package, gaining full access to package-private members. For true access control, developers should use the Security Manager, proper module boundaries (Java Platform Module System), or explicit security checks, rather than depending on visibility modifiers alone.

Common Consequences 2
Scope: Confidentiality

Impact: Read Application Data

Any data in a Java package can be accessed outside of the Java framework if the package is distributed.

Scope: Integrity

Impact: Modify Application Data

The data in a Java class can be modified by anyone outside of the Java framework if the packages is distributed.

Potential Mitigations 1
Phase: Architecture and DesignImplementation
Data should be private static and final whenever possible. This will assure that your code is protected by instantiating early, preventing access and tampering.
Demonstrative Examples 1
The following example demonstrates the weakness.

Code Example:

Bad
Java
java
References 1
The CLASP Application Security Process
Secure Software, Inc.
2005
ID: REF-18
Likelihood of Exploit

Medium

Applicable Platforms
Languages:
Java : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • CLASP
  • The CERT Oracle Secure Coding Standard for Java (2011)