Force the MIME type for .js files to be text/javascript, to override silly OS databases/registries with incorrect settings, which Flask would otherwise depend on

This commit is contained in:
Miguel Jacq 2021-12-17 17:53:15 +11:00
parent 4b18cb7d0f
commit e6a17bc743
No known key found for this signature in database
GPG key ID: EEA4341C6D97A0B6

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import logging import logging
import mimetypes
import os import os
import queue import queue
import requests import requests
@ -80,6 +81,16 @@ class Web:
self.settings = mode_settings self.settings = mode_settings
# Flask guesses the MIME type of files from a database on the operating
# system.
# Some operating systems, or applications that can modify the database
# (such as the Windows Registry) can treat .js files as text/plain,
# which breaks the chat app due to X-Content-Type-Options: nosniff.
#
# It's probably #notourbug but we can fix it by forcing the mimetype.
# https://github.com/onionshare/onionshare/issues/1443
mimetypes.add_type('text/javascript', '.js')
# The flask app # The flask app
self.app = Flask( self.app = Flask(
__name__, __name__,