Rails gem 'viewing_as' adds read-only, audited admin impersonation with write guards
Delist My Data, a personal data removal service, built a customer account impersonation feature for its admin team that enforces read-only access and maintains a transparent audit log visible to customers. Existing Rails gems like pretender and devise_masquerade handle user-switching but lack write restrictions, session timeouts, or customer-facing audit trails. The team addressed this with two protection layers: a before_action that blocks non-GET/HEAD requests during impersonation, and ActiveRecord's while_preventing_writes to catch any writes that slip through via GET routes. The solution also uses signed cookies to lock session settings like read-only mode so nothing can be altered from the browser mid-session. Last week, the company extracted the feature into an open-source gem called viewing_as for other Rails developers to use.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in