From Git 2.36, you can also add * representing ‘all’ to the safe.directory. It’s not recursive as you asked, but it may help depending upon your situation i.e.
git config --global --add safe.directory "*"
See https://github.blog/2022-04-18-highlights-from-git-2-36/ and search for safe.directory.
EDIT: As suggested by zcoop98, we should add double quotes around ‘*’.