Urgent.News

What's breaking now, across thousands of outlets.

Tech

Read-only user impersonation in Rails

Many support tools eventually grow a "log in as this customer" feature. Ours had a problem the usual gems don't solve. The people on the other side of the button are customers of a service containing sensitive user data. Delist My Data clients give us the history of their personal information that we will work to have taken down across the web. We want our admins to be restricted from ordering…

Many support tools have a feature to "log in as this customer." However, the existing gems did not solve the problem of impersonating customers with sensitive data. Delist My Data, a service that helps users delete their personal information from the web, needed a way to restrict administrators from performing sensitive actions while impersonating customers.

The team wanted to inform customers about when administrators viewed their account information. They built this functionality and released it as a gem called ViewingAs. The existing gems have limitations, such as not refusing writes or keeping a log of actions taken during impersonation. ViewingAs addresses these issues by implementing two layers of protection.

The first layer prevents non-GET/HEAD requests during an impersonation session. The second layer intercepts attempts to perform write actions and logs them at error level. A read-only setting is also provided, which can be disabled if needed. The gem includes a consent lambda that determines whether impersonation is allowed based on the customer's preferences.

The security of the system is ensured by signing the cookie containing the impersonation information and re-validating it on every request. This prevents session expiration or withdrawal of consent from causing unintended writes by the impersonating user.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Record One Nested Decision, Then Extract a Single Predicate

A pricing function still folds region rules, bulk surcharges, and coupon stacking into one nested block. A teammate asks an assistant to tidy that module before a tax change lands next week.

  • Nested pricing function consolidates multiple rules into one block of code
  • Colleague suggests refactoring module ahead of tax change
  • Record one nested decision on hot path before extracting single predicate

Stop exporting design tokens to JSON for your web apps

A PR review last Thursday morning triggered this thought. A developer had written a 40-line utility function in our main web repository.

  • Excessive JSON use for design tokens causes unnecessary complexity.
  • CSS variables are optimized for reading, cascading, and updating design values.
  • Design System Sync Figma plugin exports tokens directly to CSS variables.

More from Wednesday 23 September →