Skip to content

Commit bfd6e68

Browse files
committed
🎉 feat: sanitize html
1 parent b3abfc2 commit bfd6e68

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/plugins/html.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ new Elysia()
9090
To use JSX, don't forget to rename your file extension to either `.tsx` or `.jsx`
9191
:::
9292

93+
## Sanitize HTML
94+
If you are using JSX, you can use `safe` attribute to sanitize unsafe value
95+
```tsx
96+
const malicious = `<script>alert("Hello")</script>`
97+
98+
new Elysia()
99+
.get('/unsafe', () => (
100+
<h1 safe>{malicious}</h1>
101+
))
102+
.listen(8080)
103+
```
104+
105+
Otherwise you can use a decorated `sanitize` function decorated in `Context` to explicitly sanitize the value.
106+
```tsx
107+
const malicious = `<script>alert("Hello")</script>`
108+
109+
new Elysia()
110+
.get('/unsafe', ({ sanitize }) => (
111+
<h1>{sanitize(malicious)}</h1>
112+
))
113+
.listen(8080)
114+
```
115+
```
116+
93117
## Handler
94118
Below are the value added to the handler.
95119

0 commit comments

Comments
 (0)