Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMX attributes are stripped from HTML nodes #5956

Open
ouvreboite opened this issue Oct 11, 2024 · 4 comments
Open

HTMX attributes are stripped from HTML nodes #5956

ouvreboite opened this issue Oct 11, 2024 · 4 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@ouvreboite
Copy link

Description

I'm trying to use HTMX with mermaid charts. A naive usage would be to use the HTMX attributes in the nodes directly.

<pre class="mermaid">
  graph TD
    NodeA(<a href="NodeA.html" hx-get="NodeA.html">NodeA</a>) -->NodeB
</pre>

Sadly, the hx-get attributes (and others custom HTMX attributes) are somehow stripped and not present in the resulting foreignObject

<foreignObject width="27.125" height="24">
    <div  xmlns="...">
    <span class="nodeLabel ">
        <p>
            <a href="NodeA.html">NodeA</a> <!-- ⬅️ the hx-get attribute is missing -->
        </p>
    </span>
    </div>
</foreignObject>

I have set the security level to loose

<script type="module">
    import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
    mermaid.initialize({
        securityLevel: 'loose',
    });
</script>

Steps to reproduce

Fiddle with minimal example: https://jsfiddle.net/ejw1978d/1/

Screenshots

No response

Code Sample

<pre class="mermaid">
  graph TD
    NodeA(<a href="NodeA.html" hx-get="NodeA.html">NodeA</a>) -->NodeB
</pre>

Setup

Suggested Solutions

No response

Additional Context

No response

@ouvreboite ouvreboite added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Oct 11, 2024
@sidharthv96
Copy link
Member

We use DOMPurify for the sanitization, which might be removing the attributes.

@julosaure
Copy link

Is it possible not to sanitize while rendering?

@sidharthv96
Copy link
Member

I don't think it's possible now, but we could add a new security level (none ?), which skips DOMPurify.

@mattdean-digicatapult
Copy link

As an alternative to a security level none would you consider exposing some of the configuration parameters for DOMPurify? That way the user can configure which attributes should be allowed through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

4 participants