# US 2008/0083012 A1 · Program instrumentation method and apparatus for constraining the behavior of embedded script in documents

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2008/0083012 A1
- Document ID: US20080083012A1
- Status: Published application
- Kind: A1
- Application number: 11/765,918
- Filed: 2007-06-20
- Published: 2008-04-03
- Earliest claimed: 2006-06-26
- Inventors: Dachuan Yu; Ajay Chander; Nayeem Islam
- Web page: https://patentgrep.com/patent/US20080083012A1

## CPC

- H04L 63/1441: {Countermeasures against malicious traffic (countermeasures against attacks on cryptographic mechanisms H04L9/002)}
- G06F 21/50: Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
- G06F 21/51: at application loading time, e.g. accepting, rejecting, starting or inhibiting executable software based on integrity or source reliability
- G06F 21/56: Computer malware detection or handling, e.g. anti-virus arrangements
- H04L 63/1483: {service impersonation, e.g. phishing, pharming or web spoofing (detection of rogue wireless access points H04W12/12)}
- H04L: TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION (arrangements common to telegraphic and telephonic communication H04M)
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method and apparatus is disclosed herein for constraining the behavior of embedded script in documents using program instrumentation. In one embodiment, the method comprises downloading a document with a script program embedded therein, inspecting the script program, and rewriting the script program to cause behavior resulting from execution of the script to conform to one or more policies defining safety and security. The script program comprises self-modifying code (e.g., dynamically generated script).

## Claims

### Claim 1

A method comprising:
downloading a document with a script program embedded therein, wherein the script program comprises self-modifying code;
inspecting the script program; and
rewriting the script program to cause behavior resulting from execution of the script to conform to one or more policies defining safety and security.

### Claim 2 (depends on 1)

The method defined in claim 1 wherein the self-modifying code comprises dynamically-generated JavaScript.

### Claim 3 (depends on 1)

The method defined in claim 1 wherein rewriting the script program comprises performing syntax-directed rewriting on demand.

### Claim 4 (depends on 1)

The method defined in claim 1 wherein rewriting the script program comprises inserting a run-time check into the script program.

### Claim 5 (depends on 4)

The method defined in claim 4 wherein the run-time check comprises one or more of a group consisting of a security check and a user warning.

### Claim 6 (depends on 4)

The method defined in claim 4 wherein the run-time check comprises code, which when executed at run-time, causes a call to an instrumentation process to instrument the script program in the document in response to performing an evaluation operation of the document.

### Claim 7 (depends on 1)

The method defined in claim 1 wherein rewriting the script program comprises adding code to redirect an action through a policy module during run-time execution.

### Claim 8 (depends on 7)

The method defined in claim 7 further comprising the policy module performing a replacement action for the action at run-time.

### Claim 9 (depends on 1)

The method defined in claim 1 wherein the rewritten script program is part of an instrumented version of the document.

### Claim 10 (depends on 9)

The method defined in claim 9 wherein the instrumented version of the document includes hidden script, and further comprising rewriting the hidden script when the hidden script is generated during run-time.

### Claim 11 (depends on 1)

The method defined in claim 1 wherein rewriting the script program comprises:
parsing the document into abstract syntax trees;
performing rewriting on the abstract syntax trees; and
generating instrumented script code and an instrumented document from the abstract syntax trees.

### Claim 12 (depends on 1)

The method defined in claim 1 wherein the one or more policies are dynamically modifiable.

### Claim 13 (depends on 1)

The method defined in claim 1 wherein the one or more policies are expressed as edit automata.

### Claim 14 (depends on 1)

The method defined in claim 1 wherein at least one policy transforms a first action sequence in script program to a second action sequence different than the first action sequence.

### Claim 15 (depends on 1)

The method defined in claim 1 wherein the one or more policies comprise one policy that combines multiple policies into one policy.

### Claim 16 (depends on 1)

The method defined in claim 1 further comprising:
maintaining states relevant to an edit automaton of the policy, including a current state and a complete transition function; and
calling a check function on an action and, in response thereto, advancing the state of the automaton and provides a replacement action for the action.

### Claim 17 (depends on 1)

The method defined in claim 1 wherein the document is an HTML document.

### Claim 18 (depends on 1)

The method defined in claim 1 wherein the script program is one of a group consisting of JavaScript and an ECMAscript-based program.

### Claim 19 (depends on 1)

The method defined in claim 1 wherein downloading the document is performed by a browser or other software that includes an interpreter for JavaScript program or an interpreter for an ECMAscript-based program in a client.

### Claim 20

A proxy comprising:
a policy management module to implement a security policy;
a rewriting module to perform a rewriting process to rewrite a script embedded in a document based on the security policy, wherein the script program comprises self-modifying code, wherein the rewriting process instruments the document based on one or more policies to control the script in the document so that behavior resulting from execution of the script conforms to safety and security requirements;
an interpretation module to interpret instructions added to the scripts during rewriting.

### Claim 21 (depends on 20)

The proxy defined in claim 20 wherein the proxy comprises a part of a browser.

### Claim 22 (depends on 20)

The proxy defined in claim 20 wherein execution of one of the instructions added to the script program causes an expression corresponding to the document with the script embedded therein to be evaluated at run-time and cause a document generated by the interpretation module at run-time to be sent through the rewriting module to undergo a rewriting process.

### Claim 23 (depends on 20)

The proxy defined in claim 20 wherein the policy management module and the rewriting module are separate modules.

### Claim 24 (depends on 20)

The proxy defined in claim 20 wherein the policy module maintains states relevant to the edit automaton of the policy, including a current state and a complete transition function.

### Claim 25 (depends on 24)

The proxy defined in claim 24 wherein the policy module is called with a check function on an action and, in response thereto, advances the state of the automaton and provides a replacement action for the action.

### Claim 26 (depends on 20)

The proxy defined in claim 20 wherein the document is downloaded from a networked environment in response to a request from a browser.

### Claim 27 (depends on 20)

The proxy defined in claim 20 wherein the rewriting module:
parses documents into abstract syntax trees.
performs rewriting on the abstract syntax trees, and
generates instrumented script code and documents from the abstract syntax trees.

### Claim 28

An article of manufacturing having one or more machine-readable media storing instructions which, when executed by a machine, cause the machine to:
download a document with a script program embedded therein, wherein the script program comprises self-modifying code;
inspect the script program; and
rewrite the script program to cause behavior resulting from execution of the script to conform to one or more policies defining safety and security.
