Skip to content

Commit 1cd12c1

Browse files
committed
forms: Add configuration to enable external access
After discussion in the Discord server, and some internal discussion, this was deemed a reasonable patch for various security concerns. This basically controls whether obs-websocket binds to 127.0.0.1 or 0.0.0.0. I decided to have obs-websocket bind to 127.0.0.1 by default, since most users appear to be using obs-websocket on the same machines as their client software. This will be changed if it poses significant support-related issues. Further security solutions have been discussed, but are either a heavy amount of work, or significantly impact client applications' connect flows. One idea that I should mention is like a cookie system, where: - On first connect, obs-websocket asks the user to approve the connection. - After authentication, obs-websocket gives the client a token in the `Identified` message, which the client stores. - On future connects, the client uses this token, along with the password, to authenticate without needing user confirmation. This system will likely be implemented in a future version of obs-websocket. Closes #907
1 parent 1da0214 commit 1cd12c1

File tree

5 files changed

+79
-21
lines changed

5 files changed

+79
-21
lines changed

data/locale/en-US.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ OBSWebSocket.Settings.DebugEnable="Enable Debug Logging"
99
OBSWebSocket.Settings.DebugEnableHoverText="Enables debug logging for the current instance of OBS. Does not persist on load.\nUse --websocket_debug to enable on load."
1010

1111
OBSWebSocket.Settings.ServerSettingsTitle="Server Settings"
12+
OBSWebSocket.Settings.ServerPort="Server Port"
13+
OBSWebSocket.Settings.AllowExternal="Allow External Access"
14+
OBSWebSocket.Settings.AllowExternalHoverText="Allows clients from outside this computer to connect to obs-websocket."
1215
OBSWebSocket.Settings.AuthRequired="Enable Authentication"
1316
OBSWebSocket.Settings.Password="Server Password"
1417
OBSWebSocket.Settings.GeneratePassword="Generate Password"
15-
OBSWebSocket.Settings.ServerPort="Server Port"
1618
OBSWebSocket.Settings.ShowConnectInfo="Show Connect Info"
19+
OBSWebSocket.Settings.ShowConnectInfoHoverText="Connect Info is not available if external connections are disabled."
1720
OBSWebSocket.Settings.ShowConnectInfoWarningTitle="Warning: Currently Live"
1821
OBSWebSocket.Settings.ShowConnectInfoWarningMessage="It appears that an output (stream, recording, etc.) is currently active."
1922
OBSWebSocket.Settings.ShowConnectInfoWarningInfoText="Are you sure that you want to show your connect info?"

src/forms/SettingsDialog.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
5252
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
5353

5454
// Set the appropriate tooltip icon for the theme
55-
ui->enableDebugLoggingToolTipLabel->setText(GetToolTipIconHtml());
55+
QString toolTipHtml = GetToolTipIconHtml();
56+
ui->enableDebugLoggingToolTipLabel->setText(toolTipHtml);
57+
ui->allowExternalToolTipLabel->setText(toolTipHtml);
5658

5759
connect(sessionTableTimer, &QTimer::timeout,
5860
this, &SettingsDialog::FillSessionTable);
@@ -83,18 +85,8 @@ void SettingsDialog::showEvent(QShowEvent *)
8385
return;
8486
}
8587

86-
ui->enableWebSocketServerCheckBox->setChecked(conf->ServerEnabled);
87-
ui->enableSystemTrayAlertsCheckBox->setChecked(conf->AlertsEnabled);
88-
ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled);
89-
ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired);
90-
ui->serverPasswordLineEdit->setText(conf->ServerPassword);
91-
ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired);
92-
ui->generatePasswordButton->setEnabled(conf->AuthRequired);
93-
ui->serverPortSpinBox->setValue(conf->ServerPort);
94-
95-
if (conf->PortOverridden) {
88+
if (conf->PortOverridden)
9689
ui->serverPortSpinBox->setEnabled(false);
97-
}
9890

9991
if (conf->PasswordOverridden) {
10092
ui->enableAuthenticationCheckBox->setEnabled(false);
@@ -104,7 +96,7 @@ void SettingsDialog::showEvent(QShowEvent *)
10496

10597
passwordManuallyEdited = false;
10698

107-
FillSessionTable();
99+
RefreshData();
108100

109101
sessionTableTimer->start(1000);
110102
}
@@ -125,6 +117,31 @@ void SettingsDialog::ToggleShowHide()
125117
setVisible(false);
126118
}
127119

120+
void SettingsDialog::RefreshData()
121+
{
122+
auto conf = GetConfig();
123+
if (!conf) {
124+
blog(LOG_ERROR, "[SettingsDialog::RefreshData] Unable to retreive config!");
125+
return;
126+
}
127+
128+
ui->enableWebSocketServerCheckBox->setChecked(conf->ServerEnabled);
129+
ui->enableSystemTrayAlertsCheckBox->setChecked(conf->AlertsEnabled);
130+
ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled);
131+
ui->serverPortSpinBox->setValue(conf->ServerPort);
132+
ui->allowExternalCheckBox->setChecked(!conf->BindLoopback);
133+
ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired);
134+
ui->serverPasswordLineEdit->setText(conf->ServerPassword);
135+
136+
ui->showConnectInfoButton->setEnabled(!conf->BindLoopback);
137+
ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired);
138+
ui->generatePasswordButton->setEnabled(conf->AuthRequired);
139+
140+
ui->showConnectInfoButton->setToolTip(ui->allowExternalCheckBox->isChecked() ? "" : obs_module_text("OBSWebSocket.Settings.ShowConnectInfoHoverText"));
141+
142+
FillSessionTable();
143+
}
144+
128145
void SettingsDialog::DialogButtonClicked(QAbstractButton *button)
129146
{
130147
if (button == ui->buttonBox->button(QDialogButtonBox::Ok)) {
@@ -173,17 +190,20 @@ void SettingsDialog::SaveFormData()
173190

174191
bool needsRestart = (conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) ||
175192
(ui->enableAuthenticationCheckBox->isChecked() && conf->ServerPassword != ui->serverPasswordLineEdit->text()) ||
193+
(conf->BindLoopback == ui->allowExternalCheckBox->isChecked()) ||
176194
(conf->ServerPort != ui->serverPortSpinBox->value());
177195

178196
conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked();
179197
conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked();
180198
conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked();
199+
conf->ServerPort = ui->serverPortSpinBox->value();
200+
conf->BindLoopback = !ui->allowExternalCheckBox->isChecked();
181201
conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked();
182202
conf->ServerPassword = ui->serverPasswordLineEdit->text();
183-
conf->ServerPort = ui->serverPortSpinBox->value();
184203

185204
conf->Save();
186205

206+
RefreshData();
187207
connectInfo->RefreshData();
188208

189209
if (needsRestart) {

src/forms/SettingsDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SettingsDialog : public QDialog
3737
void showEvent(QShowEvent *event);
3838
void hideEvent(QHideEvent *event);
3939
void ToggleShowHide();
40+
void RefreshData();
4041

4142
private Q_SLOTS:
4243
void DialogButtonClicked(QAbstractButton *button);

src/forms/SettingsDialog.ui

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,21 @@
155155
</property>
156156
</widget>
157157
</item>
158-
<item row="1" column="1">
158+
<item row="3" column="1">
159159
<widget class="QCheckBox" name="enableAuthenticationCheckBox">
160160
<property name="text">
161161
<string>OBSWebSocket.Settings.AuthRequired</string>
162162
</property>
163163
</widget>
164164
</item>
165-
<item row="2" column="0">
165+
<item row="4" column="0">
166166
<widget class="QLabel" name="serverPasswordLabel">
167167
<property name="text">
168168
<string>OBSWebSocket.Settings.Password</string>
169169
</property>
170170
</widget>
171171
</item>
172-
<item row="2" column="1">
172+
<item row="4" column="1">
173173
<layout class="QHBoxLayout" name="horizontalLayout">
174174
<item>
175175
<widget class="QLineEdit" name="serverPasswordLineEdit">
@@ -187,7 +187,7 @@
187187
</item>
188188
</layout>
189189
</item>
190-
<item row="3" column="0">
190+
<item row="5" column="0">
191191
<spacer name="horizontalSpacer_2">
192192
<property name="orientation">
193193
<enum>Qt::Horizontal</enum>
@@ -203,13 +203,47 @@
203203
</property>
204204
</spacer>
205205
</item>
206-
<item row="3" column="1">
206+
<item row="5" column="1">
207207
<widget class="QPushButton" name="showConnectInfoButton">
208208
<property name="text">
209209
<string>OBSWebSocket.Settings.ShowConnectInfo</string>
210210
</property>
211211
</widget>
212212
</item>
213+
<item row="1" column="1">
214+
<layout class="QHBoxLayout" name="horizontalLayout_3">
215+
<item>
216+
<widget class="QCheckBox" name="allowExternalCheckBox">
217+
<property name="text">
218+
<string>OBSWebSocket.Settings.AllowExternal</string>
219+
</property>
220+
</widget>
221+
</item>
222+
<item>
223+
<widget class="QLabel" name="allowExternalToolTipLabel">
224+
<property name="toolTip">
225+
<string>OBSWebSocket.Settings.AllowExternalHoverText</string>
226+
</property>
227+
<property name="text">
228+
<string/>
229+
</property>
230+
</widget>
231+
</item>
232+
<item>
233+
<spacer name="horizontalSpacer_4">
234+
<property name="orientation">
235+
<enum>Qt::Horizontal</enum>
236+
</property>
237+
<property name="sizeHint" stdset="0">
238+
<size>
239+
<width>40</width>
240+
<height>20</height>
241+
</size>
242+
</property>
243+
</spacer>
244+
</item>
245+
</layout>
246+
</item>
213247
</layout>
214248
</widget>
215249
</item>

src/websocketserver/WebSocketServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void WebSocketServer::Start()
142142
blog(LOG_INFO, "[WebSocketServer::Start] Locked to IPv4 bindings.");
143143
} else {
144144
_server.listen(conf->ServerPort, errorCode);
145-
blog(LOG_INFO, "[WebSocketServer::Start] Not locked to IPv4 bindings.");
145+
blog(LOG_INFO, "[WebSocketServer::Start] Bound to all interfaces.");
146146
}
147147

148148
if (errorCode) {

0 commit comments

Comments
 (0)