- Bump _AST_CACHE_SCHEMA 23 -> 24: #4705 (ObjC NS_CLOSED_ENUM) and #4677 (SQL CREATE TABLE ERROR-node recovery) both change extraction output, and neither PR included the bump, so a warm ObjC/SQL cache would serve stale results. - #4677: display the recovered table label through _clean_ident (consistent with the routine/trigger recoveries) while keeping the id keyed off the raw name so FK edges still resolve to it. - Add regression tests the #4708/#4709/#4710 security PRs shipped without (multicast/unspecified SSRF block, Obsidian tag injection, Google shortcut frontmatter escaping). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e69cc9d89e
commit
3b213769f0
3 files changed
+42
-2
No files matched your search
+1
-1
@@ -37,7 +37,7 @@ except Exception:
|
||||
_EXTRACTOR_VERSION = "unknown"
|
||||
|
||||
# Bump when AST cache-key semantics change independently of the package version.
|
||||
_AST_CACHE_SCHEMA = 23 # `.yaml`/`.yml` files are structurally extracted (keys as nodes, config-vs-data gated) and reclassified from document to code (#2214), so cached YAML re-extracts; prior (22): SQL labels drop T-SQL brackets and routine bodies emit `reads_from`/`writes_to` (#4635), and a `GO` batch separator ends a statement (#4651), so cached `.sql` extractions re-run; prior (21): a CommonJS `const X = require('./m')` binding no longer mints a module-scope node that shadows the class the required file exports, so `new X()` resolves to the required declaration (#4621); prior (20): Obsidian `[[wikilink]]` targets that start with the scan root's own folder names now resolve to the real page (#4559), so cached markdown extractions re-run; prior (19): Dart `typedef` declarations are extracted as aliases (not variables of type `typedef`); C++ Metal/CUDA GPU qualifiers no longer mint sourceless god nodes (#4550); a `.h` header containing `extern "C"` routes to the C++ extractor; prior (18): Kotlin `typealias` (#4553), C# `delegate` (#4552), and Swift `macro` declarations (#4551) are now extracted so references stop minting sourceless stubs; Rust `use` rooted at a `mod` declared in the same scope carries `_rust_use_name` (#4564); prior (17): Python pytest-fixture markers (`_py_fixture`/`_python_fixture_param`, #4332) and module-level class-id collision salting (#2810); TS `this.field` typed from any method incl. static (#4473); Solidity callables carry `metadata.arity` + inherited-call/`super`/modifier raw calls (#4379); Go type-decl and Rust file-item case-distinct node ids (#4444); prior (16): Rust `use` edges carry the imported name as written (`_rust_use_name`, #4439); (15): Go generic receiver types normalized (`Box[T]` -> `Box`) so methods attach to the type node; prior (14): C# receiver resolution for nameless/`new X()`/`foreach` receivers (defer + receiver-chain markers) and `_`/case-distinct node ids (underscore-salted); prior (13): Kotlin/Scala/C++/Swift generic & template type params no longer mint sourceless stubs; Objective-C NS_ENUM/NS_OPTIONS extraction and `_callable`/`_callable_class` markers; Go and PHP receiver-typed member calls park cross-repo (`go_type_table`/`php_type_table`, receiver fields); prior (12): Java inherited-supertype (`receiver_unbound`) and chained/new/cast receiver typing (`java_receiver_chain`, `_java_ret`); C/C++ quoted cross-directory include provenance (`include_kind`); JS external imports anchored to the package, not the path leaf; prior (11): Python property-accessor decorators / `Self`, Swift `Self`, Go generic type params, Python forward type-hint file node, PowerShell dot-source, C# verbatim-interpolated string recovery; (10): C# partial types carry `type_path`; (9): Python property-read raw calls and `_py_property` nodes; (8): Rust `use`-group per-binding edges; (7): Python opaque-base/super(args) markers + nested-class enclosing ids.
|
||||
_AST_CACHE_SCHEMA = 24 # Objective-C `NS_CLOSED_ENUM` declarations are extracted as enums like `NS_ENUM` (#4705), and a `CREATE TABLE` whose column default the SQL grammar rejects (MySQL `DEFAULT current_timestamp()`) is recovered from its ERROR node (#4613), so cached ObjC and SQL extractions re-run; prior (23): `.yaml`/`.yml` files are structurally extracted (keys as nodes, config-vs-data gated) and reclassified from document to code (#2214), so cached YAML re-extracts; prior (22): SQL labels drop T-SQL brackets and routine bodies emit `reads_from`/`writes_to` (#4635), and a `GO` batch separator ends a statement (#4651), so cached `.sql` extractions re-run; prior (21): a CommonJS `const X = require('./m')` binding no longer mints a module-scope node that shadows the class the required file exports, so `new X()` resolves to the required declaration (#4621); prior (20): Obsidian `[[wikilink]]` targets that start with the scan root's own folder names now resolve to the real page (#4559), so cached markdown extractions re-run; prior (19): Dart `typedef` declarations are extracted as aliases (not variables of type `typedef`); C++ Metal/CUDA GPU qualifiers no longer mint sourceless god nodes (#4550); a `.h` header containing `extern "C"` routes to the C++ extractor; prior (18): Kotlin `typealias` (#4553), C# `delegate` (#4552), and Swift `macro` declarations (#4551) are now extracted so references stop minting sourceless stubs; Rust `use` rooted at a `mod` declared in the same scope carries `_rust_use_name` (#4564); prior (17): Python pytest-fixture markers (`_py_fixture`/`_python_fixture_param`, #4332) and module-level class-id collision salting (#2810); TS `this.field` typed from any method incl. static (#4473); Solidity callables carry `metadata.arity` + inherited-call/`super`/modifier raw calls (#4379); Go type-decl and Rust file-item case-distinct node ids (#4444); prior (16): Rust `use` edges carry the imported name as written (`_rust_use_name`, #4439); (15): Go generic receiver types normalized (`Box[T]` -> `Box`) so methods attach to the type node; prior (14): C# receiver resolution for nameless/`new X()`/`foreach` receivers (defer + receiver-chain markers) and `_`/case-distinct node ids (underscore-salted); prior (13): Kotlin/Scala/C++/Swift generic & template type params no longer mint sourceless stubs; Objective-C NS_ENUM/NS_OPTIONS extraction and `_callable`/`_callable_class` markers; Go and PHP receiver-typed member calls park cross-repo (`go_type_table`/`php_type_table`, receiver fields); prior (12): Java inherited-supertype (`receiver_unbound`) and chained/new/cast receiver typing (`java_receiver_chain`, `_java_ret`); C/C++ quoted cross-directory include provenance (`include_kind`); JS external imports anchored to the package, not the path leaf; prior (11): Python property-accessor decorators / `Self`, Swift `Self`, Go generic type params, Python forward type-hint file node, PowerShell dot-source, C# verbatim-interpolated string recovery; (10): C# partial types carry `type_path`; (9): Python property-read raw calls and `_py_property` nodes; (8): Rust `use`-group per-binding edges; (7): Python opaque-base/super(args) markers + nested-class enclosing ids.
|
||||
|
||||
|
||||
# Per-process memo: distributions() scans site-packages metadata, which is
|
||||
|
||||
@@ -986,6 +986,8 @@ def extract_sql(path: Path, content: str | bytes | None = None) -> dict:
|
||||
continue
|
||||
tbl_name = m.group(1)
|
||||
tbl_line = src_text[: m.start()].count("\n") + 1
|
||||
_add_node(_make_id(stem, tbl_name), tbl_name, tbl_line)
|
||||
# Clean the label (brackets/quotes) for display but key the id off the
|
||||
# raw name so it matches the pre-pass registration the FK edges resolved to.
|
||||
_add_node(_make_id(stem, tbl_name), _clean_ident(tbl_name), tbl_line)
|
||||
|
||||
return {"nodes": nodes, "edges": edges}
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Regression tests for the #4708/#4709/#4710 security hardening.
|
||||
|
||||
These fixes shipped without tests; pin them so the SSRF blocklist gap and the
|
||||
two YAML-frontmatter injection gaps cannot silently reopen.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import ipaddress
|
||||
|
||||
from graphify.export import _obsidian_tag
|
||||
from graphify.google_workspace import _safe_yaml_str
|
||||
from graphify.security import _ip_is_blocked
|
||||
|
||||
|
||||
def test_ip_is_blocked_rejects_multicast_and_unspecified():
|
||||
"""#4708: a host resolving to a multicast or unspecified address must be
|
||||
blocked by the SSRF guard; ordinary public IPs still pass."""
|
||||
for bad in ("224.0.0.1", "239.1.1.1", "ff02::1", "0.0.0.0", "::"):
|
||||
assert _ip_is_blocked(ipaddress.ip_address(bad)), f"{bad} should be blocked"
|
||||
for good in ("8.8.8.8", "1.1.1.1", "2606:4700:4700::1111"):
|
||||
assert not _ip_is_blocked(ipaddress.ip_address(good)), f"{good} should pass"
|
||||
|
||||
|
||||
def test_obsidian_tag_strips_yaml_breaking_chars():
|
||||
"""#4709: a tag value carrying a newline cannot break out of the frontmatter
|
||||
`tags:` list into a column-0 sibling key."""
|
||||
tag = _obsidian_tag("document\ninjected_key: pwned")
|
||||
assert "\n" not in tag and ":" not in tag
|
||||
assert tag == "documentinjected_key_pwned"
|
||||
|
||||
|
||||
def test_safe_yaml_str_escapes_line_breaks_and_controls():
|
||||
"""#4710: a hostile shortcut file id/url carrying raw line breaks (including
|
||||
U+2028 and U+0085) or a tab is escaped so it cannot inject sibling keys."""
|
||||
out = _safe_yaml_str("abc
injected: pwned\u0085evil: x\ttabbed\nnl\rcr")
|
||||
for raw in ("
", "
", "\u0085", "\t", "\n", "\r"):
|
||||
assert raw not in out, f"{raw!r} must be escaped, not left raw"
|
||||
assert "injected" in out # content preserved, only the breaks are escaped
|
||||
Reference in new issue
Block a user