File Security 101 - Threats Beyond Malware explained

JavaScript Runs the Moment the File Opens: How PDF Open Actions Start Scripts

Written by Joerg Schneider-Simon | Dec 3, 2026, 2:09:21 PM

A PDF can tell your reader to run a script the moment you open it, before you have read a single line. This is episode 18 of File Security 101, our series on file-based threats your anti-malware does not see.

The video explains it in about two minutes.
The article adds the details and the research behind it.

A PDF that runs code

An invoice arrives as a PDF. You open it, check the amount and close it. Nothing seems to happen. But PDF readers such as Adobe Acrobat and Reader include a programming language, JavaScript, intended for forms that calculate totals, validate input or react to clicks. And a PDF can tell the reader to run a script without any click at all.

The open action runs a script

Inside, a PDF is a list of numbered objects. The document catalog, the object the reader reads first, can hold an /OpenAction entry: what the reader does as soon as the file opens. In episode 1, that action started a program. Here it points to an action of type /S /JavaScript, whose /JS entry holds the script, either as a text string or as a stream that is usually compressed with /FlateDecode.

The script does not run in a web browser but in the reader's own JavaScript engine, which offers a large interface of its own: objects such as app, doc, util and media, with functions for forms, printing, media playback, links and much more. Every one of these functions is code that an attacker's script can call, with any arguments it likes.

The attack: before you read

The attacker writes a script that calls one of these functions with data the reader does not expect. If the function has a bug, the call corrupts the reader's memory, and with careful preparation the attacker's own code runs, with the rights of the user who opened the file. Other scripts first check the reader's version, through app.viewerVersion, and only then decide what to do, or simply open a download link. All of this happens while the first page is still being drawn.

It happened

Adobe's JavaScript interface has been a target for years. On December 15, 2009, Adobe confirmed that a vulnerability in Reader and Acrobat 9.2 and earlier was being actively exploited. The bug was a use-after-free in the Doc.media.newPlayer method, CVE-2009-4324. Until a patch was available on January 12, 2010, Adobe's recommended workaround was to uncheck "Enable Acrobat JavaScript" or to block the function with its JavaScript blacklist.

In May 2018, ESET researcher Anton Cherepanov described a PDF uploaded to a public malware repository that combined two zero-days. In his words: "Once the PDF file is opened, the JavaScript code is executed." The script exploited a double free in Reader, CVE-2018-4990, and then a Windows kernel bug, CVE-2018-8120, to break out of Reader's sandbox. The sample carried no final payload, which suggests it was caught during development. Adobe fixed the Reader bug on May 14, 2018 (APSB18-09).

CVE-2009-4324, CVE-2018-4990 and CVE-2018-8120 are all in CISA's catalog of known exploited vulnerabilities.

Why it slips through

Unlike the files in some other episodes, these PDFs do carry malicious code, and scanners do look for known exploit scripts. But a script can be compressed, split into pieces across several objects, assembled at runtime and rewritten for every mail. And a brand-new bug has no signature yet: the 2018 sample was found before any patch existed.

What to do

  • If you do not need PDF forms that calculate, turn off JavaScript in your reader. In Adobe Acrobat and Reader: Edit > Preferences > JavaScript, uncheck "Enable Acrobat JavaScript". Administrators can enforce this centrally.
  • Keep the reader updated, and keep its sandbox (Protected Mode) turned on.

Settings protect one computer at a time and are easily turned back on when a form does not work. bowbridge Content Disarm and Reconstruct rebuilds the PDF from only its visible content: text, images and layout. Document-level actions are not copied, so no /OpenAction and no JavaScript survive, whatever reader opens the file later. The visible page comes through unchanged.

Join the bowbridge CDR beta program

Sources

Subscribe to upcoming episodes