This error is detected when a public method stores a reference to a mutable object.

Vulnerability and risk

Malicious applet can modify internal state of object by modifying result that returned.

Klocwork security vulnerability (SV) checkers identify calls that create potentially dangerous data; these calls are considered unsafe sources. An unsafe source can be any data provided by the user, since the user could be an attacker or has the potential for introducing human error.

Mitigation and prevention

This vulnerability can be prevented by not storing references to mutable objects in public methods, using immutable object instead or avoid using static fields.

Example 1

18    private Collection users;
19    public void setUsers(Collection users) throws AuthorizationException {
20      for (Iterator iter = users.iterator(); iter.hasNext();) {
21        String user = (String);
22        if (!authorized(user)) throw new AuthorizationException();
24      }
25      this.users = users;
26    }
27    // ...
28    void maliciousUserCode() throws AuthorizationException {
29        Collection myUsers = new ArrayList();
30        myUsers.add("goodUser");
31        setUsers(myUsers);
32        myUsers.add("anotherUser");
33    }

SV.EXPOSE.STORE is reported for line 26: Method stores reference to mutable object 'users'. Internal state of object can be modified by malicious user.

Security training

Application security training materials provided by Secure Code Warrior.