The 26-year-old full-back joined the Buddies on a one-year deal from Ross County last summer.
Fraser said: "It is brilliant for me moving forward. I know where I will be the next two years.
"I have thoroughly enjoyed this season. I have played a lot of games, the team has done well and I have fitted into that so I am really looking forward to the next two years.
"We have got to two semi-finals and obviously we have a big game to look forward to on Sunday but next season hopefully we can continue the consistency in the league and push forward."
Fraser won the League Cup with the Staggies in 2016 and would like nothing better than to add a Scottish Cup winners' medal to his collection.
He said: "To win a trophy at any part of your career is massive.
"If you ask all footballers, it is massive for them.
"But just one step at a time, Sunday is the next big one and we will take it from there.
"If we do the business on Sunday we will have a big day to look forward to but first and foremost we have a big task on our hands, but we look forward to it."
Boss Jim Goodwin said: "I am really pleased to get Marcus tied down for another couple of seasons.
"He has been a star performer for us from day one and he will no doubt be in the running for a player of the year award as well.
"It is a step in the right direction and to extend the contracts of those players who deserve to be rewarded is something we have been trying to do since the turn of the year."