Play video content Exclusive TMZ.com

The troubled son of former 'RHOC' star Lauri Peterson is recovering after getting slashed in his face during an insane jailhouse ambush ... and TMZ has video of the whole incident.

The brutal attack went down at the Orange County jail in Santa Ana when Josh Waring was on his way back to his cell. He never got there because another inmate jumped out wielding razors wrapped in towels.

This surveillance video of the October 9 showdown shows the attacker sneak into position -- hiding under a staircase -- and then Josh, in pajamas and sandals, is suddenly fighting for his life. Fists start flying and Josh defends himself well for a while -- getting in a few head shots -- but he eventually suffered deep gashes to his chest and face.

The brawl -- which moved off-camera, but was still visible in a mirror -- lasted nearly 90 seconds and only stopped when guards rushed in ... commanding both men to get down on the ground.

Josh's attorney, Joel Garson, tells TMZ ... his client was returning to his cell in the protective custody unit of the jail after making a phone call. He says the normal protocol is for all other inmates to be locked in their cells while another inmate is using the phone.

Garson says guards are supposed to confirm over the intercom that the other inmates are locked away. There's no audio on the surveillance video, so Josh's attorney says he can't tell if that protocol was followed -- but he says he wouldn't be surprised if the attacker was allowed to be out of his cell.

Garson is claiming it could be retaliation against Josh for filing a federal lawsuit against Orange County and its Sheriff's Department for violating his civil rights while he's been behind bars.

Play video content TMZ.com

Another video shows Josh receiving medical treatment after the attack. He's surrounded by deputies as he describes his injuries. He was concerned the razors used against him weren't sterile, and he could've contracted an STD.

We're told he got 20 stitches to his chest and face, which was slashed from his left eye down to his chin.

The Orange County Sheriff's Department tells us it's opened a criminal investigation into the attack.

Josh has been locked up since 2016 while he awaits trial for attempted murder. He's accused of shooting a man at a sober living home where he was living.

He could get life in prison if convicted.

Garson tells us, based on this video, they are considering adding new claims to the federal lawsuit they've already filed against Orange County.