Sub topic 14
Sessions, devices and API keys
Assume you can sign in to a centralized exchange, understand passwords and two-factor authentication, and change account settings. This chapter explains how an exchange remembers trusted browsers, how to remove access from lost devices, and how to limit automated access through API keys.
How sessions work
A session is the exchange's record that a recent login succeeded. After you enter your password and second factor, the server gives your browser a session cookie or token. The browser sends it with later requests, so you do not need to authenticate again for every page.
A session is different from a device. A device is a phone, computer, or browser profile. One device can have several sessions, and one account can have sessions on many devices.
A session can be stolen even when the password and authenticator app remain safe. Malware, a malicious browser extension, a compromised computer, or an unsafe shared computer may expose session data. An attacker with a valid session may bypass the normal login screen until the session expires or is revoked.
flowchart TD
A[Password and second factor] --> B[Exchange creates session]
B --> C[Browser stores cookie or token]
C --> D[Later requests use the session]
D --> E{Session revoked or expired?}
E -->|No| F[Access continues]
E -->|Yes| G[Sign in again]Review and revoke devices
Open the exchange's security or devices page and inspect each entry. Look for the device name, browser, approximate location, last activity, and creation time. Location data is approximate, so an unfamiliar city is a warning, not proof of compromise.
Revoke sessions that you no longer recognize or need. Revoke all other sessions after using a public computer, losing a device, or suspecting malware. Then change the account password and review withdrawals, address changes, API keys, and security notifications.
Common errors include:
- Treating a familiar device name as proof that the session is safe.
- Leaving old sessions active after selling or repairing a phone.
- Assuming changing a password always revokes every existing session. Check the exchange's documented behavior.
- Signing in on a shared computer and saving the session in the browser.
API keys and least privilege
An API key lets software access an exchange account without interactive sign-in. A key normally has an identifier and a secret. The secret may be shown only once, so store it in a password manager or secret store, never in source code, chat, screenshots, or shell history.
Give each application its own key. Enable only the permissions it needs:
| Permission | Typical use | Risk |
|---|---|---|
| Read-only | Portfolio or price monitoring | Exposes account data |
| Trading | Automated orders | Can lose funds through bad logic |
| Withdrawals | Moving assets out | Highest risk |
Disable withdrawals unless the application truly requires them. Use IP address restrictions when the software runs from a stable server. Set exchange-side spending or withdrawal limits when available. Rotate keys after a suspected leak and delete unused keys.
A safe request path looks like this:
Application -> API key with limited permissions -> Exchange API
|
-> IP restriction and audit logsPractical hygiene
Use separate keys for production bots, testing, and portfolio tools. Keep the secret outside configuration files tracked by version control. Monitor API activity and compare orders with the application's expected behavior. A read-only key is usually enough for dashboards.
Exercise
You find an API key named “old bot” with trading and withdrawal permissions, but you no longer use the bot. What should you do?
Show answer
Disable or delete the key immediately, review recent API activity and withdrawals, and create a new least-privilege key only if the bot is still needed.