agentleFS
MicrosoftKnown publishermicrosoft/data-formulator/.cursor/rules/path-safety.mdc

data-formulator / rules

Cursor rule18k starsChanged 7 months agoMITView on GitHub

路径安全编码规范 — 编辑路由/Agent/Loader/Workspace/知识库代码时自动提醒

Trending

Steady talk.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 1 mentionMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 2 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the microsoft/data-formulator repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about microsoft/data-formulator

The biggest 5 of 31 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 31

Talked about on Bluesky, GitHub and Hacker News (31 times).

On Bluesky · 22

17 more on Bluesky

On GitHub · 7

2 more on GitHub

The file

Files
path-safety.mdc
---
description: 路径安全编码规范 — 编辑路由/Agent/Loader/Workspace/知识库代码时自动提醒
globs: py-src/data_formulator/{routes,agents,data_loader,datalake,security,knowledge}/**/*.py
alwaysApply: false
---

# 路径安全编码规范

编辑此目录下的文件时,请遵守以下安全规则(详见 `docs/dev-guides/8-path-safety.md` 和 `.cursor/skills/path-safety/SKILL.md`):

## ConfinedDir 是唯一的路径约束原语

所有接受用户可控路径的代码,**必须**通过 `ConfinedDir` 实例访问文件系统。

```python
from data_formulator.security.path_safety import ConfinedDir

jail = ConfinedDir(root_dir, mkdir=False)
try:
    target = jail.resolve(user_input)
except ValueError:
    return {"error": "Access denied"}
```

## 禁止的模式

```python
# ❌ BAD — 裸路径拼接
target = Path(root) / user_input

# ❌ BAD — 手写 resolve + relative_to(已弃用,必须用 ConfinedDir)
target = (root / user_input).resolve()
try:
    target.relative_to(root)
except ValueError: ...

# ❌ BAD — 手写 is_relative_to(已弃用,必须用 ConfinedDir)
resolved = (root / user_input).resolve()
if not resolved.is_relative_to(root.resolve()): ...

# ❌ BAD — 路径比较用 str.startswith
if str(target).startswith(str(root)): ...
```

## 正确的模式

```python
# ✅ GOOD — Agent 工具
workspace_jail = self.workspace.confined_root
scratch_jail = self.workspace.confined_scratch
target = workspace_jail.resolve(rel_path)

# ✅ GOOD — 文件下载 route
scratch_jail = workspace.confined_scratch
target = scratch_jail.resolve(filename)
return send_file(target)

# ✅ GOOD — 文件上传(两层防御)
safe_name = secure_filename(raw_filename)
target = scratch_jail.resolve(safe_name)

# ✅ GOOD — Workspace data 文件
path = workspace.get_file_path(filename)  # 内部使用 ConfinedDir
```

## 部署守卫

- 新增读取宿主文件系统的 Loader 必须在 `_enforce_deployment_restrictions()` 注册多用户禁用
- 多用户模式(`WORKSPACE_BACKEND != "local"`)必须启用沙箱

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.