Creating Custom Events

What security considerations should be taken into account when using custom events?
function sanitizeEventData(data) {
  // Deep clone to prevent reference manipulation
  const sanitized = JSON.parse(JSON.stringify(data));
  
  // Remove sensitive properties
  delete sanitized.password;
  delete sanitized.token;
  
  return Object.freeze(sanitized);
}

function dispatchSafeEvent(name, data) {
  const event = new CustomEvent(name, {
    detail: sanitizeEventData(data)
  });
  document.dispatchEvent(event);
}
Next Question (15/20)