Commit 1863b28
authored
Disambiguate 401 and 403 when accessing /projects (#719)
Previously, Editor-API would return a `403` error for any project access
that failed, including accesses that should have received a `401
Unauthorized` error.
This change checks the state of `current_user` to decide whether to
return `401` or `403`. This will then allow client applications like
Experience CS to properly route the user to either log in and retry or
present an error page with explanations as to why the `403` occurred.
## Status
- Related to RaspberryPiFoundation/experience-cs#1890
## Points for consideration:
- Security
- It may appear as if this change now leaks the existence of a given
project identifier to an unauthenticated user but they were being leaked
anyway. Some APIs return 404 to unauthenticated users accessing specific
record endpoints in order to prevent identifier enumeration, but
editor-api never did this anyway.
## What's changed?
- Modification to `api_controller.rb#denied` to:
- render `status: :forbidden` when the user is logged in but denied
access
- rebder `status: :unauthorized` when the user is NOT logged in and
denied access.
Previously, both conditions would render `:forbidden`.
## Steps to perform after deploying to production
Nothing required.
No changes are required in `editor-ui` either as 401 and 403 are
[already handled
identically](https://github.com/RaspberryPiFoundation/editor-ui/blob/eed2940b52f6e1d75e0f0c0bd8b2e36561ec2999/src/redux/reducers/loadProjectReducers.js#L40)
in `loadProjectReducers.js` in that codebase.1 parent e4b72f8 commit 1863b28
3 files changed
Lines changed: 38 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
81 | 88 | | |
82 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
83 | 93 | | |
84 | 94 | | |
85 | | - | |
86 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
91 | 113 | | |
92 | 114 | | |
93 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| |||
0 commit comments