Skip to content

Commit

Permalink
[libcontentaction] Add configuration options to restrict the invokati…
Browse files Browse the repository at this point in the history
…on of .desktop files. Contributes to JB#43964

This helps prevent .desktop files of unknown origin being used as an
executable scripts.
  • Loading branch information
adenexter committed Feb 26, 2019
1 parent 23e2f3b commit 9c8596b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data/data.pro
Expand Up @@ -28,3 +28,9 @@ highlight1.path = $$CONTENTACTION_DATADIR
highlight1.files = highlight1.xml
highlight1.CONFIG += no_check_exist
INSTALLS += highlight1

dconf_locks.files = \
locks/application_desktop_paths.txt
dconf_locks.path = /etc/dconf/db/vendor.d/locks

INSTALLS += dconf_locks
2 changes: 2 additions & 0 deletions data/locks/application_desktop_paths.txt
@@ -0,0 +1,2 @@
/desktop/sailfish/application_desktop_paths

1 change: 1 addition & 0 deletions rpm/libcontentaction-qt5.spec
Expand Up @@ -78,6 +78,7 @@ rm -rf %{buildroot}
%{_datadir}/contentaction/highlight1.xml
%{_datadir}/contentaction/tracker1.xml
%{_libdir}/libcontentaction5.so.*
%{_sysconfdir}/dconf/db/vendor.d/locks/application_desktop_paths.txt

%files devel
%defattr(-,root,root,-)
Expand Down
42 changes: 42 additions & 0 deletions src/contentaction.cpp
Expand Up @@ -24,6 +24,7 @@
#include "service.h"

#include <MDesktopEntry>
#include <MGConfItem>
#include <QFileInfo>

/*!
Expand Down Expand Up @@ -65,6 +66,45 @@ const QString XMaemoObjectPathKey("Desktop Entry/X-Maemo-Object-Path");
const QString ExecKey("Desktop Entry/Exec");
const QString URLKey("Desktop Entry/URL");
const QString TypeKeyValueLink("Link");

}

namespace {

QStringList applicationDesktopPaths()
{
QStringList desktopPaths;
const QVariant configuration = MGConfItem(
QLatin1String("/desktop/sailfish/application_desktop_paths")).value();

if (configuration.isValid()) {
for (const QString &path : configuration.toStringList()) {
if (!path.isEmpty() && path.startsWith(QLatin1Char('/'))) {
desktopPaths.append(path.endsWith(QLatin1Char('/')) ? path : path + QLatin1Char('/'));
}
}
}
return desktopPaths;
}

Q_GLOBAL_STATIC_WITH_ARGS(QStringList, desktopPaths, (applicationDesktopPaths()))

bool isApplicationDesktopPath(const QString &path)
{
const QStringList paths = *desktopPaths();

if (paths.isEmpty()) {
return true;
}

for (const QString &desktopPath : paths) {
if (path.startsWith(desktopPath)) {
return true;
}
}
return false;
}

}

ActionPrivate::~ActionPrivate()
Expand Down Expand Up @@ -173,6 +213,8 @@ Action createAction(QSharedPointer<MDesktopEntry> desktopEntry,
if (desktopEntry->type() == TypeKeyValueLink &&
desktopEntry->contains(URLKey)) {
return Action::defaultActionForScheme(desktopEntry->url());
} else if (!isApplicationDesktopPath(desktopEntry->fileName())) {
return Action();
} else if (desktopEntry->contains(XMaemoMethodKey) &&
!desktopEntry->contains(XMaemoServiceKey)) {
return Action(new ServiceFwPrivate(desktopEntry, params));
Expand Down

0 comments on commit 9c8596b

Please sign in to comment.