Skip to content

Commit

Permalink
fix: fixed #2573
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Jan 31, 2025
1 parent 4234bf6 commit 6a20e60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
35 changes: 26 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@

### Security Advisories

As a reminder, if you are handling untrusted input, you should consider using
the `MathfieldElement.createHTML()` method to sanitize content. The
`createHTML()` method follows the recommendations from the
[Trusted Type](https://www.w3.org/TR/trusted-types/) specification.

For example, using the DOMPurify library (there are other HTML sanitizers
available):

```html
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.3/purify.min.js"></script>
```

```js
MathfieldElement.createHTML = (html) => DOMPurify.sanitize(html);
```

- [**security advisory**](https://github.com/advisories/GHSA-qwj6-q94f-8425)
Untrusted input could be used to inject arbitrary HTML or JavaScript code in a
page using a mathfield or math content rendered by Mathlive that contained an
`\htmlData{}` command with malicious input.
page using a mathfield or math content rendered by the library, if the content
included an `\htmlData{}` command with maliciously crafted input and no DOM
sanitizer was used.

The content of the `\htmlData{}` command is now sanitized and the 🚫 emoji is
displayed instead.
displayed instead in the mathfield if the content is unsafe. When using
`convertLatexToMarkup()`, an exception is thrown.

In general, if you are handling untrusted input, you should consider using the
`MathfieldElement.createHTML()` method to sanitize content. The `createHTML()`
method follows the recommendations from the
[Trusted Type](https://www.w3.org/TR/trusted-types/) specification.

- The `\href` command now only allows URLs with the `http` or `https` protocol.
- The `\href{}{}` command now only allows URLs with the `http` or `https`
protocol.

### Issues Resolved

Expand All @@ -40,6 +54,9 @@

- Added support for `\dddot` and `\ddddot` commands.

- **#2573** The `\operatorname{}` command when round-tripped would incldue an
extraneous `\mathrm{}` command.

- **#2132**, **#2548** Improved handling of multi-line mathfields. To use a
multi-line mathfield, include a multi-line environment:
- `\displaylines{}`: single column of left-aligned equations
Expand Down
3 changes: 2 additions & 1 deletion src/core/modes-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export function variantString(atom: Atom): string {
'monospace',
'sans-serif',
].includes(result) &&
style.variantStyle
style.variantStyle &&
style.variantStyle !== 'up'
)
result += '-' + style.variantStyle;

Expand Down

0 comments on commit 6a20e60

Please sign in to comment.