[graphics/okular] core: Don't execute load-scripts on signed documents

Sune Vuorela <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 026f487a9cbf318b73ad57bfb2f2de682924e671 by Sune Vuorela.
Committed on 07/08/2026 at 12:30.
Pushed by sune into branch 'master'.

Don't execute load-scripts on signed documents

M  +20   -0    core/scripter.cpp

https://invent.kde.org/graphics/okular/-/commit/026f487a9cbf318b73ad57bfb2f2de682924e671

diff --git a/core/scripter.cpp b/core/scripter.cpp
index bbb36b664..221ff3753 100644
--- a/core/scripter.cpp
+++ b/core/scripter.cpp
@@ -12,6 +12,9 @@
 #include <QFile>
 
 #include "debug_p.h"
+#include "document_p.h"
+#include "form.h"
+#include "page.h"
 #include "script/executor_js_p.h"
 
 using namespace Okular;
@@ -28,6 +31,7 @@ public:
     }
 
     DocumentPrivate *m_doc;
+    bool isDigitallySigned = false;
 #if HAVE_JS
     QScopedPointer<ExecutorJS> m_js;
 #endif
@@ -36,6 +40,18 @@ public:
 Scripter::Scripter(DocumentPrivate *doc)
     : d(new ScripterPrivate(doc))
 {
+    for (const auto *page : std::as_const(d->m_doc->m_pagesVector)) {
+        const QList<Okular::FormField *> formFields = page->formFields();
+        for (const Okular::FormField *f : formFields) {
+            if (f->type() == Okular::FormField::FormSignature) {
+                d->isDigitallySigned = true;
+                break;
+            }
+        }
+        if (d->isDigitallySigned) {
+            break;
+        }
+    }
 }
 
 Scripter::~Scripter()
@@ -47,6 +63,10 @@ void Scripter::execute(Event *event, ScriptType type, const QString &script)
 {
     qCDebug(OkularCoreDebug) << "executing the script:" << script;
 #if HAVE_JS
+    if (d->isDigitallySigned && event->eventType() == Event::DocOpen) {
+        qWarning(OkularCoreDebug) << "Not executing DocOpen script on signed document";
+        return;
+    }
     static QString builtInScript;
     if (builtInScript.isNull()) {
         QFile builtInResource(QStringLiteral(":/script/builtin.js"));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.