It is a lifelong secret that she always knew
Luke (and the audience) know her identity is a great secret for her protection, as it is explained in the scene on Dagobah when Luke converses with the ghost of Kenobi.
BEN: Hmm. To protect you both from the Emperor, you were hidden from your father when you were born. The Emperor knew, as I did, if Anakin were to have any offspring, they would be a threat to him. That is the reason why your sister remains safely anonymous.
...
LUKE: But you can't let her get involved now, Ben. Vader will destroy her.
So Luke definitely knows to keep their relationship quiet. The question is-- how does Leia know?
The cynical explanation is that it is bad writing, and the screenwriter failed to differentiate between the audience's knowledge and Leia's.
A more charitable explanation can be discerned from Leia's immediate reaction to the astounding news:
LEIA: I know. Somehow...I've always known.
She immediately understands that she and Luke had a great, lifelong secret-- a secret that would be between only the two of them, that she would keep until the Emperor was dead and the danger was gone.