Skip to content

Commit aed579c

Browse files
committed
docs: address reviewer feedback on migration guide and resources doc
migration.md: added note that static URIs with Context-only handlers now error at decoration time. The pattern was previously silently unreachable (the resource registered but could never be read); now it surfaces early. Duplicate-variable-names rejection was already covered in the malformed-templates paragraph. resources.md: clarified that the .. check is depth-based (rejects values that would escape the starting directory, so a/../b passes). Changed template reference table intro from 'what the SDK supports' to 'the most common patterns' since the table intentionally omits the rarely-used fragment and path-param operators. test_uri_template.py: corrected the stray-} test comment. RFC 6570 section 2.1 strictly excludes } from literals; we accept it for TypeScript SDK parity, not because the RFC is lenient.
1 parent 2f7fd61 commit aed579c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

docs/migration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,14 @@ duplicate variable names, and unsupported syntax now raise
585585
`InvalidUriTemplate` when the decorator runs, rather than silently
586586
misbehaving at match time.
587587

588+
**Static URIs with Context-only handlers now error.** A non-template
589+
URI paired with a handler that takes only a `Context` parameter
590+
previously registered but was silently unreachable (the resource
591+
could never be read). This now raises `ValueError` at decoration time.
592+
Context injection for static resources is planned; until then, use a
593+
template with at least one variable or access context through other
594+
means.
595+
588596
See [Resources](server/resources.md) for the full template syntax,
589597
security configuration, and filesystem safety utilities.
590598

docs/server/resources.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def walk_tree(path: list[str]) -> dict:
118118
### Template reference
119119

120120
The template syntax follows [RFC 6570](https://datatracker.ietf.org/doc/html/rfc6570).
121-
Here's what the SDK supports:
121+
The most common patterns:
122122

123123
| Pattern | Example input | You get |
124124
|--------------|-----------------------|-------------------------|
@@ -141,7 +141,7 @@ or database operations, a hostile client can try path traversal
141141

142142
Before your handler runs, the SDK rejects any parameter that:
143143

144-
- contains `..` as a path component
144+
- would escape its starting directory via `..` components
145145
- looks like an absolute path (`/etc/passwd`, `C:\Windows`)
146146

147147
The `..` check is component-based, not a substring scan. Values like
@@ -211,7 +211,7 @@ The configurable checks:
211211

212212
| Setting | Default | What it does |
213213
|-------------------------|---------|-------------------------------------|
214-
| `reject_path_traversal` | `True` | Rejects `..` as a path component |
214+
| `reject_path_traversal` | `True` | Rejects `..` sequences that escape the starting directory |
215215
| `reject_absolute_paths` | `True` | Rejects `/foo`, `C:\foo`, UNC paths |
216216
| `exempt_params` | empty | Parameter names to skip checks for |
217217

tests/shared/test_uri_template.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ def test_parse_rejects_unclosed_brace(template: str, position: int):
263263
["}}", "}", "a}b", "{a}}{b}"],
264264
)
265265
def test_parse_treats_stray_close_brace_as_literal(template: str):
266-
# RFC 6570 is lenient about } outside expressions; most implementations
267-
# (including the TypeScript SDK) treat it as a literal rather than erroring.
266+
# RFC 6570 §2.1 strictly excludes } from literals, but we accept it
267+
# for TypeScript SDK parity. A stray } almost always indicates a
268+
# typo; rejecting would be more helpful but would also break
269+
# cross-SDK behavior.
268270
tmpl = UriTemplate.parse(template)
269271
assert str(tmpl) == template
270272

0 commit comments

Comments
 (0)