Skip to content

[BUG] A code template with an XML-illegal character (U+FFFE) makes the JSON code template list fail #566

Open

Description

@matthydehoog

Summary

If a code template contains a character that is not allowed in XML 1.0 (for example U+FFFE or U+FFFF), the JSON variant of the code template REST API fails for the whole list. The XML variant still works, so the Swing Administrator loads the templates normally, but every client that asks for JSON (such as the web administrator) gets an error and sees no code templates at all.

Steps to reproduce

  1. Create a code template whose code contains a raw U+FFFE character, for example in a regex: s.replace(/[<U+FFFE><U+FFFF>]/g, "") with the actual characters instead of � / � escapes.
  2. Save it (the Swing Administrator accepts it).
  3. Request the code templates as JSON, e.g. GET /api/codeTemplates with Accept: application/json.

Expected

The list is returned. The character is either escaped/stripped on output, or rejected with a clear message when the template is saved.

Actual

The request fails with a server error. The server log shows, for every request:

ERROR com.mirth.connect.model.converters.ObjectJSONSerializer: javax.xml.transform.TransformerException: com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0xfffe)

ObjectJSONSerializer converts the object to XML first and then parses that XML with Woodstox to build the JSON. The XML contains &#xfffe;, which is illegal in XML 1.0, so the parse fails. One bad template blocks the whole list.

Notes

  • Seen on OIE 4.6.0. The characters came from a JavaScript file pasted into a code template, so this can happen by accident.
  • Workaround: open the template in the Swing Administrator, remove the characters (use � escapes), and save.
  • The same path is probably used for channels, global scripts and other objects with free-text script fields, so they are likely affected too.
  • Possible fixes: strip or escape XML-illegal characters when serialising to JSON, and/or reject them on save with a message that names the template.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions