The 28-year-old Scotland international has been in impressive form for the Welsh club in their debut Premier League campaign and manager Ole Gunnar Solskjaer is delighted to have secured his services long term.
The Norwegian told Cardiff Player: "This is fantastic - we're delighted to have been able to tie David down for the foreseeable future.
"He really enjoys being at Cardiff City and was very keen to stay with our Football Club. I was very happy when things were concluded today.
"I think this gives everybody at the Club a boost. We know now that we have one of the best goalkeepers in the country committed to us for years to come.
"This is welcome news ahead of Saturday's South-Wales derby and it's great timing for him and us as we look towards the remainder of the season.
"We're trying to build towards the future of course, and David has shown that he's one of the very best. This is a signal that we are serious as to our intentions for the future and that we are committed to keeping the best players here at Cardiff City."
Marshall joined the Bluebirds from Norwich City in 2009 for a fee of £500,000.