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
// 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
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