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

Sune Vuorela <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 69cb4cbc3b7928b51485f06d760f14430dd8e3f1 by Sune Vuorela.
Committed on 07/08/2026 at 13:56.
Pushed by sune into branch 'release/26.08'.

Don't execute load-scripts on signed documents

(cherry picked from commit 026f487a9cbf318b73ad57bfb2f2de682924e671)

M  +20   -0    core/scripter.cpp

https://invent.kde.org/graphics/okular/-/commit/69cb4cbc3b7928b51485f06d760f14430dd8e3f1

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.