@@ -111,9 +111,10 @@ <h2>Background</h2>
111111< p >
112112In < i > theory</ i > you could call an escape routine every time you
113113make 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>
129130this serves as a great example.
130131In short, sometimes libraries must be specially configured to be
131132less 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 >
134135configure 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 > .
139139So as far
140140as users of < i > Flask</ i > are concerned, the Jinja templating system < i > does</ i >
141141automatically escape HTML by default.
@@ -207,10 +207,10 @@ <h3>Part 2</h3>
207207Unfortunately, this template below has a vulnerability.
208208Its "| safe" marking tells the templating system that the data is
209209safe 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 "<" 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 "<" into a name as a
213+ way to attack others.
214214Please fix this vulnerability.
215215
216216<!--
@@ -245,18 +245,20 @@ <h3>Part 3</h3>
245245< p >
246246A 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
249249is 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("<em>Hello</em> ") + "<foo>"</ tt >
255255produces a Markup instance containing the Unicode string value
256256< tt > '<em>Hello</em> &lt;foo&gt;'</ tt > -
257257note 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.
260262The code also clearly indicates what is considered safe and what is not.
261263The Markup class supports many other methods not described here
262264to simplify control over what is escaped.
0 commit comments