Skip to content

Commit fb9d7c3

Browse files
authored
Merge pull request #240 from AikidoSec/warn-setuser-shared-id
Add docs for SetUser with warning about shared user ID
2 parents 6c3d1e4 + b621049 commit fb9d7c3

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public void Configuration(IAppBuilder app)
207207
}
208208
```
209209

210+
## Guides
211+
212+
- [Troubleshooting](docs/troubleshooting.md) — common issues and how to debug Zen
213+
- [Azure Key Vault](docs/azure-key-vault.md) — using Azure Key Vault with Zen
214+
- [Set the current user](docs/user.md) — identify users for rate limiting, blocking, and attack reports
215+
210216
## Reporting to your Aikido Security dashboard
211217

212218
> Aikido is your no nonsense application security platform. One central system that scans your source code & cloud, shows you what vulnerabilities matter, and how to fix them - fast. So you can get back to building.

docs/user.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Setting the current user
2+
3+
## .NET Core
4+
5+
To set the current user, you can use the `Zen.SetUser` method in your middleware:
6+
7+
``` csharp
8+
using Aikido.Zen.DotNetCore;
9+
using Microsoft.AspNet.Identity;
10+
11+
// ...
12+
.UseRouting()
13+
.Use((context, next) =>
14+
{
15+
// Get the user from your authentication middleware
16+
var id = context.User?.Identity?.GetUserId();
17+
var name = context.User?.Identity?.Name;
18+
if (!string.IsNullOrEmpty(id))
19+
Zen.SetUser(id, name, context);
20+
return next();
21+
})
22+
.UseZenFirewall()
23+
```
24+
25+
## .NET Framework
26+
27+
In your `Global.asax.cs` file:
28+
29+
``` csharp
30+
public void Application_Start()
31+
{
32+
// other code
33+
Zen.SetUser(context => new User(context.User.Identity.GetUserId(), context.User.Identity.Name));
34+
Zen.Start();
35+
}
36+
```
37+
38+
Or if you are using OWIN, in your `Startup.cs` file:
39+
40+
``` csharp
41+
using Aikido.Zen.DotNetFramework;
42+
using Aikido.Zen.Core;
43+
using Microsoft.AspNet.Identity;
44+
45+
public void Configuration(IAppBuilder app)
46+
{
47+
// other code
48+
Zen.SetUser(context => new User(context.User.Identity.GetUserId(), context.User.Identity.Name));
49+
Zen.Start();
50+
}
51+
```
52+
53+
> [!WARNING]
54+
> Do not call `SetUser` with a shared user ID for unauthenticated or anonymous users (e.g. `SetUser("unauthenticated", "Anonymous")`). When a user is set, rate limiting is applied per user ID instead of per IP address. This means all anonymous users would share a single rate limit bucket and be blocked as a group. For unauthenticated users, simply don't call `SetUser` — rate limiting will automatically fall back to per-IP limiting.
55+
56+
## Benefits
57+
58+
Using `SetUser` has the following benefits:
59+
60+
- The user ID is used for more accurate rate limiting (you can change IP addresses, but you can't change your user ID).
61+
- Whenever attacks are detected, the user will be included in the report to Aikido.
62+
- The dashboard will show all your users, where you can also block them.
63+
- Passing the user's name is optional, but it can help you identify the user in the dashboard. You will be required to list Aikido Security as a subprocessor if you choose to share personal identifiable information (PII).

0 commit comments

Comments
 (0)