authenik8-core 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -0
- package/README.md +40 -350
- package/THREAT_MODEL.md +162 -0
- package/dist/agent/agentIdentity.d.ts +13 -1
- package/dist/agent/agentIdentity.d.ts.map +1 -1
- package/dist/agent/agentIdentity.js +203 -51
- package/dist/agent/agentIdentity.js.map +1 -1
- package/dist/audit/auditDispatcher.d.ts +13 -0
- package/dist/audit/auditDispatcher.d.ts.map +1 -0
- package/dist/audit/auditDispatcher.js +212 -0
- package/dist/audit/auditDispatcher.js.map +1 -0
- package/dist/audit/types.d.ts +40 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/{types/storage.js → audit/types.js} +1 -1
- package/dist/audit/types.js.map +1 -0
- package/dist/auth/guestModeService.d.ts +3 -5
- package/dist/auth/guestModeService.d.ts.map +1 -1
- package/dist/auth/guestModeService.js +15 -14
- package/dist/auth/guestModeService.js.map +1 -1
- package/dist/auth/jwk.d.ts +4 -1
- package/dist/auth/jwk.d.ts.map +1 -1
- package/dist/auth/jwk.js +181 -41
- package/dist/auth/jwk.js.map +1 -1
- package/dist/auth/jwtAuth.d.ts +17 -1
- package/dist/auth/jwtAuth.d.ts.map +1 -1
- package/dist/auth/jwtAuth.js +191 -27
- package/dist/auth/jwtAuth.js.map +1 -1
- package/dist/auth/refreshService.d.ts +12 -1
- package/dist/auth/refreshService.d.ts.map +1 -1
- package/dist/auth/refreshService.js +199 -48
- package/dist/auth/refreshService.js.map +1 -1
- package/dist/auth/requestIdentity.d.ts +4 -0
- package/dist/auth/requestIdentity.d.ts.map +1 -0
- package/dist/auth/requestIdentity.js +16 -0
- package/dist/auth/requestIdentity.js.map +1 -0
- package/dist/auth/sessionStore.d.ts +5 -1
- package/dist/auth/sessionStore.d.ts.map +1 -1
- package/dist/auth/sessionStore.js +103 -16
- package/dist/auth/sessionStore.js.map +1 -1
- package/dist/auth/tokenFingerprint.d.ts +3 -0
- package/dist/auth/tokenFingerprint.d.ts.map +1 -0
- package/dist/auth/tokenFingerprint.js +13 -0
- package/dist/auth/tokenFingerprint.js.map +1 -0
- package/dist/authorization/authorizationService.d.ts +22 -0
- package/dist/authorization/authorizationService.d.ts.map +1 -0
- package/dist/authorization/authorizationService.js +132 -0
- package/dist/authorization/authorizationService.js.map +1 -0
- package/dist/authorization/types.d.ts +10 -0
- package/dist/authorization/types.d.ts.map +1 -0
- package/dist/authorization/types.js +3 -0
- package/dist/authorization/types.js.map +1 -0
- package/dist/createAuthenik8.d.ts.map +1 -1
- package/dist/createAuthenik8.js +87 -18
- package/dist/createAuthenik8.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/adminService.d.ts +3 -5
- package/dist/middleware/adminService.d.ts.map +1 -1
- package/dist/middleware/adminService.js +18 -19
- package/dist/middleware/adminService.js.map +1 -1
- package/dist/oauth/adapters/memoryAdapter.d.ts.map +1 -1
- package/dist/oauth/adapters/memoryAdapter.js +47 -17
- package/dist/oauth/adapters/memoryAdapter.js.map +1 -1
- package/dist/oauth/adapters/redisAdapter.d.ts +1 -1
- package/dist/oauth/adapters/redisAdapter.d.ts.map +1 -1
- package/dist/oauth/adapters/redisAdapter.js +163 -84
- package/dist/oauth/adapters/redisAdapter.js.map +1 -1
- package/dist/oauth/brain/identityEngine.d.ts +13 -14
- package/dist/oauth/brain/identityEngine.d.ts.map +1 -1
- package/dist/oauth/brain/identityEngine.js +162 -68
- package/dist/oauth/brain/identityEngine.js.map +1 -1
- package/dist/oauth/brain/identityPolicy.d.ts +7 -4
- package/dist/oauth/brain/identityPolicy.d.ts.map +1 -1
- package/dist/oauth/brain/identityPolicy.js +15 -2
- package/dist/oauth/brain/identityPolicy.js.map +1 -1
- package/dist/oauth/core.d.ts +8 -4
- package/dist/oauth/core.d.ts.map +1 -1
- package/dist/oauth/core.js +59 -16
- package/dist/oauth/core.js.map +1 -1
- package/dist/oauth/identityValidation.d.ts +14 -0
- package/dist/oauth/identityValidation.d.ts.map +1 -0
- package/dist/oauth/identityValidation.js +90 -0
- package/dist/oauth/identityValidation.js.map +1 -0
- package/dist/oauth/providerSecurity.d.ts +13 -0
- package/dist/oauth/providerSecurity.d.ts.map +1 -0
- package/dist/oauth/providerSecurity.js +100 -0
- package/dist/oauth/providerSecurity.js.map +1 -0
- package/dist/oauth/providers/github.d.ts +2 -1
- package/dist/oauth/providers/github.d.ts.map +1 -1
- package/dist/oauth/providers/github.js +97 -20
- package/dist/oauth/providers/github.js.map +1 -1
- package/dist/oauth/providers/google.d.ts +3 -2
- package/dist/oauth/providers/google.d.ts.map +1 -1
- package/dist/oauth/providers/google.js +81 -24
- package/dist/oauth/providers/google.js.map +1 -1
- package/dist/oauth/state.d.ts +9 -0
- package/dist/oauth/state.d.ts.map +1 -0
- package/dist/oauth/state.js +55 -0
- package/dist/oauth/state.js.map +1 -0
- package/dist/oauth/types.d.ts +48 -23
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/oauth/types.js +0 -1
- package/dist/oauth/types.js.map +1 -1
- package/dist/redis/keyNamespace.d.ts +4 -0
- package/dist/redis/keyNamespace.d.ts.map +1 -0
- package/dist/redis/keyNamespace.js +34 -0
- package/dist/redis/keyNamespace.js.map +1 -0
- package/dist/redis/redisService.d.ts.map +1 -1
- package/dist/redis/redisService.js +17 -2
- package/dist/redis/redisService.js.map +1 -1
- package/dist/risk/redisSessionRiskStore.d.ts +13 -0
- package/dist/risk/redisSessionRiskStore.d.ts.map +1 -0
- package/dist/risk/redisSessionRiskStore.js +29 -0
- package/dist/risk/redisSessionRiskStore.js.map +1 -0
- package/dist/risk/sessionRiskService.d.ts +31 -0
- package/dist/risk/sessionRiskService.d.ts.map +1 -0
- package/dist/risk/sessionRiskService.js +311 -0
- package/dist/risk/sessionRiskService.js.map +1 -0
- package/dist/risk/types.d.ts +50 -0
- package/dist/risk/types.d.ts.map +1 -0
- package/dist/risk/types.js +3 -0
- package/dist/risk/types.js.map +1 -0
- package/dist/security/ipService.d.ts +27 -12
- package/dist/security/ipService.d.ts.map +1 -1
- package/dist/security/ipService.js +238 -80
- package/dist/security/ipService.js.map +1 -1
- package/dist/security/limiter.d.ts +7 -5
- package/dist/security/limiter.d.ts.map +1 -1
- package/dist/security/limiter.js +70 -29
- package/dist/security/limiter.js.map +1 -1
- package/dist/security/requestContext.d.ts +15 -0
- package/dist/security/requestContext.d.ts.map +1 -0
- package/dist/security/requestContext.js +156 -0
- package/dist/security/requestContext.js.map +1 -0
- package/dist/storage/RedisTokenStore.d.ts +2 -2
- package/dist/storage/RedisTokenStore.d.ts.map +1 -1
- package/dist/storage/RedisTokenStore.js +10 -2
- package/dist/storage/RedisTokenStore.js.map +1 -1
- package/dist/types/config.d.ts +41 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/public.d.ts +39 -18
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/tokens.d.ts +7 -1
- package/dist/types/tokens.d.ts.map +1 -1
- package/dist/utility/safeString.d.ts +2 -0
- package/dist/utility/safeString.d.ts.map +1 -0
- package/dist/utility/safeString.js +13 -0
- package/dist/utility/safeString.js.map +1 -0
- package/docs/agent-service-identity.md +69 -0
- package/docs/api-overview.md +56 -0
- package/docs/architecture.md +41 -0
- package/docs/authorization-tenants-audit.md +53 -0
- package/docs/final-thought.md +9 -0
- package/docs/getting-started.md +57 -0
- package/docs/how-it-works-internally.md +15 -0
- package/docs/key-rotation.md +13 -0
- package/docs/refresh-token-rotation.md +15 -0
- package/docs/replay-attack-detection.md +16 -0
- package/docs/replay-attack-prevention.md +15 -0
- package/docs/repository-setup.md +13 -0
- package/docs/requirements.md +31 -0
- package/docs/secure-refresh-flow.md +21 -0
- package/docs/security-audit.md +133 -0
- package/docs/security-layer.md +54 -0
- package/docs/session-risk-quarantine.md +36 -0
- package/docs/stateful-session-control.md +16 -0
- package/docs/testing.md +37 -0
- package/docs/threats-addressed.md +25 -0
- package/docs/use-cases.md +12 -0
- package/docs/what-authenik8-does.md +17 -0
- package/docs/why-authenik8.md +15 -0
- package/docs/why-stateful-matters.md +11 -0
- package/package.json +16 -6
- package/dist/oauth/brain/identityResolver.d.ts +0 -7
- package/dist/oauth/brain/identityResolver.d.ts.map +0 -1
- package/dist/oauth/brain/identityResolver.js +0 -32
- package/dist/oauth/brain/identityResolver.js.map +0 -1
- package/dist/oauth/userStore.d.ts +0 -11
- package/dist/oauth/userStore.d.ts.map +0 -1
- package/dist/oauth/userStore.js +0 -46
- package/dist/oauth/userStore.js.map +0 -1
- package/dist/storage/userStorage.d.ts +0 -8
- package/dist/storage/userStorage.d.ts.map +0 -1
- package/dist/storage/userStorage.js +0 -28
- package/dist/storage/userStorage.js.map +0 -1
- package/dist/types/storage.d.ts +0 -14
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
```text
|
|
4
|
+
┌─────────────────┐
|
|
5
|
+
│ Client │
|
|
6
|
+
│ Web / Mobile │
|
|
7
|
+
└────────┬────────┘
|
|
8
|
+
│
|
|
9
|
+
▼
|
|
10
|
+
┌─────────────────┐
|
|
11
|
+
│ API / Backend │
|
|
12
|
+
└────────┬────────┘
|
|
13
|
+
│
|
|
14
|
+
▼
|
|
15
|
+
┌────────────────────────────┐
|
|
16
|
+
│ Authenik8-core │
|
|
17
|
+
├────────────────────────────┤
|
|
18
|
+
│ JWT signing/verification │
|
|
19
|
+
│ Refresh rotation/replay │
|
|
20
|
+
│ Authorization/tenancy │
|
|
21
|
+
│ Audit and risk signals │
|
|
22
|
+
│ Agent identity │
|
|
23
|
+
│ Security middleware │
|
|
24
|
+
└─────────────┬──────────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌────────────────────────────┐
|
|
28
|
+
│ Redis │
|
|
29
|
+
├────────────────────────────┤
|
|
30
|
+
│ Session fingerprints │
|
|
31
|
+
│ Refresh-family state │
|
|
32
|
+
│ Revocation/quarantine │
|
|
33
|
+
│ Rate and signal windows │
|
|
34
|
+
└────────────────────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Audit sinks and identity registries are application-owned dependencies. The SDK
|
|
38
|
+
uses narrow interfaces for those dependencies so their storage and delivery
|
|
39
|
+
choices remain outside the authentication core.
|
|
40
|
+
|
|
41
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Authorization, Tenants, and Audit Events
|
|
2
|
+
|
|
3
|
+
Authorization middleware authenticates first, uses exact claim matching, and
|
|
4
|
+
fails closed when a configured tenant cannot be resolved or is not granted:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const auth = await createAuthenik8({
|
|
8
|
+
jwt,
|
|
9
|
+
refreshSecret,
|
|
10
|
+
redis,
|
|
11
|
+
authorization: {
|
|
12
|
+
resolveTenant: (req) => req.params.tenantId,
|
|
13
|
+
},
|
|
14
|
+
audit: {
|
|
15
|
+
delivery: "best-effort",
|
|
16
|
+
sinks: [
|
|
17
|
+
{
|
|
18
|
+
write: async (event) => securityEventRepository.append(event),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.get(
|
|
25
|
+
"/tenants/:tenantId/invoices",
|
|
26
|
+
auth.requireRole("billing-admin", "owner"),
|
|
27
|
+
auth.requirePermission("invoice:read"),
|
|
28
|
+
handler,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const tokens = await auth.issueTokens(
|
|
32
|
+
{
|
|
33
|
+
userId: "user_1",
|
|
34
|
+
email: "user@example.com",
|
|
35
|
+
roles: ["billing-admin"],
|
|
36
|
+
permissions: ["invoice:read"],
|
|
37
|
+
scopes: ["profile:read"],
|
|
38
|
+
tenantIds: ["tenant_1"],
|
|
39
|
+
},
|
|
40
|
+
{ ip: request.ip, device: request.headers["user-agent"] },
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Roles use any-of matching. Required permissions and scopes use all-of matching.
|
|
45
|
+
Checks build a set of granted claims and then inspect each required claim,
|
|
46
|
+
avoiding pairwise comparisons.
|
|
47
|
+
|
|
48
|
+
The SDK owns the versioned audit-event envelope. Applications own durable
|
|
49
|
+
console, file, queue, SIEM, or webhook sinks. Best-effort delivery protects
|
|
50
|
+
authentication availability; strict delivery rolls back issuance when a sink
|
|
51
|
+
cannot accept the event.
|
|
52
|
+
|
|
53
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Final Thought
|
|
2
|
+
|
|
3
|
+
JWT alone establishes signed claims; it is not a complete authentication
|
|
4
|
+
system.
|
|
5
|
+
|
|
6
|
+
Authenik8-core adds token lifecycle, revocation, authorization, audit, and risk
|
|
7
|
+
controls around those claims.
|
|
8
|
+
|
|
9
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
Generate and persist an ES256 private JWK once. Do not generate a new key every
|
|
4
|
+
time the process starts.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import {
|
|
8
|
+
createAuthenik8,
|
|
9
|
+
generateSigningJwk,
|
|
10
|
+
verifyAccessTokenWithJwks,
|
|
11
|
+
} from "authenik8-core";
|
|
12
|
+
|
|
13
|
+
const privateJwk = await generateSigningJwk("2026-07-primary");
|
|
14
|
+
// Store privateJwk in your secret manager before constructing the engine.
|
|
15
|
+
|
|
16
|
+
const auth = await createAuthenik8({
|
|
17
|
+
jwt: {
|
|
18
|
+
keys: [privateJwk],
|
|
19
|
+
activeKid: "2026-07-primary",
|
|
20
|
+
issuer: "https://api.example.com",
|
|
21
|
+
audience: "example-api",
|
|
22
|
+
},
|
|
23
|
+
refreshSecret: process.env.REFRESH_SECRET!,
|
|
24
|
+
redisKeyPrefix: "example-api:production",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.get("/.well-known/jwks.json", (_req, res) => res.json(auth.getJwks()));
|
|
28
|
+
app.get("/protected", auth.requireAuth, (_req, res) => res.sendStatus(204));
|
|
29
|
+
|
|
30
|
+
const tokens = await auth.issueTokens({
|
|
31
|
+
userId: "user_1",
|
|
32
|
+
email: "test@example.com",
|
|
33
|
+
});
|
|
34
|
+
const payload = await auth.verifyToken(tokens.accessToken);
|
|
35
|
+
|
|
36
|
+
// A separate service can verify with public keys only (or pass a JWKS URL).
|
|
37
|
+
const publicPayload = await verifyAccessTokenWithJwks(
|
|
38
|
+
tokens.accessToken,
|
|
39
|
+
auth.getJwks(),
|
|
40
|
+
{ issuer: "https://api.example.com", audience: "example-api" },
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`verifyToken()` verifies signature and claims only. Use
|
|
45
|
+
`verifyActiveToken()` or `requireAuth` whenever Redis revocation and
|
|
46
|
+
quarantine must be enforced.
|
|
47
|
+
|
|
48
|
+
`jwtSecret` remains available as a deprecated JOSE/HS256 migration path. It
|
|
49
|
+
does not provide a public JWKS and should not be used for new applications.
|
|
50
|
+
If it is temporarily required, both it and `refreshSecret` need at least 32
|
|
51
|
+
bytes of independent random material.
|
|
52
|
+
|
|
53
|
+
The host application must load its environment before construction (for
|
|
54
|
+
example with a runtime `--env-file` option or an application-owned dotenv
|
|
55
|
+
bootstrap). Importing Authenik8-core never changes `process.env`.
|
|
56
|
+
|
|
57
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# How It Works Internally
|
|
2
|
+
|
|
3
|
+
Authenik8-core combines signed JWT claims with Redis-backed lifecycle state.
|
|
4
|
+
Signature verification establishes token authenticity; state-aware verification
|
|
5
|
+
additionally enforces revocation, rotation, and quarantine.
|
|
6
|
+
|
|
7
|
+
Internal flows are documented separately:
|
|
8
|
+
|
|
9
|
+
- [Refresh-token rotation](./refresh-token-rotation.md)
|
|
10
|
+
- [Replay-attack detection](./replay-attack-detection.md)
|
|
11
|
+
- [Stateful session control](./stateful-session-control.md)
|
|
12
|
+
- [Security layer](./security-layer.md)
|
|
13
|
+
- [Why stateful authentication matters](./why-stateful-matters.md)
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Key Rotation
|
|
2
|
+
|
|
3
|
+
1. Generate and securely persist a new key with a unique `kid`.
|
|
4
|
+
2. Put the new private JWK and previous verification keys in `jwt.keys`.
|
|
5
|
+
3. Set `activeKid` to the new key. New tokens now carry the new `kid`.
|
|
6
|
+
4. Keep old public keys until every token they signed has expired, then remove
|
|
7
|
+
them.
|
|
8
|
+
|
|
9
|
+
`auth.getJwks()` strips private key material and returns every configured public
|
|
10
|
+
verification key. Verification enforces ES256, `kid`, issuer, audience, expiry,
|
|
11
|
+
and token purpose.
|
|
12
|
+
|
|
13
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Refresh-Token Rotation
|
|
2
|
+
|
|
3
|
+
Each refresh token includes a unique identifier (`jti`). Redis stores a SHA-256
|
|
4
|
+
fingerprint of the current token for its refresh family.
|
|
5
|
+
|
|
6
|
+
During refresh:
|
|
7
|
+
|
|
8
|
+
1. The token signature, purpose, issuer, audience, and expiry are validated.
|
|
9
|
+
2. The supplied token fingerprint is compared with the current family record.
|
|
10
|
+
3. A Redis lock and compare-and-set transition allow only one rotation.
|
|
11
|
+
4. The old token is invalidated and a new token is issued with a new `jti`.
|
|
12
|
+
5. If a dependent security operation fails, the affected family is rolled back
|
|
13
|
+
or revoked rather than leaving partially issued credentials.
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Replay-Attack Detection
|
|
2
|
+
|
|
3
|
+
When a previously rotated refresh token is reused, its fingerprint no longer
|
|
4
|
+
matches the current family record.
|
|
5
|
+
|
|
6
|
+
The SDK then:
|
|
7
|
+
|
|
8
|
+
1. Rejects the request.
|
|
9
|
+
2. Revokes the affected refresh family.
|
|
10
|
+
3. Reports a replay-risk signal.
|
|
11
|
+
4. Quarantines the affected session.
|
|
12
|
+
5. Emits a structured audit event.
|
|
13
|
+
|
|
14
|
+
This blocks both token replay and concurrent attempts to rotate the same family.
|
|
15
|
+
|
|
16
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Example: Replay Attack Prevention
|
|
2
|
+
|
|
3
|
+
The first refresh succeeds and rotates the token. Reusing the previous token is
|
|
4
|
+
rejected:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
await auth.refreshToken(token);
|
|
8
|
+
await auth.refreshToken(token); // Throws.
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Replay detection also revokes and quarantines the affected refresh family.
|
|
12
|
+
|
|
13
|
+
[Learn how replay detection works](./replay-attack-detection.md)
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Repository Setup
|
|
2
|
+
|
|
3
|
+
To connect an existing local repository to the upstream GitLab project:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
git remote add origin https://gitlab.com/COD434/authenik8-core.git
|
|
7
|
+
git branch -M main
|
|
8
|
+
git push -uf origin main
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Verify the target remote and branch before pushing.
|
|
12
|
+
|
|
13
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Requirements
|
|
2
|
+
|
|
3
|
+
Authenik8-core uses stateful JWT authentication. A Redis-compatible store is
|
|
4
|
+
therefore required for session tracking, refresh rotation, revocation, and
|
|
5
|
+
quarantine.
|
|
6
|
+
|
|
7
|
+
Stateful verification provides stronger control than signature-only JWT
|
|
8
|
+
verification, but Redis becomes security-critical infrastructure. Deploy it
|
|
9
|
+
with authentication, encryption, restricted network access, persistence, and
|
|
10
|
+
monitoring appropriate to the application.
|
|
11
|
+
|
|
12
|
+
Cryptographic and configuration requirements:
|
|
13
|
+
|
|
14
|
+
- Prefer ES256 JWKs stored in a secret manager or HSM-backed key service.
|
|
15
|
+
- The refresh HMAC secret must contain 32-4096 bytes of cryptographically random
|
|
16
|
+
material and must be independent of the deprecated access HMAC secret.
|
|
17
|
+
- Access-token lifetime is 60 seconds to 24 hours; refresh lifetime is 60
|
|
18
|
+
seconds to 31 days; agent-token lifetime is 60 seconds to one hour.
|
|
19
|
+
- Keep issuer and audience stable. They also form the default Redis isolation
|
|
20
|
+
domain. Set `redisKeyPrefix` explicitly when multiple deployments share Redis
|
|
21
|
+
or when planning a key migration.
|
|
22
|
+
- Load environment variables in the host process before importing or
|
|
23
|
+
constructing the SDK. Authenik8-core does not invoke dotenv.
|
|
24
|
+
- Configure `trustedProxyCidrs` only for networks under your control.
|
|
25
|
+
|
|
26
|
+
CI uses `ioredis-mock` by design and does not start a Redis service. A
|
|
27
|
+
production readiness process must still test
|
|
28
|
+
the selected real Redis version and topology outside CI, including Lua support,
|
|
29
|
+
cluster hash-slot behavior, failover, persistence, latency, and recovery.
|
|
30
|
+
|
|
31
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Secure Refresh Flow
|
|
2
|
+
|
|
3
|
+
The initial refresh validates the token and atomically rotates its family
|
|
4
|
+
record:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
await auth.refreshToken(token);
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The previous token no longer matches the stored fingerprint:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
await auth.refreshToken(token); // Throws.
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Replay causes the family to be revoked and the affected session to be
|
|
17
|
+
quarantined.
|
|
18
|
+
|
|
19
|
+
[Read the internal rotation flow](./refresh-token-rotation.md)
|
|
20
|
+
|
|
21
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Security Audit — 2026-07-27
|
|
2
|
+
|
|
3
|
+
## Result
|
|
4
|
+
|
|
5
|
+
This review found no open Critical or High finding in the reviewed SDK scope
|
|
6
|
+
after the remediations listed below. That result is evidence from this review,
|
|
7
|
+
not a guarantee, certification, or claim of military/government accreditation.
|
|
8
|
+
Independent review and deployment-specific testing remain required.
|
|
9
|
+
|
|
10
|
+
## Scope
|
|
11
|
+
|
|
12
|
+
The review covered:
|
|
13
|
+
|
|
14
|
+
- ES256 and legacy HS256 signing and verification.
|
|
15
|
+
- Access, refresh, guest, and agent token separation.
|
|
16
|
+
- Session persistence, rotation, replay response, revocation, and quarantine.
|
|
17
|
+
- OAuth state, provider exchange, account creation, and provider linking.
|
|
18
|
+
- Authorization, tenant checks, audit delivery, and risk-state handling.
|
|
19
|
+
- Proxy trust, client-IP resolution, allowlists, and rate limiting.
|
|
20
|
+
- Redis key construction, atomic operations, failure behavior, and isolation.
|
|
21
|
+
- Package dependencies, published files, public entry points, and CI behavior.
|
|
22
|
+
|
|
23
|
+
The host application, its custom adapters and policies, Redis deployment, edge
|
|
24
|
+
proxy, secret manager, operating system, and application routes were not
|
|
25
|
+
independently penetration-tested.
|
|
26
|
+
|
|
27
|
+
## Method
|
|
28
|
+
|
|
29
|
+
The audit combined manual data-flow and trust-boundary review with abuse-case
|
|
30
|
+
tests. It checked authentication decisions before and after persistence,
|
|
31
|
+
one-time and concurrent operations, untrusted string and collection bounds,
|
|
32
|
+
algorithm and token-purpose confusion, proxy-chain spoofing, Redis key
|
|
33
|
+
ambiguity, stored-record integrity, error handling, and package supply-chain
|
|
34
|
+
exposure.
|
|
35
|
+
|
|
36
|
+
## Findings Remediated
|
|
37
|
+
|
|
38
|
+
### Token and session integrity
|
|
39
|
+
|
|
40
|
+
- Enforced exact token-purpose, issuer, audience, algorithm, canonical compact
|
|
41
|
+
encoding, token size, claim size, and lifetime bounds.
|
|
42
|
+
- Required independent 32-4096 byte HMAC secrets and rejected shared access and
|
|
43
|
+
refresh secrets.
|
|
44
|
+
- Stored SHA-256 bearer-token fingerprints instead of newly issued raw tokens.
|
|
45
|
+
- Added field-to-record session ID integrity checks and rejected malformed
|
|
46
|
+
persisted metadata.
|
|
47
|
+
- Replaced ambiguous compound refresh and lock keys with SHA-256 pair
|
|
48
|
+
identifiers. Refresh-family revocation uses bounded concurrency.
|
|
49
|
+
- Bounded authorization arrays and strings at both issuance and verification.
|
|
50
|
+
- Restricted local verification JWKS to bounded, unique, public P-256 keys and
|
|
51
|
+
remote JWKS to credential-free HTTPS URLs.
|
|
52
|
+
|
|
53
|
+
### OAuth and identity integrity
|
|
54
|
+
|
|
55
|
+
- Made state 256-bit, five-minute, exact-shape, bounded, and atomically
|
|
56
|
+
consumable before exchange.
|
|
57
|
+
- Bounded provider HTTP time and decompressed JSON response size.
|
|
58
|
+
- Required explicit authenticated link mode; provider email never chooses the
|
|
59
|
+
link target.
|
|
60
|
+
- Made identity creation and provider linking atomic and cluster-slot safe.
|
|
61
|
+
- Cross-checked email/provider indexes against the resolved record and
|
|
62
|
+
validated all adapter-returned users before any token issuance.
|
|
63
|
+
- Disabled automatic email linking by default. Policy flags and provider email
|
|
64
|
+
verification must be actual booleans; truthy strings are not accepted.
|
|
65
|
+
- Bounded identities, roles, provider identifiers, and provider count.
|
|
66
|
+
- Detached validated identity and agent records from caller-owned mutable
|
|
67
|
+
objects.
|
|
68
|
+
|
|
69
|
+
### Network, policy, and audit integrity
|
|
70
|
+
|
|
71
|
+
- Resolved client addresses from the socket and explicitly trusted proxy CIDRs,
|
|
72
|
+
walking forwarding chains from right to left.
|
|
73
|
+
- Rejected malformed trusted forwarding headers and ignored headers from
|
|
74
|
+
untrusted peers.
|
|
75
|
+
- Canonicalized IPv4/IPv6/CIDR entries, removed implicit loopback trust, made
|
|
76
|
+
exact membership/expiry atomic, and batched CIDR maintenance.
|
|
77
|
+
- Distinguished actual rate-limit decisions from storage/protocol failures;
|
|
78
|
+
failures return 503 instead of being mislabeled as 429.
|
|
79
|
+
- Bounded and validated audit envelopes, recursively detached metadata, and
|
|
80
|
+
contained synchronous and asynchronous sink failures.
|
|
81
|
+
- Validated persisted risk state, principals, counters, policy enums, and
|
|
82
|
+
deduplication fingerprints. Invalid security state fails closed.
|
|
83
|
+
|
|
84
|
+
### Distribution and CI
|
|
85
|
+
|
|
86
|
+
- Removed obsolete alternative identity/password stores and stateless admin or
|
|
87
|
+
guest verification fallbacks.
|
|
88
|
+
- Restricted package exports to the reviewed root API and `package.json`,
|
|
89
|
+
preventing unsupported internal deep imports through the package resolver.
|
|
90
|
+
- Removed import-time dotenv behavior.
|
|
91
|
+
- CI integration tests use `ioredis-mock`; no Redis service or readiness probe
|
|
92
|
+
is required.
|
|
93
|
+
- Updated the lockfile to patched dependencies. A live
|
|
94
|
+
`npm audit --package-lock-only --audit-level=low` reported zero known
|
|
95
|
+
vulnerabilities on 2026-07-27.
|
|
96
|
+
|
|
97
|
+
## Verification Gates
|
|
98
|
+
|
|
99
|
+
The release gates are:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
npm run typecheck
|
|
103
|
+
npm run lint
|
|
104
|
+
npm test
|
|
105
|
+
npm run build
|
|
106
|
+
npm audit --package-lock-only --audit-level=low
|
|
107
|
+
npm pack --dry-run
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
CI also enables GitLab SAST, dependency scanning, and secret detection. The
|
|
111
|
+
test suite uses mocked Redis deliberately; a separate production qualification
|
|
112
|
+
must exercise the selected Redis version and topology.
|
|
113
|
+
|
|
114
|
+
## Residual Risks
|
|
115
|
+
|
|
116
|
+
- A stolen bearer token can be used until expiry, revocation, or quarantine.
|
|
117
|
+
Proof-of-possession and TLS channel binding are not implemented.
|
|
118
|
+
- Cookie authentication requires application-owned CSRF protection and secure
|
|
119
|
+
cookie policy.
|
|
120
|
+
- Redis, signing-key storage, custom identity/state adapters, authorization
|
|
121
|
+
callbacks, and delegation callbacks remain in the trusted computing base.
|
|
122
|
+
- Signature-only offline JWKS verification cannot observe online revocation.
|
|
123
|
+
- IP controls are defense in depth and are limited by NAT, address rotation,
|
|
124
|
+
and distributed attackers.
|
|
125
|
+
- The SDK does not provide TLS termination, durable tamper-evident audit
|
|
126
|
+
storage, secret-manager/HSM integration, host hardening, incident response,
|
|
127
|
+
or deployment accreditation.
|
|
128
|
+
- Mocked Redis verifies SDK logic but cannot qualify Lua/version differences,
|
|
129
|
+
cluster routing, persistence, failover, latency, or disaster recovery.
|
|
130
|
+
|
|
131
|
+
See the [full threat model](../THREAT_MODEL.md) for operator responsibilities.
|
|
132
|
+
|
|
133
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Security Layer
|
|
2
|
+
|
|
3
|
+
Authenik8-core includes:
|
|
4
|
+
|
|
5
|
+
- Rate-limiting middleware.
|
|
6
|
+
- IP allow and deny controls.
|
|
7
|
+
- Secure HTTP headers through Helmet.
|
|
8
|
+
- Human authorization middleware.
|
|
9
|
+
- Tenant isolation.
|
|
10
|
+
- Structured audit events.
|
|
11
|
+
- Session-risk signals and quarantine.
|
|
12
|
+
|
|
13
|
+
These controls share authenticated identity and session context while remaining
|
|
14
|
+
separate services, limiting coupling between policy, persistence, and delivery.
|
|
15
|
+
|
|
16
|
+
Forwarding headers are ignored by default. If the application is behind a
|
|
17
|
+
reverse proxy, authorize only its networks:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const auth = await createAuthenik8({
|
|
21
|
+
jwt,
|
|
22
|
+
refreshSecret,
|
|
23
|
+
redisKeyPrefix: "orders-api:production",
|
|
24
|
+
trustedProxyCidrs: ["10.20.0.0/16", "2001:db8:100::/48"],
|
|
25
|
+
security: {
|
|
26
|
+
rateLimitPoints: 100,
|
|
27
|
+
rateLimitDuration: 60,
|
|
28
|
+
rateLimitBlock: 300,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`trustProxyHeaders: true` without `trustedProxyCidrs` is rejected. The direct
|
|
34
|
+
socket peer must be trusted, and resolution stops at the first untrusted hop.
|
|
35
|
+
Configure the same policy at Express and the edge proxy; the proxy must replace,
|
|
36
|
+
not append to, client-supplied forwarding headers at the trust boundary.
|
|
37
|
+
|
|
38
|
+
IP allowlist entries accept canonical IPv4, IPv6, or CIDR values and expire
|
|
39
|
+
after seven days by default:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
await auth.addIP("203.0.113.10", 3600);
|
|
43
|
+
await auth.addIP("2001:db8:abcd::/48");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Loopback is not automatically allowed. Add it explicitly if a local health or
|
|
47
|
+
administration path genuinely requires it.
|
|
48
|
+
|
|
49
|
+
The default Helmet CSP is enforcing and intentionally blocks inline scripts and
|
|
50
|
+
styles. Applications requiring nonces or additional origins should replace it
|
|
51
|
+
with a reviewed `security.helmetOptions` policy; do not restore
|
|
52
|
+
`'unsafe-inline'` as a convenience.
|
|
53
|
+
|
|
54
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Session Risk and Quarantine
|
|
2
|
+
|
|
3
|
+
Refresh replay quarantines and revokes the affected family immediately.
|
|
4
|
+
Concurrent refresh and suspicious-agent signals use bounded time-window
|
|
5
|
+
thresholds. IP and device changes are audited by default and can be configured
|
|
6
|
+
to quarantine:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
const auth = await createAuthenik8({
|
|
10
|
+
jwt,
|
|
11
|
+
refreshSecret,
|
|
12
|
+
redis,
|
|
13
|
+
risk: {
|
|
14
|
+
signalWindowSeconds: 300,
|
|
15
|
+
quarantineSeconds: 900,
|
|
16
|
+
concurrentRefreshThreshold: 2,
|
|
17
|
+
suspiciousAgentThreshold: 5,
|
|
18
|
+
ipChangeAction: "quarantine",
|
|
19
|
+
deviceChangeAction: "audit",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const principal = {
|
|
24
|
+
kind: "human" as const,
|
|
25
|
+
id: userId,
|
|
26
|
+
sessionId,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
await auth.risk.getState(principal);
|
|
30
|
+
await auth.risk.release(principal);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The risk service depends on a small store interface. The default adapter uses
|
|
34
|
+
Redis-compatible commands, while CI uses `ioredis-mock`.
|
|
35
|
+
|
|
36
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Stateful Session Control
|
|
2
|
+
|
|
3
|
+
Sessions are represented in Redis, allowing the SDK to:
|
|
4
|
+
|
|
5
|
+
- Revoke an individual session.
|
|
6
|
+
- Revoke every session for a user.
|
|
7
|
+
- Reject access tokens after logout.
|
|
8
|
+
- Track refresh families independently of access-token expiry.
|
|
9
|
+
- Enforce automatic or manual quarantine.
|
|
10
|
+
- List active sessions.
|
|
11
|
+
|
|
12
|
+
Public JWKS verification remains useful for signature-only boundaries, but it
|
|
13
|
+
cannot observe this Redis state. Sensitive routes should use
|
|
14
|
+
`verifyActiveToken()` or `requireAuth`.
|
|
15
|
+
|
|
16
|
+
[Back to the documentation index](../README.md#documentation)
|
package/docs/testing.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
Authenik8-core includes automated coverage for:
|
|
4
|
+
|
|
5
|
+
- Token issuance and verification.
|
|
6
|
+
- Refresh-token rotation and replay prevention.
|
|
7
|
+
- Concurrent refresh behavior.
|
|
8
|
+
- Session persistence and revocation.
|
|
9
|
+
- Authorization and tenant isolation.
|
|
10
|
+
- Audit delivery behavior.
|
|
11
|
+
- Session-risk quarantine.
|
|
12
|
+
- Agent and delegated identity.
|
|
13
|
+
- OAuth same-email creation races and provider-owner link confusion.
|
|
14
|
+
- One-time OAuth state under concurrent consumption.
|
|
15
|
+
- Forwarded-header spoofing and trusted multi-hop proxy resolution.
|
|
16
|
+
- Exact and CIDR allowlist expiration, including IPv4 and IPv6.
|
|
17
|
+
- Deep audit-event immutability and synchronous sink failure isolation.
|
|
18
|
+
- Secret, token-lifetime, JWT-size, and Redis-key namespace bounds.
|
|
19
|
+
- Compound-key collision resistance and persisted index/record integrity.
|
|
20
|
+
- OAuth response-size, state-shape, identity-count, and runtime type bounds.
|
|
21
|
+
- Malformed risk state, audit envelope, authorization claim, and rate-limit
|
|
22
|
+
failure handling.
|
|
23
|
+
|
|
24
|
+
CI intentionally uses `ioredis-mock`, including for the concurrent refresh
|
|
25
|
+
integration scenario. The pipeline starts no Redis service. Production deployments should separately validate their
|
|
26
|
+
chosen Redis topology, persistence, failover, and operational controls.
|
|
27
|
+
|
|
28
|
+
The release dependency gate is:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm audit --package-lock-only --audit-level=low
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
See the dated [security audit](security-audit.md) for scope, remediation, and
|
|
35
|
+
residual risks.
|
|
36
|
+
|
|
37
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Threats Addressed
|
|
2
|
+
|
|
3
|
+
Authenik8-core directly mitigates:
|
|
4
|
+
|
|
5
|
+
- Refresh-token replay.
|
|
6
|
+
- Concurrent refresh abuse.
|
|
7
|
+
- Use of revoked or quarantined sessions.
|
|
8
|
+
- Cross-tenant and missing-claim authorization failures.
|
|
9
|
+
- Human and machine token-class confusion.
|
|
10
|
+
- OAuth state reuse.
|
|
11
|
+
- OAuth same-email account-creation races and provider-link account confusion.
|
|
12
|
+
- Spoofed forwarding headers from untrusted socket peers or proxy hops.
|
|
13
|
+
- Expired exact and CIDR allowlist entries.
|
|
14
|
+
- Audit-sink mutation of nested authorization metadata.
|
|
15
|
+
- Redis-key collisions between SDK deployments.
|
|
16
|
+
- Ambiguous compound refresh/lock keys within a deployment.
|
|
17
|
+
- Corrupted or inconsistent OAuth indexes, session records, and risk records.
|
|
18
|
+
- Oversized OAuth provider JSON and authorization claim collections.
|
|
19
|
+
- Truthy-string coercion in high-impact identity and delegation policies.
|
|
20
|
+
- Bearer-token exposure through raw session records.
|
|
21
|
+
|
|
22
|
+
See the [threat model](../THREAT_MODEL.md) for trust boundaries, residual risks,
|
|
23
|
+
and application responsibilities.
|
|
24
|
+
|
|
25
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Use Cases
|
|
2
|
+
|
|
3
|
+
Authenik8-core is designed for:
|
|
4
|
+
|
|
5
|
+
- SaaS backends with tenant-aware authorization.
|
|
6
|
+
- APIs that need revocable access tokens.
|
|
7
|
+
- Secure administrative systems.
|
|
8
|
+
- Applications requiring refresh replay protection.
|
|
9
|
+
- AI agents, workers, bots, and M2M callers with bounded scopes.
|
|
10
|
+
- Systems that need centralized audit and session-risk signals.
|
|
11
|
+
|
|
12
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# What Authenik8-core Does
|
|
2
|
+
|
|
3
|
+
Authenik8-core adds a stateful security layer around JWT authentication:
|
|
4
|
+
|
|
5
|
+
- Refresh-token rotation with replay protection.
|
|
6
|
+
- Redis-backed session control and revocation.
|
|
7
|
+
- Role, permission, scope, and tenant authorization.
|
|
8
|
+
- Structured security audit events.
|
|
9
|
+
- Session-risk detection and quarantine.
|
|
10
|
+
- Rate limiting, IP controls, and secure headers.
|
|
11
|
+
- Scoped identities for AI agents, workers, bots, and M2M callers.
|
|
12
|
+
|
|
13
|
+
Only SHA-256 token fingerprints are stored in session and refresh records, so a
|
|
14
|
+
read-only Redis exposure does not reveal usable bearer tokens from those
|
|
15
|
+
records.
|
|
16
|
+
|
|
17
|
+
[Back to the documentation index](../README.md#documentation)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Why Authenik8-core?
|
|
2
|
+
|
|
3
|
+
JWT makes authentication look simple but introduces hidden operational and
|
|
4
|
+
security problems:
|
|
5
|
+
|
|
6
|
+
- Refresh-token reuse and replay attacks.
|
|
7
|
+
- Stateless logout and revocation gaps.
|
|
8
|
+
- Broken or incomplete token rotation.
|
|
9
|
+
- Security logic scattered across routes and services.
|
|
10
|
+
|
|
11
|
+
Authenik8-core addresses these with refresh-token rotation, Redis-backed session
|
|
12
|
+
control, authorization middleware, risk quarantine, audit events, and a unified
|
|
13
|
+
API.
|
|
14
|
+
|
|
15
|
+
[Back to the documentation index](../README.md#documentation)
|