---
title: 'ARCE0002: A command or query is both anonymous and restricted'
editUrl: https://github.com/Cratis/Arc.Elixir/edit/main/Documentation/code-analysis/ARCE0002.md
description: ARCE0002 reports an Elixir command or query that sets allow_anonymous together with roles, policy or authenticated, which silently removes the restriction.
lastUpdated: 2026-11-14T00:00:00.000Z
---


**Kind:** module. **Default severity:** error. The .NET counterpart is `ARC0019`.

## Rule

A declaration that sets `allow_anonymous: true` together with `roles:`, `policy:` or `authenticated:` contradicts itself. Arc checks `allow_anonymous` first and lets the caller through, so the restriction is silently ignored. The rule checks the module-level `authorize` of a command or read model and the `authorize:` option of each `@query` and `@observe`.

## Why it matters

The author wrote a restriction and believes it holds. It does not: the command or query is open to everyone. This is an access control mistake, which is why it defaults to an error.

## Bad

```elixir
defmodule MyApp.Authors.Registration.RemoveAuthor do
  use Arc.Command

  authorize allow_anonymous: true, roles: ["admin"]

  # ...
end
```

```elixir
@query authorize: [allow_anonymous: true, policy: :can_list]
def all_authors(_args, _ctx), do: # ...
```

## Good

Keep the one you mean:

```elixir
authorize roles: ["admin"]
```

```elixir
@query allow_anonymous: true
def all_authors(_args, _ctx), do: # ...
```

A query may legitimately differ from its module: `@query allow_anonymous: true` inside a module that says `authorize roles: [...]` overrides the module for that query, and is not reported.

## How to fix

Decide who may call it and delete the other half of the declaration.

## Related rules

- [Authorization and identity](/arc/backend/elixir/authorization-and-identity/) explains how requirements are checked.
