Skip to content

Commit a424e9b

Browse files
finish xss section
1 parent a2cf72e commit a424e9b

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

.serena/project.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ symbol_info_budget:
117117
# Note: the backend is fixed at startup. If a project with a different backend
118118
# is activated post-init, an error will be returned.
119119
language_backend:
120+
121+
# line ending convention to use when writing source files.
122+
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
123+
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
124+
line_ending:
125+
126+
# list of regex patterns which, when matched, mark a memory entry as read‑only.
127+
# Extends the list from the global configuration, merging the two lists.
128+
read_only_memory_patterns: []
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[
22
"safe-attribute",
3-
"detection",
43
"scanner-cli",
54
"safety-rules",
65
"error-codes",
7-
"why-not-auto-escape"
6+
"why-not-auto-escape",
7+
"detection"
88
]

packages/docs/docs/guide/xss/safe-attribute.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rendering the payload as harmless text.
2626
Place `safe` on the innermost element that holds the untrusted value. Do not add it to a
2727
parent wrapper, as that would escape the HTML of child components too.
2828

29-
```tsx
29+
```tsx twoslash kita
3030
function UserCard({ name, bio }: { name: string; bio: string }) {
3131
return (
3232
<div class="card">
@@ -35,6 +35,8 @@ function UserCard({ name, bio }: { name: string; bio: string }) {
3535
</div>
3636
)
3737
}
38+
// ---cut-after---
39+
const html = <UserCard name="Name" bio="Bio" />
3840
```
3941

4042
## Component children
@@ -64,13 +66,16 @@ html = <MyComponent>{escapeHtml(userInput)}</MyComponent>
6466

6567
## Template literal helper
6668

67-
The `e` tagged template escapes interpolated values while preserving literal HTML around
68-
them.
69+
The `e` tagged template is an alias to `escapeHtml()` that you can use as interpolated
70+
content in template literals. It provides a convenient way to escape dynamic values
71+
outside of JSX.
6972

70-
```tsx
73+
```tsx twoslash kita
74+
const userName = '<script>untrusted()</script>' as const
75+
// ---cut---
7176
import { e } from '@kitajs/html'
7277

73-
const html = e`<p>Hello, ${userName}!</p>`
78+
const html = e`Hello, ${userName}!`
7479
```
7580

7681
## Suppression conventions
@@ -111,15 +116,29 @@ const unsafeContent = 'My safe string' as const
111116
const html = <div>{unsafeContent}</div>
112117
```
113118

119+
::: warning
120+
121+
Manual casts and naming conventions are not enforced by the compiler. They rely on
122+
developer discipline and code reviews to ensure safety. Use them judiciously and document
123+
the rationale for any exceptions.
124+
125+
:::
126+
114127
Cast the expression to `'safe'` inline. This tells the plugin to skip the check for that
115-
specific usage.
128+
specific usage and not warn about possible XSS vulnerabilities.
116129

117-
```tsx
118-
<div>{content as 'safe'}</div>
130+
```tsx twoslash kita
131+
const content: string = '<script>untrusted()</script>'
132+
// ---cut---
133+
const html = <div>{content as 'safe'}</div>
119134
```
120135

121136
Call `Html.escapeHtml()` directly. The plugin recognizes the return value as escaped.
122137

123-
```tsx
124-
<div>{Html.escapeHtml(content)}</div>
138+
```tsx twoslash kita
139+
const content: string = '<script>untrusted()</script>'
140+
// ---cut---
141+
import { Html } from '@kitajs/html'
142+
143+
const html = <div>{Html.escapeHtml(content)}</div>
125144
```

0 commit comments

Comments
 (0)