dbsc-toolkit 1.0.2 → 1.2.0
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/README.md +38 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,44 @@ Tree-shaking eliminates anything you don't import.
|
|
|
84
84
|
|
|
85
85
|
`tier` on `res.locals.dbsc` reads `"dbsc"` once registration completes.
|
|
86
86
|
|
|
87
|
+
## Using the tier to actually defend
|
|
88
|
+
|
|
89
|
+
Setting up the middleware does not protect anything on its own. The library does the negotiation and gives you a tier; **enforcing it is your responsibility**. The pattern:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
app.get("/payment", (req, res) => {
|
|
93
|
+
if (res.locals.dbsc.tier !== "dbsc") {
|
|
94
|
+
return res.status(403).json({ error: "hardware-bound session required" });
|
|
95
|
+
}
|
|
96
|
+
// safe to process payment
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If you skip the tier check, a stolen cookie still works. The cookie reaches your server, the session record exists, your code happily proceeds — DBSC bought you nothing. The whole point is the demotion: when a cookie is replayed without the TPM proof, tier drops to `"none"` (or stays at the lower fallback tier) and your gate refuses the request.
|
|
101
|
+
|
|
102
|
+
Suggested handling per tier in a real application:
|
|
103
|
+
|
|
104
|
+
- `tier === "dbsc"`: full access. Payments, account changes, anything sensitive.
|
|
105
|
+
- `tier === "webauthn"`: most access. Hardware-bound via platform authenticator.
|
|
106
|
+
- `tier === "hmac"`: read-only or low-risk actions. The binding is best-effort.
|
|
107
|
+
- `tier === "none"`: treat as unauthenticated. Force re-login, revoke the session, log a `session_stolen` candidate, depending on context.
|
|
108
|
+
|
|
109
|
+
Putting this in a single middleware keeps it consistent:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
function requireDbsc(req, res, next) {
|
|
113
|
+
if (res.locals.dbsc.tier !== "dbsc") {
|
|
114
|
+
return res.status(401).json({ error: "re-authenticate" });
|
|
115
|
+
}
|
|
116
|
+
next();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
app.post("/payment", requireDbsc, handler);
|
|
120
|
+
app.post("/account/email", requireDbsc, handler);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
See [docs/security/best-practices.md](./docs/security/best-practices.md) for the full tier-policy guidance.
|
|
124
|
+
|
|
87
125
|
## Local testing
|
|
88
126
|
|
|
89
127
|
You need HTTPS — `__Host-` cookies require it and Chrome rejects DBSC on plain HTTP. Two options:
|