Sandbox JPanel within JFrame

150 Views Asked by At

I have a JFrame with a JPanel in it. I'm loading some untrusted 3rd party code that needs to add some components to my JPanel. How can I sandbox my JPanel such that to make it impossible for the 3rd party components to access resources outside the JPanel (eg. the JFrame)?

1

There are 1 best solutions below

3
treeno On

This will be difficult since your JPanel extends JComponent that has getParent() which would return your JFrame... Since every component in Swing implement that, it is likely that your third-party component also implement that. You could try to overwrite these methods, but I don't think that swing will still work correctly because you would cut of the ComponentTree by doing that...

Could you explain how you load that untrusted code? Is it a library or do you load that at runtime by reflection or something similar?