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

Math inequality symbols in attributes are not properly encoded #24

Open
iongion opened this issue Feb 4, 2018 · 2 comments
Open

Math inequality symbols in attributes are not properly encoded #24

iongion opened this issue Feb 4, 2018 · 2 comments

Comments

@iongion
Copy link

iongion commented Feb 4, 2018

The tag open < and > are not properly encoded inside attribute values.
They should become &lt; and &gt; - they makes the lib dangerous in projects dealing with user input/output.

@iongion iongion changed the title Entities in parameters are not properly encoded Math inequality symbols in attributes are not properly encoded Feb 4, 2018
@iongion
Copy link
Author

iongion commented Feb 4, 2018

For when running inside the web browser, a safe way to encode attribute values would be something like this:

  function htmlEncode(value) {
    const div = document.createElement('div');
    div.textContent = value;
    return div.innerHTML;
  }

Unfortunately, node env does not offer such a built-in, so you cannot rely on it, you could nevertheless, reference https://www.npmjs.com/package/js-htmlencode in your dependencies and use those functions to perform encoding. Encoding is not trivial task, use a library!

This person already tried disabling the encoding part of this project:

edkotkas@f0bf5d9

@touv
Copy link
Collaborator

touv commented Feb 7, 2018

I'm not sure to understand

XML specefiction doesn't allow & < and > : https://www.w3.org/TR/xml/#NT-AttValue
So they should be encoded, but how ?
Probably like HTML spec ? https://www.w3.org/TR/html51/syntax.html#attribute-value-double-quoted-state

The package that you cite replace special character by there corresponding literal entity
https://github.com/emn178/js-htmlencode/blob/master/src/htmlencode.js#L295-L298

Just like this package :

https://github.com/Inist-CNRS/node-xml-writer/blob/master/lib/xml-writer.js#L258-L265

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

No branches or pull requests

2 participants