im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! `GET /logout` and `POST /logout`: OpenID Connect RP-Initiated Logout (contracts.md 2.5), and the |
| 2 | //! sign-out button of the account menu, which posts to the same path with no hint. |
| 3 | //! |
| 4 | //! The rules, in order: |
| 5 | //! - An `id_token_hint` is an ID token of ours: the signature and `iss` are checked, the expiry is not |
| 6 | //! (an expired hint still names a session). A hint that fails is ignored, as if it were absent. |
| 7 | //! - The client is named by the hint's `aud`. A redirect happens only when the client is enabled and |
| 8 | //! `post_logout_redirect_uri` equals one of its registered URIs exactly. Otherwise the answer is the |
| 9 | //! signed-out page, never a redirect. |
| 10 | //! - `state` is echoed on the redirect only when it is usable (bounded, no control characters). |
| 11 | //! - A `GET` never ends a session: a link or an image on another site must not sign the browser out. A |
| 12 | //! `GET` with a session answers with a form that carries the session's CSRF token. The form posts itself |
| 13 | //! (`data-auto-submit`, run by `assets/pages.js`) only when the hint is this browser's own: its `sid` is |
| 14 | //! the viewer's session and its `sub` is the viewer. That is a client's sign-out, so the browser returns |
| 15 | //! to the client without a second click. Any other hint (anyone can hold a valid ID token of their own) |
| 16 | //! leaves the person to click. The visible button is the fallback without JS. Only the `POST` ends the |
| 17 | //! session, and it checks that token before anything changes. |
| 18 | //! - Ending the session is `im`'s own: the browser session is deleted (and its clients told by |
| 19 | //! back-channel logout, in the store's transaction). When the hint names another session of the same |
| 20 | //! person, that one ends too. |
| 21 | |
| 22 | use ; |
| 23 | use AuditAction; |
| 24 | use MAX_ECHO_BYTES; |
| 25 | use Store; |
| 26 | use EndReason; |
| 27 | use Deserialize; |
| 28 | use Value; |
| 29 | use Result; |
| 30 | use ; |
| 31 | use Form; |
| 32 | use ; |
| 33 | use page; |
| 34 | use ; |
| 35 | |
| 36 | use signing; |
| 37 | use ; |
| 38 | use crate; |
| 39 | use crate; |
| 40 | use crateLang; |
| 41 | use crate; |
| 42 | use crateTopic; |
| 43 | use crateAppState; |
| 44 | use crate; |
| 45 | |
| 46 | /// The parameters of a logout request, from the query (GET) or the form (POST). Every field is optional. |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | /// What a valid hint says: the person it was issued to and the session it names. |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// The checked request: the hint (if valid), the redirect to make (if allowed) and the echoed state. |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | /// Tells a state apart from a value that must not be echoed. |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | /// Verifies an ID token of ours for logout. `None` when it is not an ID token of this provider, or its |
| 86 | /// signature or issuer is wrong. The expiry is not checked. Returns the client it was issued to and the |
| 87 | /// hint's claims that matter here. |
| 88 | async |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// Checks the request. Nothing here changes state. |
| 120 | async |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | /// The redirect to the client, with the state when there is one. `None` means the signed-out page. |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | /// Ends the browser's session and, when the hint names another session of the same person, that one |
| 162 | /// too. Audits the sign-out. |
| 163 | async |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | /// `GET /logout`. Never ends a session: with one, it shows the confirmation form. |
| 188 | |
| 189 | async |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | /// `POST /logout`. Without a session there is nothing to end, so no CSRF check applies. |
| 221 | |
| 222 | async |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | /// The form that signs the browser out (the GET answer with a session). It posts itself. |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | /// The confirmation page, or the signed-out page when `confirm` is `None`. The form posts to this same |
| 251 | /// path and carries everything the POST needs to finish the same request. |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 |