eliotsykes / rails-security-checklist

:key: Community-driven Rails Security Checklist (see our GitHub Issues for the newest checks that aren't yet in the README)
1.36k stars 96 forks source link

Turbo signed-stream-name never expires #85

Open eliotsykes opened 1 year ago

eliotsykes commented 1 year ago

Turbo's signed stream names provided by turbo_stream_from never expire: https://github.com/hotwired/turbo-rails/issues/61

Example of how this could be a problem

Potential mitigations?

lu-x commented 5 months ago

This team member is removed from the @team. The removed team member can still receive data from the turbo stream as they have the signed-stream-name.

I think as a first step you can add authentication on the ActionCable level, this will prevent the user from connecting and subscribing to any channel without a valid session.
If the user has a valid session (for example with a new account) i guess authorization has to take place during the subscription to the specific channel.

Example: https://github.com/hotwired/turbo-rails/blob/main/app/channels/turbo/streams_channel.rb#L11 However, i'm not sure what's a good way to authorise the user, maybe it's possible to include a user id in the stream name and then compare it to the user id retrieved from the session (?).