Checking for forwarding loops with a ring group

Hello

Over the years I have built up a rather complex dial plan that’s executes when people set an immediate forward.

This checks for loops 2 hops along, valid extension and length checks and numerous other things and works great

However, I have just came across an issue that’s been going on for months that I’ve never spotted in that a single extension has an immediate forward to a ring group and one of the members of that ring group is on an immediate forward to the single extension which is resulting in creating a loop.

I know I can ignore CF at group level but there are times when member handsets need to be set to forward the group which does work as long as the number forwarded to is not forwarded back to the group.

Can anyone advise on a way to have a loop check when setting the forward when a ring group is involved?

I can’t see where the info is stored in asterisk db to reference to