Jurgen Klopp's side have now equaled a club record of 63 matches unbeaten at home.
West Ham took the lead inside the first 10 minutes when Fornals reacted to Joe Gomez's poor header to finish past Alisson.
Five minutes later, Jota received a through ball from fellow substitute Xherdan Shaqiri to win the game for the hosts.
"The world is in a difficult place and we are happy to be allowed to play football. So we have to try everything to win football games. It's not about shining, or flying, or whatever, it's about hard work," said Klopp.
"That was absolutely necessary against this opponent. It's not about the simple stuff because they are too good for that -- you need to be cheeky, tricky as well, and we were."
West Ham manager David Moyes was upset with the decision to award Salah a penalty after his reaction to contact in the box.
"I'm amazed that a penalty was given in the first half. I can't believe that we're allowing those sorts of penalties to be awarded," he said.
"We weren't clinical enough at times. We missed a couple of really good opportunities to get another goal. I wouldn't say we were unlucky today, but I'm really disappointed when we were 1-0 up that the penalty was given."
The Premier League champions go top of the table for the time being while West Ham stay in 13th position.