# Annoymous principal check

**URL:** <https://forum.dfinity.org/t/annoymous-principal-check/36534>\
**Category:** Developers\
**Tags:** rust\
**Created:** [October 24, 2024, 4:36pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534 "2024-10-24T16:36:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederico02](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@frederico02](https://forum.dfinity.org/u/frederico02)\
**Post date:** [October 24, 2024, 4:36pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/1 "2024-10-24T16:36:26Z")

</div>

I’m curious about the annoymous principal.

is it always the same principal regardless of what generates it? e.g from the rust package

```rust
Principal::anonymous()

```

or from a frontend that isn’t authenticated with II or Plug for example.

I want to guard against annoymous principals in my backend canister. what im doing now is

```rust
if caller == Principal::annoymous() {
  /// do stuff
}

```

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [October 24, 2024, 4:45pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/2 "2024-10-24T16:45:01Z")

</div>

That’ll do it - the standard anonymous principal has a string representation of `'2vxsx-fae'`.

Technically speaking though, any principal that ends with `0x04` will be classified as anonymous and won’t require a signature. The one used by the agents is just an empty seed with that classification. I don’t actually know if there’s a convenient way to guard against all anonymous identities, or to easily identify them.

[interface-spec → identity special cases → anonymous](https://internetcomputer.org/docs/current/references/ic-interface-spec#id-classes)

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [October 24, 2024, 7:26pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/3 "2024-10-24T19:26:12Z")

</div>

> [@anon74414410](#):
>
> any principal that ends with `0x04` will be classified as anonymous

Quite an interesting detail I didn’t know of. Anonymous identifiers that don’t require a signature.

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [October 24, 2024, 7:35pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/4 "2024-10-24T19:35:14Z")

</div>

Yeah, you could theoretically do something interesting with these - using a token “secret” to have a unique anonymous identity to manage sessions but still use anonymous calls that don’t require signatures

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [October 24, 2024, 7:47pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/5 "2024-10-24T19:47:39Z")

</div>

The spec you linked here says that `0x04` is _the_ anonymous identity. It doesn’t mention that there are other anonymous identities. Is that intentional that “longer” anonymous identities are accepted?

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [October 24, 2024, 8:22pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/6 "2024-10-24T20:22:50Z")

</div>

Hard to tell, spec is ambiguous. Especially putting ‘the’ next to ‘anonymous’.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/7/c/7cbf761bfa2365fe9f91d6ee0e03fe54b4ca39c0.png)  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/b/7/b737328e75f682e2273487b976982d70dd6d9197.png)

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [October 24, 2024, 9:02pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/7 "2024-10-24T21:02:26Z")

</div>

That’s my vague recollection from a conversation I had years ago, yes. How the actual replica handles this ambiguous detail in the spec today is another question

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [October 24, 2024, 9:14pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/8 "2024-10-24T21:14:03Z")

</div>

Apparently in practice it throws an error:

```auto
AgentError: Gateway returned an error: Code: 400 (Bad Request) Body: Missing signature from user: gagks-yqbai-bqiba

```

Tested by modifying the AnonymousIdentity to use

```auto
new Uint8Array([1, 2, 3, 4, ANONYMOUS_SUFFIX]);

```

in `agent-js`.

@bjoern care to weigh in on the intended behavior? Is there just one anonymous identity, or is it supposed to be a category of identity for agents to use?

---

<div class="post-metadata">

**Author:** ![bjoern](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bjoern/32/2100_2.png) [@bjoern](https://forum.dfinity.org/u/bjoern)\
**Post date:** [October 25, 2024, 7:27am UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/9 "2024-10-25T07:27:13Z")

</div>

The intended behavior is that there is exactly one anonymous principal, which is `0x04`. If ingress validation where to accept anything ending on `0x04` but not being exactly equal to `0x04`, I’d consider that a bug.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [October 25, 2024, 12:41pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/10 "2024-10-25T12:41:26Z")

</div>

Motoko has the `Principal.isAnonymous(p)` function that tests that p == Principal.fromBlob(“\04”).

---

<div class="post-metadata">

**Author:** ![frederico02](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@frederico02](https://forum.dfinity.org/u/frederico02)\
**Post date:** [October 25, 2024, 3:16pm UTC](https://forum.dfinity.org/t/annoymous-principal-check/36534/11 "2024-10-25T15:16:04Z")

</div>

Would be nice for the rust library to also have this
