Harpocrates: A Statically Typed Privacy Conscious Programming Framework

Sinan Pehlivanoglu, Malte Schwarzkopf

TL;DR

Harpocrates is a new Scala compiler plugin and framework that automates privacy policy enforcement using "oblivious membranes." By centralizing privacy logic and automatically wrapping sensitive data at the type level, it prevents accidental data leaks while allowing developers to write standard, idiomatic code with minimal performance overhead.

What Problem Does This Paper Address?

Modern privacy regulations like GDPR are moving targets—complex, evolving, and distributed across microservices. Traditionally, developers handle privacy in one of two ways:

  1. Manual Checks: Writing if statements before accessing sensitive data. This is highly prone to human error; it only takes one forgotten check to cause a massive data leak.
  2. Monadic/Static IFC: Using complex types (like Monads) or specialized languages to track data flow. While safer, these often require massive code refactors, break existing libraries, and struggle with dynamic policies (e.g., "only show this email if the user is the owner").

The authors identify a "usability-security" gap: existing tools are either too dangerous (manual) or too difficult to use in real-world production environments (academic IFC).

Methods

Harpocrates introduces Oblivious Membranes through a 15-phase Scala compiler plugin. Key technical components include:

  • The enforce Keyword: Developers annotate data constructors with a policy (e.g., email: Email enforce EmailPolicy). The compiler then ensures this data only exists in a protected form within the application.
  • Structural Equality & Method Dispatch: To keep the framework "oblivious," the compiler copies all methods from the original data type onto the Policy wrapper. This allows a developer to call .length() on a Policy[String] as if it were a regular String, without manual unwrapping.
  • Inorganic Policies: When a developer transforms protected data (e.g., extracting an address from a protected User object), the compiler automatically generates a new "Inorganic Policy" for the result, ensuring the privacy protection "sticks" to the data as it flows through the system.
  • Scoped Controllers: These allow for context-aware declassification. For example, a "Scoped Controller" can implicitly signal to the policy engine that the current request is coming from the data owner, allowing the policy to pass.
  • TASTy Integration: By leveraging Scala 3’s TASTy (Typed Abstract Syntax Trees) format, Harpocrates can analyze and protect types even when they are imported from external libraries.

Datasets

The framework was evaluated by integrating it into Vizion, a real-world project management microservice for musicians.

  • Scale: The integration focused on the publicity module of an application consisting of over 20,000 lines of code.
  • Comparison: The authors compared the Harpocrates-enhanced version against a "Base" version (no checks) and a "Manual" version (standard if statement checks).

Key Insights and Ideas

  • Centralization is Key: By moving privacy logic out of the business logic and into a dedicated Policy class, maintainers can update compliance rules (e.g., changing a GDPR retention policy) in one file without touching the rest of the codebase.
  • Obliviousness Reduces Friction: The "aha moment" is that privacy tools fail when they make the developer's life harder. By making the policy wrapper behave exactly like the underlying data, Harpocrates allows the use of favorite libraries and standard patterns without "monad hell."
  • Conservative by Default: The compiler wraps any method that might have side effects in a policy check. While this adds a small overhead, it ensures that data cannot "escape" the application boundary (like being sent to a database or log) without being verified.

Key Results

  • Developer Effort: Integrating Harpocrates into the Vizion module required changing only 17 lines of existing code and adding 45 lines of policy definitions.
  • Compile-Time Overhead: The plugin adds roughly 12.4% overhead to clean builds compared to the base application, which the authors argue is acceptable for the safety gained.
  • Runtime Performance:
    • Harpocrates showed an 8% runtime overhead compared to manual checks.
  • In a "conservative" stress test with eight artificial application boundaries, the overhead peaked at 11%.
  • The authors note that most of this overhead comes from the necessary database calls to verify permissions, which would occur regardless of the enforcement method.

Limitations and Future Work

  • Asynchrony: Currently, the framework requires developers to manually resolve Promises or Futures within check functions. The authors suggest that future versions could use "Tagless Final" patterns to better support effect systems like Cats Effect or ZIO.
  • Java Interop: Harpocrates does not currently support Java classes or interfaces, which is a hurdle for Scala projects heavily reliant on the broader JVM ecosystem.
  • Language Features: Certain Scala features, such as private fields, import renames, and nested classes inside policies, are not yet supported.
  • Distributed Systems: While it works well within a single microservice, the authors highlight the need to investigate how these policies can be serialized and enforced across distributed service boundaries.

Summary updated

BibTeX
@inproceedings{pehlivanoglu2024harpocrates,
  author = {Sinan Pehlivanoglu and Malte Schwarzkopf},
  title = {{Harpocrates: A Statically Typed Privacy Conscious Programming Framework}},
  booktitle = {Open},
  year = {2024},
}
Figure