Since WordPress 5.7 you can make use of the wp_script_attributes filter:
add_filter('wp_script_attributes', function ($attributes) {
  if ($attributes['id'] === 'jquery-js') {
    $attributes['integrity'] = 'foobar';
    $attributes['crossorigin'] = 'anonymous';
  }
  return $attributes;
});