File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,30 @@ new Elysia()
90
90
To use JSX, don't forget to rename your file extension to either ` .tsx ` or ` .jsx `
91
91
:::
92
92
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
+
93
117
## Handler
94
118
Below are the value added to the handler.
95
119
You can’t perform that action at this time.
0 commit comments