Sanitize shareWith

Backport of #2062 to stable45