How to allow any file extension (or use a blacklist instead of a whitelist) for file fields in Drupal 8? For a file field, it’s required to enter file extensions in "Allowed file extensions". 

Is there a way to allow any file extension? Or a way to switch from a whitelist to a blacklist?

What I found


For Drupal 7, there is the module Allow All File Extensions. A Drupal 8 port doesn’t seem to be planned.
For Drupal 7, there is the question How to allow for files of any extension to be uploaded?, where the module mentioned above is recommended.
For Drupal 8, there is the issue Not possible to allow uploading files with any file extension, but it seems to be inactive.
Implement a hook alter on the node form or the field level and  in it change the validator to your custom function:

/**
 * alter form field element:.
 * 
 * Implements hook_FORM_alter
 */
function my_module_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $upload_validators = array(
        'my_module_file_validate_extensions_blacklist' =&gt; ['jpg jpeg gif png mp4']
    );
    $form['your_file_field_element']['#upload_validators'] = $upload_validators;

}


Alternatively you can change the behavior of the field on any node, or entity by altering the widget form:

function mymodule_field_widget_form_alter(&amp;$element, &amp;$form_state, $context) {  
   if ( "condition to check if it's your field" == TRUE) {
     $upload_validators = array(
            'my_module_file_validate_extensions_blacklist' =&gt; ['jpg jpeg gif png mp4']
        );
        $element['#upload_validators'] = $upload_validators;
  }
}


Then write you own function to do what you want:

function my_module_file_validate_extensions_blacklist(stdClass $file, $extensions) {
  $errors = array();
  $regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
  if (preg_match($regex, $file-&gt;filename)) {
    $errors[] = t('files with the following extensions are not allowed: %files-allowed.', array(
      '%files-allowed' =&gt; $extensions,
    ));
  }
  return $errors
}