"Handguards" on a handgun are OK, look at the various single shot hand cannons such as the Contender and XP100. Horizontal forearm, IOW.
Rails are also OK, again they are standard equipment on almost all full size modern semi auto handguns. Just don't clamp on a grip.
The only law involved with forward grips is the NFA, specifically the definition of Any Other Weapon, or AOW. Here's where things get confusing, mainly because of ATF's interpretation of the law.
Fed law defines a pistol as:
"A weapon originally designed, made, and intended to fire a
projectile (bullet) from one or more barrels when held in one hand, and
having (a) a chamber(s) as an integral part(s) of, or permanently
aligned with, the bore(s); and (b) a short stock designed to be gripped
by one hand and at an angle to and extending below the line of the
An AOW is basically any "concealable" (under 16" bbl or 26" overall according to ATF) firearm that isn't a handgun, rifle, or shotgun.
Somewhere along the line someone at ATF saw a forward grip on a handgun and said "That's designed to be fired with two hands, not one!" So not a handgun, no buttstock so not a rifle. That leaves AOW. The problem is pistols are specifically exempted from AOW status, and the legal definition states originally designed, made, and intended to be fired from one hand. How does Joe Glockowner clamping a grip to the rail after he buys it change Glock's original design and intent? It could even be argued that since Glock and many other makers add checkering and/or a "hook" to the front of the triggerguard to steady the forefinger of the off hand in a two handed grip the pistol was in fact originally designed to be fired with two hands, yet ATF classes it as a handgun.
Now, say Beretta comes out with a semiautomatic 93R clone with factory folding foregrip, well ATF would be right that it is not a handgun. But people installing them after they are made and sold? Not an AOW according to the letter of the law.
AFAIK no cases have ever been prosecuted over a forward grip on a pistol. I guess no one wants to be the test case that gets ATF's interpretation voided.