Depth of Field and Depth Pass problem

Hi everyone

I seem to be having some trouble getting the look I need from DOF. Below is a render I did with DOF enabled:

At first, everything looks fine, but, the corners of the glass box is also blurring, which is not what I want. I only need the background objects to be blurred. So then I looked for other ways of doing this. I settled with using the Depth pass and Defocus node. This is the result:

So great, the glass box is in focus and the background blurred. The problem now is that objects behind the glass box, like the objects in the background, isn’t blurred when looking at them through the glass box, which isn’t surprising considering how depth maps work,

So my question is, is there a way to use the Depth map with the other passes like glossy to get the result I want?

Here is my blend file
help.blend (4.3 MB)

Any help would be greatly appreciated.
Thanks all

You can enable DOF in camera, then focus on the cube. Then go to Render > DOF > and adjust the max size so that the cube is inside the focus.
Take a look at this tutorial, although it’s only for Eevee:

Edit: Actually to make more sense to your specific case, try adding a ColorRamp after the Normalize node:

Edit2: If you want the blur only inside the cube, you will have to mix the blurry layer with the clear one using the cube as mask, like this: