You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ The Auth0 Next.js SDK is a library for implementing user authentication in Next.
17
17
-[API Reference](#api-reference)
18
18
-[v1 Migration Guide](./V1_MIGRATION_GUIDE.md)
19
19
-[Cookies and Security](#cookies-and-security)
20
+
-[Error Handling and Security](#error-handling-and-security)
20
21
-[Base Path and Internationalized Routing](#base-path-and-internationalized-routing)
21
22
-[Architecture](./ARCHITECTURE.md)
22
23
-[Comparison with auth0-react](#comparison-with-auth0-react)
@@ -188,6 +189,22 @@ The `HttpOnly` setting will make sure that client-side JavaScript is unable to a
188
189
189
190
The `SameSite=Lax` setting will help mitigate CSRF attacks. Learn more about SameSite by reading the ["Upcoming Browser Behavior Changes: What Developers Need to Know"](https://auth0.com/blog/browser-behavior-changes-what-developers-need-to-know/) blog post.
190
191
192
+
### Error Handling and Security
193
+
194
+
The default server side error handler for the `/api/auth/*` routes prints the error message to screen, eg
195
+
196
+
```js
197
+
try {
198
+
awaithandler(req, res);
199
+
} catch (error) {
200
+
res.status(error.status||400).end(error.message);
201
+
}
202
+
```
203
+
204
+
Because the error can come from the OpenID Connect `error` query parameter we do some [basic escaping](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#rule-1-html-encode-before-inserting-untrusted-data-into-html-element-content) which makes sure the default error handler is safe from XSS.
205
+
206
+
If you write your own error handler, you should **not** render the error message without using a templating engine that will properly escape it for other HTML contexts first.
207
+
191
208
### Base Path and Internationalized Routing
192
209
193
210
With Next.js you can deploy a Next.js application under a sub-path of a domain using [Base Path](https://nextjs.org/docs/api-reference/next.config.js/basepath) and serve internationalized (i18n) routes using [Internationalized Routing](https://nextjs.org/docs/advanced-features/i18n-routing).
Copy file name to clipboardExpand all lines: src/utils/errors.ts
+43Lines changed: 43 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,5 @@
1
+
import{HttpError}from'http-errors';
2
+
1
3
/**
2
4
* The error thrown by {@link GetAccessToken}
3
5
*
@@ -19,3 +21,44 @@ export class AccessTokenError extends Error {
19
21
this.code=code;
20
22
}
21
23
}
24
+
25
+
// eslint-disable-next-line max-len
26
+
// Basic escaping for putting untrusted data directly into the HTML body, per: https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#rule-1-html-encode-before-inserting-untrusted-data-into-html-element-content
27
+
functionhtmlSafe(input: string): string{
28
+
returninput
29
+
.replace(/&/g,'&')
30
+
.replace(/</g,'<')
31
+
.replace(/>/g,'>')
32
+
.replace(/"/g,'"')
33
+
.replace(/'/g,''');
34
+
}
35
+
36
+
/**
37
+
* The error thrown by API route handlers.
38
+
*
39
+
* Because the error message can come from the OpenID Connect `error` query parameter we
40
+
* do some basic escaping which makes sure the default error handler is safe from XSS.
41
+
*
42
+
* If you write your own error handler, you should **not** render the error message
43
+
* without using a templating engine that will properly escape it for other HTML contexts first.
0 commit comments