Naming
Prefer domain-based names; avoid type-based names.
- Good:
config_dir,uploads_root,archive_src,user_vroot,system_root. - Avoid:
boundary,jail,source_prefixes, or one-letter variables. - Keep names consistent with the directory they represent and convey intent in code review.
Quick Reference Table
| Context | ✅ Good Names | ❌ Avoid |
|---|---|---|
| Untrusted input | requested_file, user_input, uploaded_data, attack_input | filename, path, name, file |
| Boundaries | uploads_root, config_dir, archive_src, static_assets | boundary, jail, root, b |
| Virtual roots | user_vroot, tenant_sandbox, project_root | vroot, vr, sandbox |
| Markers | UserUploads, MediaLibrary, BrandAssets | UserUploadsMarker, Root, Type |
| Paths | avatar_file, config_path, entry_path | p, f, temp, x |
Why This Matters
Variable names are documentation. When reviewing security-critical code, names should immediately communicate:
- What is being validated —
requested_filescreams “this came from outside” - What boundary protects it —
uploads_rootexplains the restriction - What marker type encodes —
UserUploadstells you what’s stored
Anti-pattern example:
#![allow(unused)]
fn main() {
// ❌ What is `filename`? Where did it come from? Is it safe?
let path = boundary.strict_join(filename)?;
}
Improved:
#![allow(unused)]
fn main() {
// ✅ Obvious: user-provided input being validated against upload boundary
let avatar_path = user_uploads_root.strict_join(requested_avatar_filename)?;
}
Marker Types
- Name markers after the storage domain (
struct PublicAssets;,struct BrandEditorWorkspace;). Reviewers should understand the filesystem contents from the type alone. - Skip suffixes like
Marker,Type, orRoot; they repeat what Rust already communicates.struct MediaLibrary;is clearer thanstruct MediaLibraryMarker;. - Tuples that pair storage with authorization should keep the resource first and the capability second:
StrictPath<(BrandDirectorArchive, FullControlCapability)>. - Focus on what’s stored, not who uses it. A marker like
BrandAssetstells you the directory contains brand materials, whileEditorFilesonly tells you someone called “Editor” uses it. The marker describes the filesystem contents and access policy, not the caller’s identity.