---
title: "CWE-492: Use of Inner Class Containing Sensitive Data"
url: https://radicalnotion.ai/cwe/cwe-492
type: cwe
description: "Inner classes are translated into classes that are accessible at package scope and may expose code that the programmer intended to keep private to attackers."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-492: Use of Inner Class Containing Sensitive Data

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

Inner classes are translated into classes that are accessible at package scope and may expose code that the programmer intended to keep private to attackers.

Inner classes quietly introduce several security concerns because of the way they are translated into Java bytecode. In Java source code, it appears that an inner class can be declared to be accessible only by the enclosing class, but Java bytecode has no concept of an inner class, so the compiler must transform an inner class declaration into a peer class with package level access to the original outer class. More insidiously, since an inner class can access private fields in its enclosing class, once an inner class becomes a peer class in bytecode, the compiler converts private fields accessed by the inner class into protected fields.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Java (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality | Read Application Data | "Inner Classes" data confidentiality aspects can often be overcome. |

## Potential mitigations

### Implementation

Using sealed classes protects object-oriented encapsulation paradigms and therefore protects code from being extended in unforeseen ways.

### Implementation

Inner Classes do not provide security. Warning: Never reduce the security of the object from an outer class, going to an inner class. If an outer class is final or private, ensure that its inner class is private as well.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following Java Applet code mistakenly makes use of an inner class.

Bad code:

```java
public final class urlTool extends Applet {
    private final class urlHelper {
        ...
    }
    ...
}
```

### Example 2

The following example shows a basic use of inner classes. The class OuterClass contains the private member inner class InnerClass. The private inner class InnerClass includes the method concat that accesses the private member variables of the class OuterClass to output the value of one of the private member variables of the class OuterClass and returns a string that is a concatenation of one of the private member variables of the class OuterClass, the separator input parameter of the method and the private member variable of the class InnerClass.

Bad code:

```java
public class OuterClass {
    // private member variables of OuterClass
    private String memberOne;
    private String memberTwo;

    // constructor of OuterClass
    public OuterClass(String varOne, String varTwo) {
        this.memberOne = varOne;
        this.memberTwo = varTwo;
    }

    // InnerClass is a member inner class of OuterClass
    private class InnerClass {
        private String innerMemberOne;

        public InnerClass(String innerVarOne) {
            this.innerMemberOne = innerVarOne;
        }

        public String concat(String separator) {
            // InnerClass has access to private member variables of OuterClass
            System.out.println("Value of memberOne is: " + memberOne);
            return OuterClass.this.memberTwo + separator + this.innerMemberOne;
        }
    }
}
```

Good code:

```java
public class OuterClass {

    // private member variables of OuterClass
    private String memberOne;
    private static String memberTwo;

    // constructor of OuterClass
    public OuterClass(String varOne, String varTwo) {
        this.memberOne = varOne;
        this.memberTwo = varTwo;
    }

    // InnerClass is a static inner class of OuterClass
    private static class InnerClass {

        private String innerMemberOne;

        public InnerClass(String innerVarOne) {
            this.innerMemberOne = innerVarOne;
        }
        public String concat(String separator) {
            // InnerClass only has access to static member variables of OuterClass
            return memberTwo + separator + this.innerMemberOne;
        }
    }
}
```

### Example 3

In the following example the BankAccount class contains the private member inner class InterestAdder that adds interest to the bank account balance. The start method of the BankAccount class creates an object of the inner class InterestAdder, the InterestAdder inner class implements the ActionListener interface with the method actionPerformed. A Timer object created within the start method of the BankAccount class invokes the actionPerformed method of the InterestAdder class every 30 days to add the interest to the bank account balance based on the interest rate passed to the start method as an input parameter. The inner class InterestAdder needs access to the private member variable balance of the BankAccount class in order to add the interest to the bank account balance.

Bad code:

```java
public class BankAccount {

    // private member variables of BankAccount class
    private String accountOwnerName;
    private String accountOwnerSSN;
    private int accountNumber;
    private double balance;

    // constructor for BankAccount class
    public BankAccount(String accountOwnerName, String accountOwnerSSN,
    int accountNumber, double initialBalance, int initialRate)
    {
        this.accountOwnerName = accountOwnerName;
        this.accountOwnerSSN = accountOwnerSSN;
        this.accountNumber = accountNumber;
        this.balance = initialBalance;
        this.start(initialRate);
    }

    // start method will add interest to balance every 30 days

    // creates timer object and interest adding action listener object
    public void start(double rate)
    {
        ActionListener adder = new InterestAdder(rate);
        Timer t = new Timer(1000 * 3600 * 24 * 30, adder);
        t.start();
    }

    // InterestAdder is an inner class of BankAccount class

    // that implements the ActionListener interface
    private class InterestAdder implements ActionListener
    {
        private double rate;

        public InterestAdder(double aRate)
        {
            this.rate = aRate;
        }

        public void actionPerformed(ActionEvent event)
        {
            // update interest
            double interest = BankAccount.this.balance * rate / 100;
            BankAccount.this.balance += interest;
        }
    }
}
```

Good code:

```java
public class BankAccount {

    // private member variables of BankAccount class
    private String accountOwnerName;
    private String accountOwnerSSN;
    private int accountNumber;
    private double balance;

    // constructor for BankAccount class
    public BankAccount(String accountOwnerName, String accountOwnerSSN,
    int accountNumber, double initialBalance, int initialRate)
    {
        this.accountOwnerName = accountOwnerName;
        this.accountOwnerSSN = accountOwnerSSN;
        this.accountNumber = accountNumber;
        this.balance = initialBalance;
        this.start(initialRate);
    }

    // start method will add interest to balance every 30 days

    // creates timer object and interest adding action listener object
    public void start(final double rate)
    {

        // InterestAdder is a local inner class

        // that implements the ActionListener interface
        class InterestAdder implements ActionListener
        {
            public void actionPerformed(ActionEvent event)
            {
                // update interest
                double interest = BankAccount.this.balance * rate / 100;
                BankAccount.this.balance += interest;
            }
        }
        ActionListener adder = new InterestAdder();
        Timer t = new Timer(1000 * 3600 * 24 * 30, adder);
        t.start();
    }
}
```

Good code:

```java
public class BankAccount {

    // private member variables of BankAccount class
    private String accountOwnerName;
    private String accountOwnerSSN;
    private int accountNumber;
    private double balance;

    // constructor for BankAccount class
    public BankAccount(String accountOwnerName, String accountOwnerSSN,
    int accountNumber, double initialBalance, int initialRate)
    {
        this.accountOwnerName = accountOwnerName;
        this.accountOwnerSSN = accountOwnerSSN;
        this.accountNumber = accountNumber;
        this.balance = initialBalance;
        this.start(initialRate);
    }

    // start method will add interest to balance every 30 days

    // creates timer object and interest adding action listener object
    public void start(final double rate)
    {

        // anonymous inner class that implements the ActionListener interface
        ActionListener adder = new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {

                double interest = BankAccount.this.balance * rate / 100;
                BankAccount.this.balance += interest;
            }
        };

        Timer t = new Timer(1000 * 3600 * 24 * 30, adder);
        t.start();
    }
}
```

### Example 4

In the following Java example a simple applet provides the capability for a user to input a URL into a text field and have the URL opened in a new browser window. The applet contains an inner class that is an action listener for the submit button, when the user clicks the submit button the inner class action listener's actionPerformed method will open the URL entered into the text field in a new browser window. As with the previous examples using inner classes in this manner creates a security risk by exposing private variables and methods. Inner classes create an additional security risk with applets as applets are executed on a remote machine through a web browser within the same JVM and therefore may run side-by-side with other potentially malicious code.

Bad code:

```java
public class UrlToolApplet extends Applet {

    // private member variables for applet components
    private Label enterUrlLabel;
    private TextField enterUrlTextField;
    private Button submitButton;

    // init method that adds components to applet

    // and creates button listener object
    public void init() {
        setLayout(new FlowLayout());
        enterUrlLabel = new Label("Enter URL: ");
        enterUrlTextField = new TextField("", 20);
        submitButton = new Button("Submit");
        add(enterUrlLabel);
        add(enterUrlTextField);
        add(submitButton);
        ActionListener submitButtonListener = new SubmitButtonListener();
        submitButton.addActionListener(submitButtonListener);
    }

    // button listener inner class for UrlToolApplet class
    private class SubmitButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == submitButton) {
                String urlString = enterUrlTextField.getText();
                URL url = null;
                try {
                    url = new URL(urlString);
                } catch (MalformedURLException e) {
                    System.err.println("Malformed URL: " + urlString);
                }
                if (url != null) {
                    getAppletContext().showDocument(url);
                }
            }
        }
    }
}
```

Good code:

```java
public class UrlToolApplet extends Applet implements ActionListener {

    // private member variables for applet components
    private Label enterUrlLabel;
    private TextField enterUrlTextField;
    private Button submitButton;

    // init method that adds components to applet
    public void init() {
        setLayout(new FlowLayout());
        enterUrlLabel = new Label("Enter URL: ");
        enterUrlTextField = new TextField("", 20);
        submitButton = new Button("Submit");
        add(enterUrlLabel);
        add(enterUrlTextField);
        add(submitButton);
        submitButton.addActionListener(this);
    }

    // implementation of actionPerformed method of ActionListener interface
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == submitButton) {
            String urlString = enterUrlTextField.getText();
            URL url = null;
            try {
                url = new URL(urlString);
            } catch (MalformedURLException e) {
                System.err.println("Malformed URL: " + urlString);
            }
            if (url != null) {
                getAppletContext().showDocument(url);
            }
        }
    }
}
```

As with the previous examples a solution to this problem would be to use a static inner class, a local inner class or an anonymous inner class. An alternative solution would be to have the applet implement the action listener rather than using it as an inner class as shown in the following example.

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-668](https://radicalnotion.ai/cwe/cwe-668) | Exposure of Resource to Wrong Sphere |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Mobile Code: Use of Inner Class | - | - |
| CLASP | Publicizing of private data when using inner classes | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not expose private members of an outer class from within a nested class | OBJ08-J | - |

## Frequently asked questions

### What is CWE-492?

Inner classes are translated into classes that are accessible at package scope and may expose code that the programmer intended to keep private to attackers.

### How do you prevent CWE-492?

Using sealed classes protects object-oriented encapsulation paradigms and therefore protects code from being extended in unforeseen ways.

### How is CWE-492 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-492?

Exploiting CWE-492 can lead to: Read Application Data.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/492.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-492). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
