Skip to content

Commit c39e8f5

Browse files
Tweak lab xss (#655)
Signed-off-by: David A. Wheeler <[email protected]>
1 parent b6c2e74 commit c39e8f5

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

docs/labs/count-tiers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
# This simple script lets us quickly report lab status
4+
35
echo 'Per tier here is done; planned and assigned; planned and unassigned:'
46

57
for tier in 0 1 2; do

docs/labs/xss.html

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ <h2>Background</h2>
111111
<p>
112112
In <i>theory</i> you could call an escape routine every time you
113113
make a call to generate an output.
114-
In <i>practice</i> this approach is insecure,
115-
because it's too easy to accidentally forget to call the escape routine.
116-
It's instead safer to use mechanisms which escape <i>by default</i>.
114+
In <i>practice</i> this approach is insecure.
115+
Sooner or later a developer will accidentally forget to
116+
call the escape routine while generating output.
117+
It's much safer to use mechanisms which escape <i>by default</i>.
117118
<p>
118119
<a href="https://pypi.org/project/Flask/"
119120
>Flask</a> is a lightweight server-side web application framework
@@ -129,13 +130,12 @@ <h2>Background</h2>
129130
this serves as a great example.
130131
In short, sometimes libraries must be specially configured to be
131132
less dangerous to use.
132-
This isn't ideal, but it can still be used.
133-
You simply need to ensure that you correctly
133+
This isn't ideal, but such libraries can still be used.
134+
You simply need to ensure that you <i>correctly</i>
134135
configure the library to be used securely.
135136
<p>
136-
It turns out that
137137
<a href="https://flask.palletsprojects.com/en/3.0.x/quickstart/#rendering-templates"
138-
>Flask by default configures Jinja2 to automatically escape of HTML</a>.
138+
>Flask by default configures Jinja2 to automatically escape HTML</a>.
139139
So as far
140140
as users of <i>Flask</i> are concerned, the Jinja templating system <i>does</i>
141141
automatically escape HTML by default.
@@ -207,10 +207,10 @@ <h3>Part 2</h3>
207207
Unfortunately, this template below has a vulnerability.
208208
Its "| safe" marking tells the templating system that the data is
209209
safe and shouldn't be escaped.
210-
However, when the data <i>should</i> be escaped
211-
(as is often the case), this would lead to a vulnerability.
212-
For example, this would often lead to a vulnerability
213-
if an attacker can slip characters like "&lt;" into a name,
210+
However, as shown in the code above, the person's name is from an untrusted
211+
user. Thus the person's name (as with most data) is <i>not</i> safe.
212+
Currently an attacker can slip characters like "&lt;" into a name as a
213+
way to attack others.
214214
Please fix this vulnerability.
215215

216216
<!--
@@ -245,18 +245,20 @@ <h3>Part 3</h3>
245245
<p>
246246
A instance of a <tt>Markup</tt> class is created by calling
247247
<tt>Markup</tt>.
248-
Whatever string is passed during its original construction
248+
A string is passed during its original construction
249249
is assumed to be safe and is <i>not</i> escaped.
250-
You can concatenate a normal string to a Markup value, but those additions
250+
You can concatenate a normal string to a Markup value, and those additions
251251
<i>will</i> be escaped.
252252
<a href="https://tedboy.github.io/flask/generated/generated/flask.Markup.html"
253253
>For example</a>, computing
254254
<tt>Markup("&lt;em&gt;Hello&lt;/em&gt; ") + "&lt;foo&gt;"</tt>
255255
produces a Markup instance containing the Unicode string value
256256
<tt>'&lt;em&gt;Hello&lt;/em&gt; &amp;lt;foo&amp;gt;'</tt> -
257257
note how the first part isn't escaped but the latter part <i>is</i> escaped.
258-
Since every concatenation will be escaped by default, the default is
259-
the safe (escaping) operation.
258+
You can even create a Markup instance with an empty string, and every
259+
concatenation of a normal string will be escaped.
260+
Since every concatenation to a Markup value of a normal string
261+
will be escaped by default, the default is the safe (escaping) operation.
260262
The code also clearly indicates what is considered safe and what is not.
261263
The Markup class supports many other methods not described here
262264
to simplify control over what is escaped.

0 commit comments

Comments
 (0)