You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When logged into the application I want to be able to view all my active sessions so that I can determine if my account has been compromised based on the session data, user agent, and IP address.
Issues
------
- Closes#69
Copy file name to clipboardexpand all lines: README.md
+85
Original file line number
Diff line number
Diff line change
@@ -1398,3 +1398,88 @@ end
1398
1398
> **What's Going On Here?**
1399
1399
>
1400
1400
> - We force SSL in production to prevent [session hijacking](https://guides.rubyonrails.org/security.html#session-hijacking). Even though the session is encrypted we want to prevent the cookie from being exposed through an insecure network. If it were exposed, a bad actor could sign in as the victim.
1401
+
1402
+
## Step 19: Capture Request Details for Each New Session
1403
+
1404
+
1. Add new columns to the active_sessions table.
1405
+
1406
+
```bash
1407
+
rails g migration add_request_columns_to_active_sessions user_agent:string ip_address:string
1408
+
rails db:migrate
1409
+
```
1410
+
1411
+
2. Update login method to capture request details.
> - We add columns to the `active_sessions` table to store data about when and where these sessions are being created. We are able to do this by tapping into the [request object](https://api.rubyonrails.org/classes/ActionDispatch/Request.html) and returning the [ip](https://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-ip) and user agent. The user agent is simply the browser and device.
> - We're simply showing any `active_session` associated with the `current_user`. By rendering the `user_agent`, `ip_address`, and `created_at` values we're giving the `current_user` all the information they need to know if there's any suspicious activity happening with their account. For example, if there's an `active_session` with a unfamiliar IP address or browser, this could indicate that the user's account has been compromised.
1484
+
> - Note that we also instantiate `@active_sessions` in the `update` method. This is because the `update` method renders the `edit` method during failure cases.
0 commit comments