MCPcopy Index your code
hub / github.com/brownsys/paralegal

github.com/brownsys/paralegal @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
2,149 symbols 6,750 edges 159 files 554 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Paralegal: A Privacy and Security Bug Finder for Rust Applications.

Paralegal is a static analyzer for Rust code that enforces privacy and security policies on programs.

For example, developers have used Paralegal to find problems such as: * Failing to delete user data upon request * Missing authorization checks before privileged actions * Forgetting to encrypt sensitive data before storage

Paralegal's user guide and documentation is available at https://brownsys.github.io/paralegal, which includes a step-by-step walkthrough of an example application and policy.

See also our paper from OSDI 2025.

Example

Take the following policy for a social media application, which checks that the user is not banned or deleted before executing an action on their behalf (e.g., posting, commenting):

Scope:
Everywhere

Policy:
1. For each "action" marked write:
  A. There is a "deleted user check" marked delete_check where:
    a. "deleted user check" affects whether "action" happens
  and
  B. There is a "banned user check" marked ban_check where:
    a. "banned user check" affects whether "action" happens

Developers connect policies to application code by defining markers, which denote high-level concepts such as write, encrypts or user_data. Developers apply markers to types, function arguments, or function return values using lightweight annotations, e.g.:

#[paralegal::marker(ban_check, return)]
fn is_user_banned(user: &User) -> bool { ... }

impl Database {
  #[paralegal::marker(write, argument = [0])]
  fn insert_post(&mut self, user: &User, post: String) { ... }
}

Paralegal directly integrates with cargo and rustc, so running it is as easy as building your project (cargo paralegal-flow).

Performance

Paralegal is a fast cargo and rustc plugin that developers can run frequently (in CI for example) to find potential bugs as they develop their application.

Here is a performance breakdown plot of Paralegal running end-to-end on realistic web applications.

Installation and Usage

Install the latest release from source with:

curl -fsSL https://raw.githubusercontent.com/brownsys/paralegal/main/install.sh | sh

This builds Paralegal against the nightly toolchain pinned in rust-toolchain.toml (provisioned automatically by rustup), so the first install compiles the analyzer and may take a few minutes. See install.sh --help for options (specific version, custom install dir, building from a local checkout).

For a full walkthrough of installation and writing your first policy, see the step-by-step guide in our online documentation.

Extension points exported contracts — how you extend this code

IntoDefId (Interface)
Brother to [`IntoLocalDefId`], converts the id type to a [`DefId`] using [`TyCtxt`] [6 implementers]
crates/plugin/src/utils/mod.rs
HasDiagnosticsBase (Interface)
Low level machinery for diagnostics. As a user you should only be using methods from [`Diagnostics`]. It may however be [7 …
crates/policy/src/diagnostics.rs
IntoIterGlobalNodes (Interface)
This lets us be agnostic whether a primitive (such as `flows_to`) is called with a [`GlobalNode`] or `&NodeCluster`. No [3 …
crates/pdg/src/lib.rs
TyExt (Interface)
Extension trait for [`Ty`]. [1 implementers]
crates/rustc-utils/src/hir/ty.rs
VisitMut (Interface)
(no doc) [1 implementers]
crates/compiler/src/common/vis.rs
FileSystemStorable (Interface)
(no doc)
crates/utils/src/lib.rs
IntoLocalDefId (Interface)
A trait for types that can be converted into a [`mir::LocalDefId`] via [`TyCtxt`]. [4 implementers]
crates/plugin/src/utils/mod.rs
Context (Interface)
Actions that behave differently depending on the context [2 implementers]
crates/policy/src/context.rs

Core symbols most depended-on inside this repo

iter
called by 286
crates/pdg/src/lib.rs
unwrap
called by 206
crates/plugin/src/utils/mod.rs
push
called by 104
crates/pdg/src/pdg.rs
to_string
called by 76
crates/rustc-utils/src/mir/location_or_arg.rs
contains
called by 65
crates/pdg/src/lib.rs
join
called by 58
crates/plugin/src/analysis/pdg/local/mod.rs
into_iter
called by 51
crates/pdg/src/lib.rs
unwrap
called by 49
crates/plugin/src/analysis/pdg/mod.rs

Shape

Method 1,028
Function 772
Class 235
Enum 77
Interface 37

Languages

Rust100%

Modules by API surface

crates/plugin/src/test_utils.rs108 symbols
crates/pdg/src/lib.rs89 symbols
crates/plugin/src/utils/mod.rs81 symbols
crates/policy/src/context.rs78 symbols
crates/policy/src/diagnostics.rs76 symbols
crates/policy/tests/raw-code/contile.rs51 symbols
crates/plugin/src/ann/db/mod.rs51 symbols
crates/compiler/src/common/vis.rs42 symbols
crates/pdg/src/pdg.rs41 symbols
crates/plugin/src/source_access/encoder.rs39 symbols
crates/rustc-utils/src/mir/place.rs38 symbols
crates/plugin/src/args.rs38 symbols

For agents

$ claude mcp add paralegal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page