Skip to content

Add htmx security essay#2280

Merged
1cg merged 10 commits intomasterfrom
security-essay
Feb 6, 2024
Merged

Add htmx security essay#2280
1cg merged 10 commits intomasterfrom
security-essay

Conversation

@alexpetros
Copy link
Copy Markdown
Collaborator

New essay about security

@megatux
Copy link
Copy Markdown
Contributor

megatux commented Feb 5, 2024

Just skimming the text, looks great to me.
Sorry if my English is wrong here, is "Many use applications can be built" right? or "useR applications" was the intended string?
Also, I'd like to add Ruby ERB example to the templates escaping table:

| Ruby | ERB | Yes, with `<%= %>` |

@alexpetros
Copy link
Copy Markdown
Collaborator Author

I meant "useful" actually, thanks for the catch, and for reading! I'll add the Ruby templates, I'm kinda surprised I didn't have them already

Copy link
Copy Markdown
Contributor

@yawaramin yawaramin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Few comments.

Comment thread www/content/essays/web-security-basics-with-htmx.md

We make these simplifying assumptions in order to target the widest possible audience, without including distracting information—obviously this can't catch everyone. No security guide is perfectly comprehensive. If you feel there's a mistake, or an obvious gotcha that we should have mentioned, please reach out and we'll update it.

## The Golden Rules
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency–some of the headings are in 'Sentence case' while others are in 'Capitalized Case'. Do we want to have them all be in the same style?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I'll fix that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with sentence-case, except on this one specifically where I'm using Golden Rules like a proper noun.


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 `<script>` inside it, that script can steal the user's data. When you don't control the route, you cannot guarantee that whoever does control the route won't add a malicious script.

Fortunately, this is a very easy rule to follow. Hypermedia APIs (i.e. HTML) are [specific to the layout of your application](https://htmx.org/essays/hypermedia-apis-vs-data-apis/), so there is almost never any reason you'd *want* to insert someone else's HTML into your page. All you have to do is make sure you only call your own routes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that this can be enforced with htmx.config.selfRequestsOnly = true and that this will be the default in htmx 2.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Comment thread www/content/essays/web-security-basics-with-htmx.md
For example, let's say you're building a dating site, and it lets users share a little bio about themselves. You'd render that bio like this, with `{{ user.bio }}` being the bio stored in the database:

```html
<p class=bio>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p class=bio>
<p class="bio">

Copy link
Copy Markdown
Collaborator Author

@alexpetros alexpetros Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using quotes is legal and fine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but (1) it's inconsistent because other places in the article are using quotes and (2) this is a security-focused article and specifically recommends using quotes, so why not get into the habit everywhere?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was just going to come back and say that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand by my no-quoting style!!! But it's not appropriate for this article specifically

Comment thread www/content/essays/web-security-basics-with-htmx.md Outdated
Comment thread www/content/essays/web-security-basics-with-htmx.md
Comment thread www/content/essays/web-security-basics-with-htmx.md Outdated
Comment thread www/content/essays/web-security-basics-with-htmx.md Outdated
Comment thread www/content/essays/web-security-basics-with-htmx.md
Comment thread www/content/essays/web-security-basics-with-htmx.md Outdated
@alexpetros
Copy link
Copy Markdown
Collaborator Author

Thanks so much for the review @yawaramin :)

@1cg 1cg merged commit 2fc76ca into master Feb 6, 2024
@alexpetros alexpetros deleted the security-essay branch February 6, 2024 21:06
rekado pushed a commit to rekado/htmx that referenced this pull request Feb 9, 2024
* Add htmx security essay

* Change user id prop

* Typo fixes

* More typos

* Add ruby templates and fix "use" typo

* Change paragraph structure slightly

* Rephrase JSON note

* Rephase JSON security point

* Yawar edits

* Add note about flask
FraserChapman pushed a commit to FraserChapman/htmx that referenced this pull request Feb 16, 2024
* Add htmx security essay

* Change user id prop

* Typo fixes

* More typos

* Add ruby templates and fix "use" typo

* Change paragraph structure slightly

* Rephrase JSON note

* Rephase JSON security point

* Yawar edits

* Add note about flask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants