bigskysoftware / bigskysoftware/htmx

Javascript should not be evaluated on responses with content type `text/plain`

Open
#2,586 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

| HTMX Version | Browser |
| --- | --- |
| 1.8.0 | Chrome |

## Context

We are developing a plugin for [Netbox](https://github.com/netbox-community/netbox) which uses htmx. The feature we implemented is quite simple:

```html



```

The response has the content type `text/plain`, not `text/html`.

## Actual Behavior

We have a container providing a reverse proxy, the returned logs may contain lines of the form:

```
[timestamp] [...] url="https://example.com/?foo=javascript:alert(1)" [...]
```

We noticed that the `javascript:alert(1)` part was evaluated (which is problematic).

## Desired Behavior

I know there is `htmx.config.allowEval` but it seem to be global. Either HTMX should trust the `Content-Type` header and consider that "there is no Javascript to evaluate in a `text/plain` response", or we should be able (via a response header, or an attribute) to override locally the `allowEval` configuration option.

## Note

Even though this would be fixed in a later version, we are dependent on Netbox actually updating, and our production environment to also upgrade Netbox, which might take some time. Is there a workaround to somehow sanitize the output ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.