"CSRF validation failed" when try to send POST request in custom module
You need to get a CSRF token before making your POST call.

function getCsrfToken(callback) {
  jQuery
    .get(Drupal.url('rest/session/token'))
    .done(function (data) {
      var csrfToken = data;
      callback(csrfToken);
    });
}


and use this in your ajax call as a new header:

  jQuery.ajax({
    url: 'http://example.com/entity/node?_format=hal_json',
    method: 'POST',
    headers: {
      'Content-Type': 'application/hal+json',
      'X-CSRF-Token': csrfToken
    },
    data: JSON.stringify(node),
    success: function (node) {
      console.log(node);
    }
  });


https://www.drupal.org/docs/8/core/modules/rest/3-post-for-creating-content-entities