Check origin of events

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: typescript-browser-security/event-check-origin

Language: TypeScript

Severity: Warning

Category: Security

Description

Not checking the rule origin can lead to XSS attacks. Always check the event origin.

Learn More

Non-Compliant Code Examples

window.addEventListener('message', (event: Event) => {
  processing();
})

Compliant Code Examples

window.addEventListener('message', (event: Event) => {
  if (event.origin != 'https://app.domain.tld') {
    throw new Error('invalid origin')
  }

  processing();
})
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis