The pair's previous deals had expired at the end of the 2021-2022 season.
However, Maldini had belatedly confirmed he would be staying at the club after a tough start to the close season.
Although Milan won the Serie A title last season with a team built in part by Maldini and Massara, the Rossoneri have struggled to add reinforcements for the coming campaign.
With Milan in the midst of a takeover, it could not compete with Newcastle United for highly rated defender Sven Botman.
The centre-back was said to be a primary target for Maldini, while reports have suggested Paris Saint-Germain has jumped the queue for Botman's Lille team-mate Renato Sanches.
However, Milan, Maldini and Massara have now come to an agreement that will see two key figures remain in their roles for at least another two seasons.
"This deal highlights the importance of continuity we see throughout the club as we continue to strengthen and grow," Milan said in a statement.