Skip to content

AST Sandboxing & Security

To protect host infrastructure and maintain tenant boundaries, all .pb.js code uploaded via the console or Remote MCP undergoes automated Abstract Syntax Tree (AST) static verification.

AST Verification Pipeline

flowchart TD
    JS["📄 JavaScript Server Hook (.pb.js)"] --> Parser["1. Static AST Analysis Engine"]
    
    subgraph ASTValidation ["Automated Security Checks"]
        Check1{"Forbidden OS Call?<br/>(exec, spawn, child_process, fs)"}
        Check2{"Arbitrary Eval?<br/>(eval, Function constructor)"}
        Check3{"Unauthorized Socket Bind?"}
    end

    Parser --> Check1
    Check1 -->|Pass| Check2
    Check2 -->|Pass| Check3

    Check1 -->|Violation| Reject["❌ Rejected with AST Syntax Error"]
    Check2 -->|Violation| Reject
    Check3 -->|Violation| Reject

    Check3 -->|All Checks Pass| Sandbox["🔒 Goja ECMAScript Runtime Sandbox"]
    Sandbox --> PocketBase["⚡ Active PocketBase Database Hooks & APIs"]

Prohibited JavaScript Patterns

  • Direct require('child_process') or require('fs')
  • Raw system command execution (exec, spawn, fork)
  • Direct binding to unauthorized non-loopback network ports
  • Evaluation of untrusted dynamic strings via eval()

Safe Goja Global Bindings

Hooks execute inside the standard Goja ECMAScript runtime and have safe access to:

  • $app: PocketBase application instance (queries, collections, records, logs)
  • $http: Outgoing HTTP client ($http.send)
  • $security: Cryptographic hashing and token generation ($security.hs256, $security.randomString)
  • $os: Safe environment variables ($os.getenv)