diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index b3a393a6..b08130d1 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ from PyQt5 import QtCore, QtWidgets, QtGui -import sys, platform, datetime +import sys, platform, datetime, re from onionshare import strings, common from onionshare.settings import Settings @@ -688,11 +688,20 @@ class SettingsDialog(QtWidgets.QDialog): # provided from https://bridges.torproject.org new_bridges = [] bridges = self.tor_bridges_use_custom_textbox.toPlainText().split('\n') + bridges_valid = False for bridge in bridges: if bridge != '': - new_bridges.append(''.join(['Bridge ', bridge, '\n'])) - new_bridges = ''.join(new_bridges) - settings.set('tor_bridges_use_custom_bridges', new_bridges) + # Check the syntax of the custom bridge to make sure it looks legitimate + pattern = re.compile("[0-9.]+:[0-9]+\s[A-Z0-9]+$") + if pattern.match(bridge): + new_bridges.append(''.join(['Bridge ', bridge, '\n'])) + bridges_valid = True + if bridges_valid: + new_bridges = ''.join(new_bridges) + settings.set('tor_bridges_use_custom_bridges', new_bridges) + else: + Alert(strings._('gui_settings_tor_bridges_invalid', True)) + settings.set('no_bridges', True) return settings diff --git a/share/locale/en.json b/share/locale/en.json index cfdcdb6d..9b5fcac6 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -95,6 +95,7 @@ "gui_settings_tor_bridges_obfs4_radio_option": "Use obfs4 pluggable transports", "gui_settings_tor_bridges_custom_radio_option": "Use custom bridges", "gui_settings_tor_bridges_custom_label": "You can get bridges from https://bridges.torproject.org", + "gui_settings_tor_bridges_invalid": "None of the bridges you supplied seem to be valid, so they've been ignored.\nPlease try again with valid bridges.", "gui_settings_button_save": "Save", "gui_settings_button_cancel": "Cancel", "gui_settings_button_help": "Help",