...
This compliant solution avoids the TOCTOU vulnerability by copying the mutable input and performing all operations on the copy. Consequently, an attacker's changes to the mutable input cannot affect the copy. Acceptable techniques include using a copy constructor or implementing the java.lang.Cloneable
interface and declaring a public
clone method (for classes not declared as final
). In cases like HttpCookie
where the mutable class is declared final
— that is, it cannot provide an accessible copy method — perform a manual copy of the object state within the caller. See rule OBJ08OBJ04-J. Provide mutable classes with copy functionality to allow passing instances to untrusted code safely for more information. Note that any input validation must be performed on the copy and not on the original object.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5493f637b6b5f4bd-39626020-4e894b42-bf7b9b91-83aa49eb4af9e145496618f9"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 39: Make defensive copies when needed | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6bb095fd8f078b54-a9570360-43544f7d-bc52b82b-3b7258ece2b0ed3f35233ed5"><ac:plain-text-body><![CDATA[ | [[Pugh 2009 | AA. Bibliography#Pugh 09]] | Returning references to internal mutable state | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="44601fb0776e5220-7e8189fa-4ce64f15-865986b8-4711b0aac4338e22f8a26dc3"><ac:plain-text-body><![CDATA[ | [[SCG 2007 | AA. Bibliography#SCG 07]] | Guideline 2-1 Create a copy of mutable inputs and outputs | ]]></ac:plain-text-body></ac:structured-macro> |
...