Skip to content

Commit fbfc000

Browse files
authored
[ty] Add runtime threat models for Ruff and ty (#28523)
## Summary The repository threat model in #28395 covers CI and release automation. Ruff and ty also need security guidance for their command-line tools, libraries, language servers, and browser playgrounds. Add three models that define trusted inputs, security invariants, and severity for these components, including the public playground sharing API. An index linked from `AGENTS.md` points reviewers to the applicable models. Depends on #28395. ## Test Plan Reviewed the trust assumptions and execution paths against the CLI, language-server, and playground code.
1 parent 6f4d5a4 commit fbfc000

5 files changed

Lines changed: 169 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ request already addresses the issue, do not submit a competing one without maint
1010

1111
## Code Review Rules
1212

13+
For security reviews of Ruff and ty runtime changes, use the
14+
[threat models](agents/references/threat-models.md) to assess trust boundaries and
15+
calibrate severity.
16+
1317
When reviewing a branch or pull request, be deliberately nitpicky. Report not
1418
only bugs and regressions, but also architectural and maintenance risks, weak
1519
test coverage, unclear code, unnecessary complexity, and meaningful style or
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Ruff and ty CLI threat model
2+
3+
## Overview
4+
5+
Ruff is a Python linter and formatter. ty is a Python type checker. Their commands and native
6+
libraries run with the user's or CI worker's permissions.
7+
8+
A behavior is a security issue only when an independent attacker controls a concrete input, Ruff or
9+
ty uses it to cross a boundary defined below, and the crossing gives the attacker new power or harms
10+
a protected asset. Trusted-machine compromise, intended behavior, and correctness defects that give
11+
an attacker no new power are not security issues.
12+
13+
Editors, playgrounds, and repository automation have [separate models](threat-models.md).
14+
15+
## Trust boundaries and assumptions
16+
17+
- **Attacker-controlled:** project files used during analysis, including source code, project
18+
configuration, and dependency source code.
19+
- **Trusted local input:** the operating system, installed programs, environment variables, `PATH`,
20+
caches, user configuration, explicit command-line choices, and user-managed filesystem state that
21+
the attacker cannot change.
22+
23+
## Security invariants
24+
25+
- **Code Execution:** Analysis must not execute user-supplied code.
26+
- **Configuration and file discovery:** Ruff's `--isolated` must ignore configuration files. Imports,
27+
configuration extensions, and symlinks may lead outside the project; reading those files is
28+
expected.
29+
- **Edits and cleanup:** Formatting, fixes, ignore insertion, and cache cleanup may change only the
30+
targets selected by that operation. Formatting with `--check` must preserve source files.
31+
Incorrect fixes are ordinarily correctness bugs.
32+
- **External programs:** ty's uv integration is disabled by default. When enabled, it uses the
33+
executable selected by `UV` or `PATH` for workspace metadata and script environments. Script
34+
synchronization may install dependencies.
35+
- **Output:** Diagnostics may contain source text and paths. They must be encoded for the selected
36+
terminal or CI format so that attacker-controlled text cannot inject commands or active content.
37+
- **Availability:** Failing or slow analysis is a correctness or performance bug.
38+
A security issue requires repeatable, disproportionate resource use that materially disrupts
39+
the developer's machine or CI worker beyond the failed analysis.
40+
41+
## Severity calibration
42+
43+
- **Critical:** With few prerequisites and safe defaults, analysis input compromises credentials
44+
with broad permissions or causes widespread file damage without first compromising a trusted host.
45+
- **High:** A demonstrated path from analysis input to arbitrary native execution, substantial
46+
disclosure of private data, or destructive filesystem access beyond the requested operation.
47+
- **Medium:** A limited unauthorized read or write, or bypass of an execution restriction with
48+
limited effect.
49+
- **Low:** A narrow disclosure or safety gap across a real boundary with limited practical impact,
50+
or reliable resource exhaustion affecting the developer's machine or CI worker.
51+
- **Informational:** A genuine security concern with negligible current impact.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Ruff and ty language server threat model
2+
3+
## Overview
4+
5+
This model covers the Ruff and ty language servers and their interactions with editors. The
6+
[CLI threat model](cli-threat-model.md) also applies. The workspace trust rules below take precedence
7+
when deciding which inputs are trusted. Browser integrations have a separate
8+
[playground model](playground-threat-model.md).
9+
10+
## Trust boundaries and assumptions
11+
12+
- **Attacker-controlled:** all inputs analyzed in an untrusted workspace, including source code,
13+
project configuration, and notebooks.
14+
- **Trusted local input:** the editor, its extensions and their bundled files, the local machine and
15+
its file system, and the user's configuration and trust decisions.
16+
17+
ty treats workspaces as trusted unless `untrustedWorkspace` is true at initialization. Trust extends
18+
to everything in the workspace, including source code, configuration, notebooks, and the targets of
19+
symlinks that point outside it.
20+
21+
## Security invariants
22+
23+
- **Code Execution:** In untrusted workspaces, the editor extension and server may launch executables
24+
bundled with the extension or trusted programs already installed on the host. They must not
25+
execute workspace or dependency code, including code run during installation.
26+
- **Edits:** Only editing operations may change source files, and they must not change unrelated
27+
files.
28+
- **Output:** Attacker-controlled text in diagnostics, documentation, and logs must not inject code
29+
or editor commands. Actions intentionally provided by the editor or language server may run when
30+
the user chooses them.
31+
- **Availability:** An isolated analysis failure or slow analysis is a correctness or performance bug.
32+
A security issue requires repeatable, disproportionate resource use that materially disrupts
33+
the editor or the developer's machine beyond the failed analysis.
34+
35+
## Severity calibration
36+
37+
- **Critical:** With few prerequisites and safe defaults, an attacker gains broad execution
38+
or credential access.
39+
- **High:** A demonstrated boundary crossing causes substantial confidentiality or integrity harm,
40+
such as executing attacker code despite an effective untrusted-workspace restriction.
41+
- **Medium:** A limited unauthorized read or write, or bypass of an execution restriction with
42+
limited effect.
43+
- **Low:** A narrow disclosure or safety gap with limited practical impact, or reliable resource
44+
exhaustion affecting the editor or the developer's machine.
45+
- **Informational:** A genuine security concern with negligible current impact.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Ruff and ty playground threat model
2+
3+
## Overview
4+
5+
This model covers browser analysis, Python execution, file exports, and the public sharing API. The
6+
[CLI threat model](cli-threat-model.md) defines the general criteria for security findings.
7+
8+
Builds and publication have a separate
9+
[repository threat model](repository-threat-model.md).
10+
11+
## Trust boundaries and assumptions
12+
13+
- **Attacker-controlled:** shared URLs and workspace contents, including source code, configuration,
14+
filenames, and which file is selected.
15+
- **Trusted environment:** the browser, operating system, local caches, HTTPS, application
16+
dependencies including Pyodide, and configured Cloudflare service and KV namespace.
17+
- **Python execution:** Choosing Run authorizes the workspace's Python code to use the page's
18+
JavaScript and browser APIs through Pyodide.
19+
- **API callers:** The sharing API accepts anonymous uploads, creates a random identifier, and
20+
returns stored text to anyone who has that identifier.
21+
22+
## Security invariants
23+
24+
### Browser applications
25+
26+
- **Code Execution:** Analysis must not execute user-supplied code. Running Python requires choosing
27+
Run.
28+
- **Rendering:** Diagnostics, documentation, filenames, errors, and program output must not allow
29+
attacker-controlled text to run code or invoke commands in the playground.
30+
- **Paths and exports:** Loading or editing workspace files must not overwrite unrelated application
31+
state. Extracting an exported ZIP must not write outside the chosen directory.
32+
- **Source privacy:** Analysis must not upload source. Share and the Markdown copy actions upload the
33+
selected workspace. Restoring a shared workspace must not disclose other playground data.
34+
- **Availability:** An isolated analysis failure or slow analysis is a correctness or performance
35+
bug. A security issue requires repeatable, disproportionate resource use that materially
36+
disrupts the browser or user's machine beyond the playground tab.
37+
38+
### Sharing API
39+
40+
- **Stored values:** Requests must not overwrite unrelated entries, reveal their identifiers or
41+
contents, expose deployment credentials, or execute code in the worker.
42+
- **Availability:** Anonymous requests must not cause disproportionate resource use that denies
43+
service to other users or exhausts shared resources.
44+
45+
## Severity calibration
46+
47+
- **Critical:** Service or host compromise, or loss of credentials with comparable authority,
48+
with few prerequisites.
49+
- **High:** Substantial confidentiality or integrity harm, such as executing attacker code on
50+
opening a shared link and stealing other playground data.
51+
- **Medium:** Limited disclosure or modification, or reliable resource exhaustion affecting the
52+
shared service.
53+
- **Low:** A narrow safety gap with limited practical impact, or reliable resource exhaustion
54+
affecting a user's browser or machine beyond the playground tab.
55+
- **Informational:** A genuine security concern with negligible current impact.

‎agents/references/threat-models.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Security threat models
2+
3+
Use each model that covers the behavior under review.
4+
5+
- [Ruff and ty CLI](cli-threat-model.md): command-line tools, native libraries, analysis,
6+
configuration, file operations, subprocesses, and diagnostics.
7+
- [Language servers](language-server-threat-model.md): editor messages, workspace trust, document
8+
access, edits, and logs.
9+
- [Playgrounds](playground-threat-model.md): browser applications, WASM, Python execution, and the
10+
HTTP sharing API.
11+
- [GitHub repository](repository-threat-model.md):
12+
CI, releases, publishing, ecosystem jobs, and maintainer automation.
13+
14+
Development tools that build or run third-party code follow the repository model.

0 commit comments

Comments
 (0)