Seems like there are two types of fees being talked about here.

Pre Funding/Application Fee and Post Funding/service, closing, boarding, management fee.

The part that is illegal seems to be the pre funding fees, but even the SBA has a form that allows you to charge the borrower up to 2% direct for a consulting fee, on top of the fee the bank will give you for the referral. The document is signed by the borrow and part of the closing doc, and then it is up to you to collect that consulting fee direct.

The biggest issue is that a pre funding fee is/was associated with bad actors making promises of funding that may not actually come to fruition.
You could charge a post funding fee as long as the proper disclosure happens up front and is documented properly.

* I am no lawyer, my 2 cents, consult a lawyer before charging any fees*