Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 658 Bytes

how_do_you_avoid_receiving_postmessages_from_attackers.md

File metadata and controls

20 lines (13 loc) · 658 Bytes

How do you avoid receiving postMessages from attackers?

To prevent receiving messages from attackers, always validate the origin property of the message and ensure it matches the trusted source. You can also check the message's content for additional security.

Example:

window.addEventListener('message', (event) => {
  if (event.origin !== 'https://trusted.com') {
    return;
  }
  // Process message
});

Tags: advanced, JavaScript, Security