Skip to content

Commit 9c3f053

Browse files
committed
[ui] add security warning when executing scripts
1 parent abe1485 commit 9c3f053

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/app/qgisapp.cpp

+26-5
Original file line numberDiff line numberDiff line change
@@ -6056,11 +6056,32 @@ void QgisApp::runScript( const QString &filePath )
60566056
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
60576057
return;
60586058

6059-
mPythonUtils->runString(
6060-
QString( "import sys\n"
6061-
"from qgis.utils import iface\n"
6062-
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
6063-
, tr( "Failed to run Python script:" ), false );
6059+
QgsSettings settings;
6060+
bool showScriptWarning = settings.value( QStringLiteral( "UI/showScriptWarning" ), true ).toBool();
6061+
6062+
QMessageBox msgbox;
6063+
if ( showScriptWarning )
6064+
{
6065+
msgbox.setText( tr( "Security warning: executing a script from an untrusted source can lead to data loss and/or leak. Continue?" ) );
6066+
msgbox.setIcon( QMessageBox::Icon::Warning );
6067+
msgbox.addButton( QMessageBox::Yes );
6068+
msgbox.addButton( QMessageBox::No );
6069+
msgbox.setDefaultButton( QMessageBox::No );
6070+
QCheckBox *cb = new QCheckBox( tr( "Don't show this again." ) );
6071+
msgbox.setCheckBox( cb );
6072+
msgbox.exec();
6073+
settings.setValue( QStringLiteral( "UI/showScriptWarning" ), !msgbox.checkBox()->isChecked() );
6074+
}
6075+
6076+
if ( !showScriptWarning || msgbox.result() == QMessageBox::Yes )
6077+
{
6078+
mPythonUtils->runString(
6079+
QString( "import sys\n"
6080+
"from qgis.utils import iface\n"
6081+
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
6082+
, tr( "Failed to run Python script:" ), false );
6083+
}
6084+
60646085
#else
60656086
Q_UNUSED( filePath );
60666087
#endif

0 commit comments

Comments
 (0)