### Changed
- Return HTTP error 413 when uploading an avatar or banner that's above the configured upload limit instead of a 500.
- Non-admin users now cannot register `admin` scope tokens (not security-critical, they didn't work before, but you _could_ create them)
+ - Admin scopes will be dropped on create
- Rich media will now backoff for 20 minutes after a failure
### Upgrade notes
%{
key: :pool_size,
type: :integer,
- description:
- "Number of concurrent outbound HTTP requests to allow. Default 50.",
+ description: "Number of concurrent outbound HTTP requests to allow. Default 50.",
suggestions: [50]
},
%{
defp do_create_authorization(%User{} = user, %App{} = app, requested_scopes)
when is_list(requested_scopes) do
with {:account_status, :active} <- {:account_status, User.account_status(user)},
+ requested_scopes <- Scopes.filter_admin_scopes(requested_scopes, user),
{:ok, scopes} <- validate_scopes(user, app, requested_scopes),
{:ok, auth} <- Authorization.create_authorization(app, user, scopes) do
{:ok, auth}
end
end
+ @spec filter_admin_scopes([String.t()], Pleroma.User.t()) :: [String.t()]
+ @doc """
+ Remove admin scopes for non-admins
+ """
+ def filter_admin_scopes(scopes, %Pleroma.User{is_admin: true}), do: scopes
+
+ def filter_admin_scopes(scopes, _user) do
+ drop_scopes = OAuthScopesPlug.filter_descendants(scopes, ["admin"])
+ Enum.reject(scopes, fn scope -> Enum.member?(drop_scopes, scope) end)
+ end
+
defp validate_scopes_are_supported(scopes, app_scopes) do
case OAuthScopesPlug.filter_descendants(scopes, app_scopes) do
^scopes -> {:ok, scopes}
describe "POST /oauth/authorize" do
test "redirects with oauth authorization, " <>
- "granting requested app-supported scopes to both admin users" do
+ "granting requested app-supported scopes to admin users" do
app_scopes = ["read", "write", "admin", "secret_scope"]
app = insert(:oauth_app, scopes: app_scopes)
redirect_uri = OAuthController.default_redirect_uri(app)
redirect_uri = OAuthController.default_redirect_uri(app)
non_admin = insert(:user, is_admin: false)
- scopes_subset = ["read:subscope", "write"]
+ scopes_subset = ["read:subscope", "write", "admin", "admin:metrics"]
# In case scope param is missing, expecting _all_ app-supported scopes to be granted
conn =
assert %{"state" => "statepassed", "code" => code} = query
auth = Repo.get_by(Authorization, token: code)
assert auth
- assert auth.scopes == scopes_subset
+ assert auth.scopes == ["read:subscope", "write"]
end
test "authorize from cookie" do