safe-markdown

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.

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

Bad.

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.

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.asyncapi has the details.

commands:
  lint:
    asyncapi:
      rules:
        safe-markdown: off

Related rules

Last updated on View as Markdown
Was this helpful?