Skip to content

Add threat model#133

Open
bioball wants to merge 7 commits into
apple:mainfrom
bioball:threat-model
Open

Add threat model#133
bioball wants to merge 7 commits into
apple:mainfrom
bioball:threat-model

Conversation

@bioball
Copy link
Copy Markdown
Member

@bioball bioball commented Jun 3, 2026

No description provided.

Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
PklProject.deps.json:: The dependency list, generated by `pkl project resolve`.
Contains resolved versions and SHA-256 checksums for all declared package dependencies.

Root directory:: A filesystem boundary configured via `--root-dir` that restricts `file:` reads to files within that path.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This affects imports and jar:file: URIs as well.

It doesn't affect: multiple file output from the CLI, package caching, loading settings.pkl, and external/custom readers. Did I miss anything?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also doesn't affect loading PklProject, PklProject.deps.json. But these are also behaviors of the CLI specifically, not the language runtime.

Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated

== Threats

=== Language Runtime
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is missing mention of DoS attacks and the use of timeouts as mitigation.

Copy link
Copy Markdown
Member Author

@bioball bioball Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think timeouts would really address this problem; you can still write a program that exhausts CPU/memory resources before a timeout hits.

Pkl would need flags for CPU/memory bounds, which we ideally should have.

Security vulnerabilities may be reported on the link:https://security.apple.com/submit[Report a vulnerability] form.
When submitting a vulnerability, select "Apple Devices and Software" as the affected platform, and "Open Source" as the affected area.

If you are not certain if something counts as a security vulnerability, you can review our xref:threat-model.adoc[threat model].
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it might be good to explicitly call out up front that reports relying on evaluating untrusted code are only valid if Pkl's sandbox is bypassed and that overly broad (or default) evaluator settings are not considered a vulnerability.

Comment thread landing/modules/ROOT/pages/threat-model.adoc

Insecure Evaluator Client configurations::

Users who configure overly broad evaluator permissions while executing un-trusted Pkl code.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Users who configure overly broad evaluator permissions while executing un-trusted Pkl code.
Overly broad evaluator permissions while executing un-trusted Pkl code that can result in compromise.

Copy link
Copy Markdown
Member Author

@bioball bioball Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"User" here is referring to one of the external actors in the section above; it's to distinguish from, say, our language binding configures the evaluator insecurely which would be in-scope.

Comment on lines +147 to +148
The Language Runtime enforces I/O permissions set by the Evaluator Client before evaluation begins.
No Pkl code can modify these settings at runtime.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth noting that evaluators setting may be set via settings.pkl and/or PklProject so these files must be trusted or restricted as well. Probably worth calling out --no-project/--omit-project-settings and the override behavior of evaluator settings.

Copy link
Copy Markdown

@madrob madrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking thoughts.

==== Package Integrity

When importing a package, the runtime verifies the package's contents against a SHA-256 checksum declared in the project's dependency list (`PklProject.deps.json`).
This verification is independent of which server served the package, providing integrity guarantees even if the package server is compromised or the connection is intercepted.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also cover the local cache, in addition to remote servers.

Copy link
Copy Markdown
Member Author

@bioball bioball Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local cache is trusted and their contents aren't verified; attacks that require that an attacker have write permissions to the filesystem is considered out-of-scope.


=== Package Resolution

==== Tampered Package
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this belongs here or in supply chain, but we should call out that we do not offer protection against typo-squatting. Maybe in the future we can build a system to do that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRT building a system that prevents typosquatting: that's currently not a goal; we don't intend on maintaining a package registry anytime soon.

* Pkl cannot perform I/O outside what is explicitly allowed.
* Pkl code cannot modify or exceed the permissions established by the Evaluator Client.
* Pkl cannot execute arbitrary system commands or load native code.
* Pkl will run to completion, or time out.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we consider whatever the Pkl equivalent of adversarial regular expressions or ReDoS out of scope? Maybe a good example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I think that ReDoS is out of scope; guards against DoS attacks would happen via resource limit flags (CPU and memory) if/once we have them.

Open to opinions here though.

If the import URI does not include a SHA-256 checksum segment, the runtime performs no integrity verification and Pkl code within the tampered package is evaluated.

NOTE: Package imports that include a checksum in the URI are verified against the declared hash.
Direct imports without a checksum (e.g., `package://example.com/pkg@1.0.0#/mod.pkl`) are not verified.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserves its own item on the list, feels like a big deal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify? This is already its own item?

@@ -0,0 +1,392 @@
= Threat Model
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a version and date so that users can identify how recently reviewed this was.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a "last edited" date. Is the version useful? Can the edited date serve as the version?


[source,pkl]
----
import "package://example.com/pkg@1.0.0#/myModule.pkl"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd add another example showing an import that does verify package integrity.


* Pkl cannot perform I/O outside what is explicitly allowed.
* Pkl code cannot modify or exceed the permissions established by the Evaluator Client.
* Pkl cannot execute arbitrary system commands or load native code.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teechnically, due to external readers, Pkl can execute arbitrary code. But this is explained in other parts of this doc, so it's probably fine to not point this out here.

Comment on lines +351 to +352
Package imports that include a checksum in the URI are verified against the declared hash.
Direct imports without a checksum (e.g., `package://example.com/pkg@1.0.0#/mod.pkl`) are not verified.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also happen with regular project imports, not only direct package imports.
If the cache does not contain package X and an attacker tampered with it, Pkl will download the malicious package and cache it locally.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PklProject.deps.json file guards against this; it includes the checksum of all dependencies and verifies them when downloading.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It protects you from a package version you already know about being tampered. It doesn't protect you from a package version being tampered before you store the checksum.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's the "trust on first use" policy; definitely worth mentioning.

Users whose package imports do not include checksums would fetch and execute malicious packages without any verification failure.

*Attacker:* Remote Attacker; Network Attacker +
*Violates:* _pkg.pkl-lang.org only redirects to official Pkl-hosted content_; _Imported package dependencies are authentic_
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_pkg.pkl-lang.org only redirects to official Pkl-hosted content_ is not in the Security Goals.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I had that initially but got rid of it.

Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Comment thread landing/modules/ROOT/pages/threat-model.adoc Outdated
Co-authored-by: Islon Scherer <islonscherer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants