# safe-markdown

Source: https://api-genie.dev/docs/linter/asyncapi/rules/safe-markdown

A rule of the AsyncAPI linter, which reads AsyncAPI 3 documents; the reader rejects AsyncAPI 2 documents. Since 0.9.0. Fixed by `--fix`. In the rulesets: Recommended at warning, Strict at error, All at error.

This rule ensures that Markdown strings (descriptions) do not contain unsafe
constructs like script tags or `eval()` calls.

## Rule details

Unsafe constructs embedded in Markdown strings can pose security risks when
the documentation is rendered, for example by a documentation portal.

The `safe-markdown` rule checks the `description` field of every object that
supports CommonMark descriptions: the info object, servers, server variables,
channels, parameters, operations, operation traits, operation reply addresses,
messages, message traits, correlation IDs, tags, external documentation,
schemas and security schemes. It reports:

- `Markdown contains <script> tag` when a description contains a `script`
  element,
- `Markdown contains eval() function` when a description contains an
  `eval()` call.

## Examples

**Good**.

```yaml
asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
  description: Events published when pets are adopted or returned.
```

**Bad**.

```yaml
asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
  description: "Events published when pets are adopted. <script>alert('Unsafe')</script>"
```

## Automatic fixes

`--fix` escapes the delimiters of recognized
script elements and `eval()` calls. It preserves the surrounding Markdown and
does not alter code spans or fenced code blocks.
