An email sent from localhost should only be from a domain hosted there. How do I enforce this?

I've seen instructions on how to restrict the domain for authenticated accounts but localhost does not need authentication, it's a trusted IP. Trying to restrict the sender address just also blocks all incoming email from other domains.

I haven't been able to find any instructions on how to configure Postfix to do this...

if (IP=localhost) and (sender address != local_domain) then reject

Any suggestions appreciated. Otherwise I will have to try and write a custom bash script filter to do it, which I'm sure is over-kill.