Install imagick module and enable it as default image toolkit.
Add custom code:
/**
* Implements hook_file_insert().
*/
function MYMODULE_file_insert(EntityInterface $file) {
if ($file->getMimeType() === 'image/jpeg') {
$image = \Drupal::service('image.factory')->get($file->getFileUri());
if ($image->getToolkit()->apply('autorotate')) {
$image->save();
}
}
}
If you also want to clean EXIF data add this code
if ($image->getToolkit()->apply('strip')) {
$image->save();
}