Reputation is known as a mechanism for market self-regulation, but where does reputation come from?
One possible mechanism would be that consumer surplus generates reputation. It may even be possible that transactions are always value-neutral. Consider the possibility that cost equals benefit in every transaction, where any additional consumer benefit above the price charged becomes reputation capital held by the consumer with respect to the firm.
Now, consider that firms face increased cost in the form of reputation cost, or foregone quantity demanded. This reputation cost can arise from the production of negative externalities. With a low enough reputation cost not only do consumers stop consuming, they can coordinate social action such as a boycott.
So we have a way for a market to internalize externalities, whether positive or negative. The market can compare the consumer surplus against the externality reputation cost in order to produce a socially optimal result.