Commit 90c2294
committed
fix(security): move GitHub OAuth token from sessionStorage to React state
AuthContext.jsx stored the GitHub OAuth access token in sessionStorage:
sessionStorage.setItem(`gh_token_${authUser.uid}`, accessToken)
sessionStorage is accessible to any JavaScript running on the page. An
XSS injection (e.g. via a third-party script or unsanitised user input)
can exfiltrate the token, giving the attacker the same GitHub API access
as the logged-in user for the token's lifetime.
The comment describing the approach as "securely (non-persistent across
tabs for security)" was inaccurate: sessionStorage is still readable by
all scripts on the same origin.
Changes in src/context/AuthContext.jsx:
- Added ghAccessToken state variable (useState(null)).
- setGhAccessToken(accessToken) replaces sessionStorage.setItem() on
login.
- setGhAccessToken(null) replaces sessionStorage.removeItem() on logout.
- fetchGitHubStats reads from ghAccessToken state instead of
sessionStorage.getItem().
The token remains in React component memory and is never written to
any Web Storage API, making it inaccessible to injected scripts.
The trade-off is that the token is lost on page refresh, but
fetchGitHubStats is called immediately after login so this is acceptable.
Closes #801 parent 4efa207 commit 90c2294
1 file changed
Lines changed: 15 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| |||
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
95 | | - | |
96 | | - | |
| 101 | + | |
| 102 | + | |
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| |||
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| 159 | + | |
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
163 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
164 | 172 | | |
165 | | - | |
| 173 | + | |
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
| |||
0 commit comments