Using SAST tools for static code analysis, we're getting security findings in jaxb generated code, claiming "Passing mutable objects to an untrusted method" (CWE-374) in getter and setter methods. The suggestion is, cloning the objects before passing its references to the caller.
But how can we handle issues like that in generated code? Is there an option in jaxb?
I don't know of a customization option that would affect that particular code generation.
There are two options that I know work well:
We currently utilize both of these approaches to manage our generated code.
Another possibility that we have not implemented would be to add an annotation to the methods you are interested in tweaking (which can be done with existing open source JAXB plugins) and use other technologies to affect the code/execution (e.g., annotation processor, AOP tool).