@pyric/cli 0.1.0-alpha.20 → 0.1.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -89
- package/dist/assurance/.generated/conformance-verdicts.d.ts +238 -1
- package/dist/assurance/.generated/conformance-verdicts.d.ts.map +1 -1
- package/dist/assurance/.generated/conformance-verdicts.js +238 -1
- package/dist/assurance/.generated/conformance-verdicts.js.map +1 -1
- package/dist/bridge/client/dispatch.d.ts +25 -19
- package/dist/bridge/client/dispatch.d.ts.map +1 -1
- package/dist/bridge/client/dispatch.js +41 -48
- package/dist/bridge/client/dispatch.js.map +1 -1
- package/dist/bridge/client/tool-family-factories.d.ts +26 -0
- package/dist/bridge/client/tool-family-factories.d.ts.map +1 -0
- package/dist/bridge/client/tool-family-factories.js +10 -0
- package/dist/bridge/client/tool-family-factories.js.map +1 -0
- package/dist/bridge/server/mcp-contract.d.ts +7 -6
- package/dist/bridge/server/mcp-contract.d.ts.map +1 -1
- package/dist/bridge/server/mcp-contract.js +9 -48
- package/dist/bridge/server/mcp-contract.js.map +1 -1
- package/dist/bridge/server/peer.d.ts +11 -1
- package/dist/bridge/server/peer.d.ts.map +1 -1
- package/dist/bridge/server/peer.js +22 -1
- package/dist/bridge/server/peer.js.map +1 -1
- package/dist/bridge/server/tool-family-factories.d.ts +30 -0
- package/dist/bridge/server/tool-family-factories.d.ts.map +1 -0
- package/dist/bridge/server/tool-family-factories.js +22 -0
- package/dist/bridge/server/tool-family-factories.js.map +1 -0
- package/dist/bridge/server/tool-metadata.d.ts +17 -18
- package/dist/bridge/server/tool-metadata.d.ts.map +1 -1
- package/dist/bridge/server/tool-metadata.js +24 -59
- package/dist/bridge/server/tool-metadata.js.map +1 -1
- package/dist/bridge/tool-families.d.ts +48 -0
- package/dist/bridge/tool-families.d.ts.map +1 -0
- package/dist/bridge/tool-families.generated.d.ts +32 -0
- package/dist/bridge/tool-families.generated.d.ts.map +1 -0
- package/dist/bridge/tool-families.generated.js +15 -0
- package/dist/bridge/tool-families.generated.js.map +1 -0
- package/dist/bridge/tool-families.js +51 -0
- package/dist/bridge/tool-families.js.map +1 -0
- package/dist/bridge/tool-family-records/conformance.d.ts +7 -0
- package/dist/bridge/tool-family-records/conformance.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/conformance.js +6 -0
- package/dist/bridge/tool-family-records/conformance.js.map +1 -0
- package/dist/bridge/tool-family-records/firestore-data.d.ts +7 -0
- package/dist/bridge/tool-family-records/firestore-data.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/firestore-data.js +15 -0
- package/dist/bridge/tool-family-records/firestore-data.js.map +1 -0
- package/dist/bridge/tool-family-records/firestore-inspect.d.ts +7 -0
- package/dist/bridge/tool-family-records/firestore-inspect.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/firestore-inspect.js +6 -0
- package/dist/bridge/tool-family-records/firestore-inspect.js.map +1 -0
- package/dist/bridge/tool-family-records/firestore-rules.d.ts +7 -0
- package/dist/bridge/tool-family-records/firestore-rules.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/firestore-rules.js +15 -0
- package/dist/bridge/tool-family-records/firestore-rules.js.map +1 -0
- package/dist/bridge/tool-family-records/firestore-simulator.d.ts +7 -0
- package/dist/bridge/tool-family-records/firestore-simulator.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/firestore-simulator.js +16 -0
- package/dist/bridge/tool-family-records/firestore-simulator.js.map +1 -0
- package/dist/bridge/tool-family-records/rtdb-inspection.d.ts +7 -0
- package/dist/bridge/tool-family-records/rtdb-inspection.d.ts.map +1 -0
- package/dist/bridge/tool-family-records/rtdb-inspection.js +6 -0
- package/dist/bridge/tool-family-records/rtdb-inspection.js.map +1 -0
- package/dist/bundler/externals.d.ts +37 -0
- package/dist/bundler/externals.d.ts.map +1 -0
- package/dist/bundler/externals.js +52 -0
- package/dist/bundler/externals.js.map +1 -0
- package/dist/bundler/index.d.ts +17 -0
- package/dist/bundler/index.d.ts.map +1 -0
- package/dist/bundler/index.js +17 -0
- package/dist/bundler/index.js.map +1 -0
- package/dist/cli/inlined-sdk-scanner.d.ts +6 -0
- package/dist/cli/inlined-sdk-scanner.d.ts.map +1 -0
- package/dist/cli/inlined-sdk-scanner.js +82 -0
- package/dist/cli/inlined-sdk-scanner.js.map +1 -0
- package/dist/cli/sandbox-interlock.d.ts +97 -0
- package/dist/cli/sandbox-interlock.d.ts.map +1 -0
- package/dist/cli/sandbox-interlock.js +112 -0
- package/dist/cli/sandbox-interlock.js.map +1 -0
- package/dist/cli/sandbox-runner.d.ts +20 -12
- package/dist/cli/sandbox-runner.d.ts.map +1 -1
- package/dist/cli/sandbox-runner.js +24 -21
- package/dist/cli/sandbox-runner.js.map +1 -1
- package/dist/cli/serve.d.ts +6 -10
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +57 -77
- package/dist/cli/serve.js.map +1 -1
- package/dist/cli/unsupported-runtime.d.ts +27 -0
- package/dist/cli/unsupported-runtime.d.ts.map +1 -0
- package/dist/cli/unsupported-runtime.js +63 -0
- package/dist/cli/unsupported-runtime.js.map +1 -0
- package/dist/conformance/.generated/can-i-use-browser.d.ts +1 -1
- package/dist/conformance/.generated/can-i-use-browser.d.ts.map +1 -1
- package/dist/conformance/.generated/can-i-use-browser.js +1 -1
- package/dist/conformance/.generated/can-i-use-browser.js.map +1 -1
- package/dist/conformance/.generated/can-i-use.d.ts +1 -1
- package/dist/conformance/.generated/can-i-use.d.ts.map +1 -1
- package/dist/conformance/.generated/can-i-use.js +1 -1
- package/dist/conformance/.generated/can-i-use.js.map +1 -1
- package/dist/conformance/.generated/conformance-docs.d.ts.map +1 -1
- package/dist/conformance/.generated/conformance-docs.js +1 -1
- package/dist/conformance/.generated/conformance-docs.js.map +1 -1
- package/dist/functions-rtdb/child.d.ts +37 -0
- package/dist/functions-rtdb/child.d.ts.map +1 -1
- package/dist/functions-rtdb/child.js +90 -21
- package/dist/functions-rtdb/child.js.map +1 -1
- package/dist/functions-rtdb/development-runtime.d.ts +3 -0
- package/dist/functions-rtdb/development-runtime.d.ts.map +1 -1
- package/dist/functions-rtdb/development-runtime.js +1 -0
- package/dist/functions-rtdb/development-runtime.js.map +1 -1
- package/dist/google-endpoints.d.ts +67 -0
- package/dist/google-endpoints.d.ts.map +1 -0
- package/dist/google-endpoints.js +119 -0
- package/dist/google-endpoints.js.map +1 -0
- package/dist/next/runtime-env.d.ts.map +1 -1
- package/dist/next/runtime-env.js +5 -0
- package/dist/next/runtime-env.js.map +1 -1
- package/dist/next/with-pyric.d.ts +1 -1
- package/dist/next/with-pyric.js +1 -1
- package/dist/register/beacon.d.ts +69 -0
- package/dist/register/beacon.d.ts.map +1 -0
- package/dist/register/beacon.js +199 -0
- package/dist/register/beacon.js.map +1 -0
- package/dist/register/index.d.ts.map +1 -1
- package/dist/register/index.js +65 -6
- package/dist/register/index.js.map +1 -1
- package/dist/register/net-guard.d.ts +110 -0
- package/dist/register/net-guard.d.ts.map +1 -0
- package/dist/register/net-guard.js +462 -0
- package/dist/register/net-guard.js.map +1 -0
- package/dist/serve/ai-diagnostics-relay.d.ts +63 -0
- package/dist/serve/ai-diagnostics-relay.d.ts.map +1 -0
- package/dist/serve/ai-diagnostics-relay.js +125 -0
- package/dist/serve/ai-diagnostics-relay.js.map +1 -0
- package/dist/serve/ai-proxy.d.ts +92 -0
- package/dist/serve/ai-proxy.d.ts.map +1 -0
- package/dist/serve/ai-proxy.js +269 -0
- package/dist/serve/ai-proxy.js.map +1 -0
- package/dist/serve/ai-status.d.ts +44 -0
- package/dist/serve/ai-status.d.ts.map +1 -0
- package/dist/serve/ai-status.js +77 -0
- package/dist/serve/ai-status.js.map +1 -0
- package/dist/serve/ai-terminal-blocks.d.ts +97 -0
- package/dist/serve/ai-terminal-blocks.d.ts.map +1 -0
- package/dist/serve/ai-terminal-blocks.js +128 -0
- package/dist/serve/ai-terminal-blocks.js.map +1 -0
- package/dist/serve/ai-terminal-text.d.ts +36 -0
- package/dist/serve/ai-terminal-text.d.ts.map +1 -0
- package/dist/serve/ai-terminal-text.js +48 -0
- package/dist/serve/ai-terminal-text.js.map +1 -0
- package/dist/serve/beacon-route.d.ts +53 -0
- package/dist/serve/beacon-route.d.ts.map +1 -0
- package/dist/serve/beacon-route.js +101 -0
- package/dist/serve/beacon-route.js.map +1 -0
- package/dist/serve/entries/active-auth-registry.d.ts +16 -0
- package/dist/serve/entries/active-auth-registry.d.ts.map +1 -0
- package/dist/serve/entries/active-auth-registry.js +48 -0
- package/dist/serve/entries/active-auth-registry.js.map +1 -0
- package/dist/serve/entries/active-auth.d.ts +18 -0
- package/dist/serve/entries/active-auth.d.ts.map +1 -0
- package/dist/serve/entries/active-auth.js +84 -0
- package/dist/serve/entries/active-auth.js.map +1 -0
- package/dist/serve/entries/auth-helper-core.d.ts +1 -0
- package/dist/serve/entries/auth-helper-core.d.ts.map +1 -1
- package/dist/serve/entries/auth-helper-core.js +4 -0
- package/dist/serve/entries/auth-helper-core.js.map +1 -1
- package/dist/serve/entries/auth-helper-dom.d.ts.map +1 -1
- package/dist/serve/entries/auth-helper-dom.js +28 -2
- package/dist/serve/entries/auth-helper-dom.js.map +1 -1
- package/dist/serve/entries/auth.d.ts.map +1 -1
- package/dist/serve/entries/auth.js +8 -0
- package/dist/serve/entries/auth.js.map +1 -1
- package/dist/serve/entries/bridge-url.d.ts +1 -1
- package/dist/serve/entries/bridge-url.js +1 -1
- package/dist/serve/entries/init.d.ts.map +1 -1
- package/dist/serve/entries/init.js +70 -4
- package/dist/serve/entries/init.js.map +1 -1
- package/dist/serve/entries/runtime.d.ts.map +1 -1
- package/dist/serve/entries/runtime.js +9 -0
- package/dist/serve/entries/runtime.js.map +1 -1
- package/dist/serve/namespace.d.ts +14 -5
- package/dist/serve/namespace.d.ts.map +1 -1
- package/dist/serve/namespace.js +57 -124
- package/dist/serve/namespace.js.map +1 -1
- package/dist/serve/runtime/chip-config.d.ts.map +1 -1
- package/dist/serve/runtime/chip-config.js +16 -2
- package/dist/serve/runtime/chip-config.js.map +1 -1
- package/dist/serve/runtime/chip-dialog.d.ts +18 -0
- package/dist/serve/runtime/chip-dialog.d.ts.map +1 -0
- package/dist/serve/runtime/chip-dialog.js +315 -0
- package/dist/serve/runtime/chip-dialog.js.map +1 -0
- package/dist/serve/runtime/chip-install.d.ts +2 -0
- package/dist/serve/runtime/chip-install.d.ts.map +1 -1
- package/dist/serve/runtime/chip-install.js +9 -4
- package/dist/serve/runtime/chip-install.js.map +1 -1
- package/dist/serve/runtime/chip-user-search.d.ts +16 -0
- package/dist/serve/runtime/chip-user-search.d.ts.map +1 -0
- package/dist/serve/runtime/chip-user-search.js +354 -0
- package/dist/serve/runtime/chip-user-search.js.map +1 -0
- package/dist/serve/runtime/chip.d.ts +10 -0
- package/dist/serve/runtime/chip.d.ts.map +1 -1
- package/dist/serve/runtime/chip.js +118 -15
- package/dist/serve/runtime/chip.js.map +1 -1
- package/dist/serve/runtime/identity.d.ts +17 -0
- package/dist/serve/runtime/identity.d.ts.map +1 -0
- package/dist/serve/runtime/identity.js +10 -0
- package/dist/serve/runtime/identity.js.map +1 -0
- package/dist/serve/sandbox-session.d.ts +7 -0
- package/dist/serve/sandbox-session.d.ts.map +1 -1
- package/dist/serve/sandbox-session.js +2 -0
- package/dist/serve/sandbox-session.js.map +1 -1
- package/dist/serve/site-ui/_astro/{RulesCodeEditor.XtDmHOlN.js → RulesCodeEditor.DsTAsKIa.js} +1 -1
- package/dist/serve/site-ui/_astro/app.CMmTxyhL.js +1 -0
- package/dist/serve/site-ui/_astro/app.DhALsVii.js +115 -0
- package/dist/serve/site-ui/_astro/{chess-showcase.B72XYeoh.js → chess-showcase.Bn_pP6UJ.js} +2 -2
- package/dist/serve/site-ui/_astro/{example-runtime.C25_lx6Z.js → example-runtime.CXopTGv7.js} +1 -1
- package/dist/serve/site-ui/_astro/sandbox-controls.rOuZTOUG.js +510 -0
- package/dist/serve/site-ui/_astro/{seed.Co0yUJY5.js → seed.lywYbXZ0.js} +2 -2
- package/dist/serve/site-ui/_astro/writes.BsPBG3dp.js +653 -0
- package/dist/serve/site-ui/auth/index.html +1 -1
- package/dist/serve/site-ui/docs/_rhythm/index.html +1 -1
- package/dist/serve/site-ui/docs/agent/set-up-your-agent/index.html +1 -1
- package/dist/serve/site-ui/docs/agent/watch-and-review/index.html +1 -1
- package/dist/serve/site-ui/docs/agent/work-with-an-agent/index.html +1 -1
- package/dist/serve/site-ui/docs/ai-compat/index.html +1 -1
- package/dist/serve/site-ui/docs/api-reference/index.html +8 -1
- package/dist/serve/site-ui/docs/api-reference.md +7 -0
- package/dist/serve/site-ui/docs/app-compat/index.html +1 -1
- package/dist/serve/site-ui/docs/auth-compat/index.html +3 -3
- package/dist/serve/site-ui/docs/auth-compat.md +2 -2
- package/dist/serve/site-ui/docs/build/ai-logic/index.html +6 -1
- package/dist/serve/site-ui/docs/build/ai-logic.md +6 -0
- package/dist/serve/site-ui/docs/build/authentication/index.html +2 -2
- package/dist/serve/site-ui/docs/build/authentication.md +1 -1
- package/dist/serve/site-ui/docs/build/cloud-firestore/index.html +4 -2
- package/dist/serve/site-ui/docs/build/cloud-firestore.md +4 -0
- package/dist/serve/site-ui/docs/build/cloud-messaging/index.html +1 -1
- package/dist/serve/site-ui/docs/build/cloud-storage/index.html +1 -1
- package/dist/serve/site-ui/docs/build/realtime-database/index.html +1 -1
- package/dist/serve/site-ui/docs/conformance-scores/index.html +14 -2
- package/dist/serve/site-ui/docs/conformance-scores.md +13 -1
- package/dist/serve/site-ui/docs/create-pyric-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/database-compat/index.html +44 -44
- package/dist/serve/site-ui/docs/database-compat.md +43 -43
- package/dist/serve/site-ui/docs/examples/chess/index.html +1 -1
- package/dist/serve/site-ui/docs/examples/index.html +1 -1
- package/dist/serve/site-ui/docs/firestore-compat/index.html +4 -4
- package/dist/serve/site-ui/docs/firestore-compat.md +3 -3
- package/dist/serve/site-ui/docs/firestore-flutter-compat/index.html +319 -0
- package/dist/serve/site-ui/docs/firestore-flutter-compat.md +344 -0
- package/dist/serve/site-ui/docs/firestore-kotlin-compat/index.html +319 -0
- package/dist/serve/site-ui/docs/firestore-kotlin-compat.md +344 -0
- package/dist/serve/site-ui/docs/firestore-swift-compat/index.html +490 -0
- package/dist/serve/site-ui/docs/firestore-swift-compat.md +517 -0
- package/dist/serve/site-ui/docs/functions-rtdb-compat/index.html +1 -1
- package/dist/serve/site-ui/docs/get-started/backend-bundlers/index.html +105 -0
- package/dist/serve/site-ui/docs/get-started/backend-bundlers.md +165 -0
- package/dist/serve/site-ui/docs/get-started/flutter/index.html +98 -0
- package/dist/serve/site-ui/docs/get-started/flutter.md +105 -0
- package/dist/serve/site-ui/docs/get-started/how-the-swap-works/index.html +1 -1
- package/dist/serve/site-ui/docs/get-started/nextjs/index.html +1 -1
- package/dist/serve/site-ui/docs/get-started/start-building/index.html +1 -1
- package/dist/serve/site-ui/docs/get-started/vite/index.html +1 -1
- package/dist/serve/site-ui/docs/index.json +3211 -1471
- package/dist/serve/site-ui/docs/messaging-compat/index.html +1 -1
- package/dist/serve/site-ui/docs/observe/resolve-runtime-status/index.html +4 -3
- package/dist/serve/site-ui/docs/observe/resolve-runtime-status.md +3 -1
- package/dist/serve/site-ui/docs/observe/see-whats-happening/index.html +1 -1
- package/dist/serve/site-ui/docs/observe/shape-your-data/index.html +1 -1
- package/dist/serve/site-ui/docs/observe/switch-and-impersonate-identities/index.html +110 -0
- package/dist/serve/site-ui/docs/observe/switch-and-impersonate-identities.md +134 -0
- package/dist/serve/site-ui/docs/overview/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-app-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-auth-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-database-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-firestore-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-messaging-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-admin-storage-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ai-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ai-scripting-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-analytics-reference-api/index.html +124 -0
- package/dist/serve/site-ui/docs/pyric-analytics-reference-api.md +287 -0
- package/dist/serve/site-ui/docs/pyric-app-check-reference-api/index.html +87 -0
- package/dist/serve/site-ui/docs/pyric-app-check-reference-api.md +199 -0
- package/dist/serve/site-ui/docs/pyric-app-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-auth-reference-api/index.html +6 -2
- package/dist/serve/site-ui/docs/pyric-auth-reference-api.md +2 -1
- package/dist/serve/site-ui/docs/pyric-cli-assurance-browser-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-assurance-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-bridge-client-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-cli-bridge-client-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-bridge-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-bundler-reference-api/index.html +56 -0
- package/dist/serve/site-ui/docs/pyric-cli-bundler-reference-api.md +72 -0
- package/dist/serve/site-ui/docs/pyric-cli-conformance-browser-reference-api/index.html +4 -1
- package/dist/serve/site-ui/docs/pyric-cli-conformance-browser-reference-api.md +3 -0
- package/dist/serve/site-ui/docs/pyric-cli-conformance-docs-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-conformance-reference-api/index.html +4 -1
- package/dist/serve/site-ui/docs/pyric-cli-conformance-reference-api.md +3 -0
- package/dist/serve/site-ui/docs/pyric-cli-credentials-node-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-discover-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-next-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-cli-next-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-register-app-bridge-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-register-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-remote-reference-api/index.html +34 -9
- package/dist/serve/site-ui/docs/pyric-cli-remote-reference-api.md +16 -8
- package/dist/serve/site-ui/docs/pyric-cli-serve-worker-reference-api/index.html +133 -93
- package/dist/serve/site-ui/docs/pyric-cli-serve-worker-reference-api.md +61 -1
- package/dist/serve/site-ui/docs/pyric-cli-verify-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-cli-verify-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-cli-vite-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-cli-vite-reference-api.md +2 -2
- package/dist/serve/site-ui/docs/pyric-database-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-database-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-firestore-lite-reference-api/index.html +559 -0
- package/dist/serve/site-ui/docs/pyric-firestore-lite-reference-api.md +1240 -0
- package/dist/serve/site-ui/docs/pyric-firestore-reference-api/index.html +40 -11
- package/dist/serve/site-ui/docs/pyric-firestore-reference-api.md +18 -8
- package/dist/serve/site-ui/docs/pyric-functions-reference-api/index.html +67 -0
- package/dist/serve/site-ui/docs/pyric-functions-reference-api.md +149 -0
- package/dist/serve/site-ui/docs/pyric-messaging-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-messaging-sw-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-performance-reference-api/index.html +35 -0
- package/dist/serve/site-ui/docs/pyric-performance-reference-api.md +69 -0
- package/dist/serve/site-ui/docs/pyric-remote-config-reference-api/index.html +132 -0
- package/dist/serve/site-ui/docs/pyric-remote-config-reference-api.md +307 -0
- package/dist/serve/site-ui/docs/pyric-rules-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-sandbox-database-reference-api/index.html +52 -17
- package/dist/serve/site-ui/docs/pyric-sandbox-database-reference-api.md +48 -9
- package/dist/serve/site-ui/docs/pyric-sandbox-firestore-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-sandbox-reference-api/index.html +239 -49
- package/dist/serve/site-ui/docs/pyric-sandbox-reference-api.md +148 -31
- package/dist/serve/site-ui/docs/pyric-storage-reference-api/index.html +22 -4
- package/dist/serve/site-ui/docs/pyric-storage-reference-api.md +25 -3
- package/dist/serve/site-ui/docs/pyric-ui-agents-reference-api/index.html +26 -96
- package/dist/serve/site-ui/docs/pyric-ui-agents-reference-api.md +20 -51
- package/dist/serve/site-ui/docs/pyric-ui-auth-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-auth-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-ui-auth-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-events-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-events-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-firestore-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-firestore-reference-api/index.html +2 -2
- package/dist/serve/site-ui/docs/pyric-ui-firestore-reference-api.md +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-primitives-reference-api/index.html +124 -26
- package/dist/serve/site-ui/docs/pyric-ui-primitives-reference-api.md +58 -5
- package/dist/serve/site-ui/docs/pyric-ui-rtdb-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-rules-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-rules-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-storage-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-storage-reference-api/index.html +4 -5
- package/dist/serve/site-ui/docs/pyric-ui-storage-reference-api.md +3 -4
- package/dist/serve/site-ui/docs/pyric-ui-traffic-hooks-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/pyric-ui-traffic-reference-api/index.html +1 -1
- package/dist/serve/site-ui/docs/reference/cli/index.html +6 -3
- package/dist/serve/site-ui/docs/reference/cli.md +8 -2
- package/dist/serve/site-ui/docs/rules-compat/index.html +10 -2
- package/dist/serve/site-ui/docs/rules-compat.md +9 -1
- package/dist/serve/site-ui/docs/secure/audit-your-rules/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/firestore-rules-limits/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/read-a-denial/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/rtdb-rules-in-typescript/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/rules-standard-library/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/secure-it-with-rules/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/simulate-and-lint/index.html +1 -1
- package/dist/serve/site-ui/docs/secure/write-a-rules-test-suite/index.html +1 -1
- package/dist/serve/site-ui/docs/ship/ship-to-production/index.html +1 -1
- package/dist/serve/site-ui/docs/ship/test-in-node/index.html +1 -1
- package/dist/serve/site-ui/docs/storage-compat/index.html +13 -13
- package/dist/serve/site-ui/docs/storage-compat.md +12 -12
- package/dist/serve/site-ui/docs/trust/how-we-know-it-matches-firebase/index.html +1 -1
- package/dist/serve/site-ui/docs/trust/rules-standard-library/index.html +1 -1
- package/dist/serve/site-ui/docs/trust/versioning-and-compatibility/index.html +1 -1
- package/dist/serve/site-ui/docs/tutorial/index.html +1 -1
- package/dist/serve/site-ui/examples/chess/index.html +1 -1
- package/dist/serve/site-ui/firestore/index.html +1 -1
- package/dist/serve/site-ui/llms.txt +13 -0
- package/dist/serve/site-ui/rtdb/index.html +1 -1
- package/dist/serve/site-ui/settings/index.html +1 -1
- package/dist/serve/site-ui/storage/index.html +1 -1
- package/dist/serve/site-ui/studio/index.html +1 -1
- package/dist/serve/site-ui/traffic/index.html +1 -1
- package/dist/serve/studio/disk-workspace.d.ts.map +1 -1
- package/dist/serve/studio/disk-workspace.js +64 -2
- package/dist/serve/studio/disk-workspace.js.map +1 -1
- package/dist/serve/vite-plugin.d.ts +7 -7
- package/dist/serve/vite-plugin.js +1 -1
- package/dist/serve/vite-plugin.js.map +1 -1
- package/dist/serve/vite-sandbox-generation.d.ts.map +1 -1
- package/dist/serve/vite-sandbox-generation.js +12 -0
- package/dist/serve/vite-sandbox-generation.js.map +1 -1
- package/dist/serve/worker/client/auth.js +1 -2
- package/dist/serve/worker/client/auth.js.map +1 -1
- package/dist/serve/worker/client/core.d.ts +21 -1
- package/dist/serve/worker/client/core.d.ts.map +1 -1
- package/dist/serve/worker/client/core.js +79 -3
- package/dist/serve/worker/client/core.js.map +1 -1
- package/dist/serve/worker/client.d.ts +1 -1
- package/dist/serve/worker/client.d.ts.map +1 -1
- package/dist/serve/worker/client.js +1 -1
- package/dist/serve/worker/client.js.map +1 -1
- package/dist/serve/worker/context-resolver.d.ts +30 -0
- package/dist/serve/worker/context-resolver.d.ts.map +1 -0
- package/dist/serve/worker/context-resolver.js +44 -0
- package/dist/serve/worker/context-resolver.js.map +1 -0
- package/dist/serve/worker/entry.js +23 -19
- package/dist/serve/worker/entry.js.map +1 -1
- package/dist/serve/worker/host/core.d.ts +1 -0
- package/dist/serve/worker/host/core.d.ts.map +1 -1
- package/dist/serve/worker/host/core.js +12 -6
- package/dist/serve/worker/host/core.js.map +1 -1
- package/dist/serve/worker/host/storage.js +2 -2
- package/dist/serve/worker/host-auth.js +1 -2
- package/dist/serve/worker/host-auth.js.map +1 -1
- package/dist/serve/worker/index.d.ts +1 -1
- package/dist/serve/worker/index.d.ts.map +1 -1
- package/dist/serve/worker/index.js +2 -2
- package/dist/serve/worker/index.js.map +1 -1
- package/dist/serve/worker/port-lifecycle.d.ts +18 -0
- package/dist/serve/worker/port-lifecycle.d.ts.map +1 -0
- package/dist/serve/worker/port-lifecycle.js +28 -0
- package/dist/serve/worker/port-lifecycle.js.map +1 -0
- package/dist/serve/worker/serve-init.d.ts.map +1 -1
- package/dist/serve/worker/serve-init.js +8 -2
- package/dist/serve/worker/serve-init.js.map +1 -1
- package/dist/verify/fixture.d.ts +1 -1
- package/package.json +16 -5
- package/src/assurance/.generated/conformance-verdicts.ts +238 -1
- package/src/bridge/client/dispatch.ts +52 -56
- package/src/bridge/client/tool-family-factories.ts +34 -0
- package/src/bridge/server/mcp-contract.ts +15 -59
- package/src/bridge/server/peer.ts +24 -1
- package/src/bridge/server/tool-family-factories.ts +40 -0
- package/src/bridge/server/tool-metadata.ts +29 -61
- package/src/bridge/tool-families.generated.ts +17 -0
- package/src/bridge/tool-families.ts +87 -0
- package/src/bridge/tool-family-records/conformance.ts +6 -0
- package/src/bridge/tool-family-records/firestore-data.ts +15 -0
- package/src/bridge/tool-family-records/firestore-inspect.ts +6 -0
- package/src/bridge/tool-family-records/firestore-rules.ts +15 -0
- package/src/bridge/tool-family-records/firestore-simulator.ts +16 -0
- package/src/bridge/tool-family-records/rtdb-inspection.ts +6 -0
- package/src/bundler/externals.ts +55 -0
- package/src/bundler/index.ts +21 -0
- package/src/cli/cli.test.ts +0 -44
- package/src/cli/inlined-sdk-scanner.ts +77 -0
- package/src/cli/sandbox-interlock.ts +167 -0
- package/src/cli/sandbox-runner.ts +37 -26
- package/src/cli/serve.ts +68 -69
- package/src/cli/unsupported-runtime.ts +68 -0
- package/src/conformance/.generated/can-i-use-browser.ts +2 -2
- package/src/conformance/.generated/can-i-use.ts +2 -2
- package/src/conformance/.generated/conformance-docs.ts +1 -1
- package/src/functions-rtdb/child.ts +115 -21
- package/src/functions-rtdb/development-runtime.ts +4 -0
- package/src/google-endpoints.ts +155 -0
- package/src/next/runtime-env.ts +5 -0
- package/src/next/with-pyric.ts +1 -1
- package/src/register/beacon.ts +232 -0
- package/src/register/index.ts +68 -6
- package/src/register/net-guard.ts +567 -0
- package/src/serve/ai-diagnostics-relay.ts +243 -0
- package/src/serve/ai-proxy.ts +327 -0
- package/src/serve/ai-status.ts +109 -0
- package/src/serve/ai-terminal-blocks.ts +210 -0
- package/src/serve/ai-terminal-text.ts +52 -0
- package/src/serve/beacon-route.ts +141 -0
- package/src/serve/entries/active-auth-registry.ts +56 -0
- package/src/serve/entries/active-auth.ts +100 -0
- package/src/serve/entries/auth-helper-core.ts +5 -0
- package/src/serve/entries/auth-helper-dom.ts +26 -2
- package/src/serve/entries/auth.ts +8 -0
- package/src/serve/entries/bridge-url.ts +1 -1
- package/src/serve/entries/init.ts +78 -3
- package/src/serve/entries/runtime.ts +10 -0
- package/src/serve/namespace.ts +73 -140
- package/src/serve/runtime/chip-config.ts +16 -2
- package/src/serve/runtime/chip-dialog.ts +366 -0
- package/src/serve/runtime/chip-install.ts +10 -4
- package/src/serve/runtime/chip-user-search.ts +391 -0
- package/src/serve/runtime/chip.ts +140 -15
- package/src/serve/runtime/identity.ts +26 -0
- package/src/serve/sandbox-session.ts +9 -0
- package/src/serve/studio/disk-workspace.ts +76 -2
- package/src/serve/vite-plugin.ts +8 -8
- package/src/serve/vite-sandbox-generation.ts +15 -0
- package/src/serve/worker/client/auth.ts +1 -1
- package/src/serve/worker/client/core.ts +80 -3
- package/src/serve/worker/client.ts +1 -1
- package/src/serve/worker/context-resolver.ts +60 -0
- package/src/serve/worker/entry.ts +22 -18
- package/src/serve/worker/host/core.ts +9 -7
- package/src/serve/worker/host/storage.ts +2 -2
- package/src/serve/worker/host-auth.ts +1 -1
- package/src/serve/worker/index.ts +4 -1
- package/src/serve/worker/port-lifecycle.ts +45 -0
- package/src/serve/worker/serve-init.ts +9 -2
- package/src/verify/fixture.ts +1 -1
- package/dist/serve/site-ui/_astro/app.B52xr-DK.js +0 -1
- package/dist/serve/site-ui/_astro/app.DWBraPUw.js +0 -12
- package/dist/serve/site-ui/_astro/sandbox-controls.DEpnKg-O.js +0 -1169
- package/dist/serve/site-ui/_astro/writes.rpjrFzmu.js +0 -102
package/src/register/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@pyric/cli/register` — the Node substitution seam (adoption layer 2).
|
|
3
3
|
*
|
|
4
|
-
* Loaded via `node --import @pyric/cli/register` (which `pyric
|
|
5
|
-
* through NODE_OPTIONS), it makes the user's UNCHANGED `firebase-admin`
|
|
6
|
-
* `firebase` imports resolve to `pyric-admin`
|
|
4
|
+
* Loaded via `node --import @pyric/cli/register` (which `pyric sandbox`
|
|
5
|
+
* injects through NODE_OPTIONS), it makes the user's UNCHANGED `firebase-admin`
|
|
6
|
+
* and `firebase` imports resolve to `pyric-admin` and `pyric`, every subpath 1:1,
|
|
7
7
|
* and installs the sandbox-factory global that `pyric-admin`'s ambient
|
|
8
8
|
* `initializeApp()` consumes.
|
|
9
9
|
*
|
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
* `require()` and `import`. On older 22.x it falls back to
|
|
18
18
|
* `module.register()` (ESM-only) with a warning that CJS require() is not
|
|
19
19
|
* rewritten.
|
|
20
|
+
*
|
|
21
|
+
* On activation it also installs the NETWORK GUARD (`./net-guard.js`), which
|
|
22
|
+
* reports egress from this process to live Google/Firebase endpoints, or
|
|
23
|
+
* refuses it under `PYRIC_GUARD=block`. See that module for the policy and the
|
|
24
|
+
* `PYRIC_GUARD` and `PYRIC_GUARD_ALLOW` knobs.
|
|
25
|
+
*
|
|
26
|
+
* Finally it emits the HANDSHAKE BEACON (`./beacon.js`): a fire-and-forget
|
|
27
|
+
* `POST /__pyric/beacon` when the activator carries a bridge URL, plus a
|
|
28
|
+
* stderr line when the developer asked for detail. That is how `pyric sandbox`
|
|
29
|
+
* learns that interception actually reached this child rather than assuming
|
|
30
|
+
* it did.
|
|
20
31
|
*/
|
|
21
32
|
import Module from 'node:module';
|
|
22
33
|
import { readFileSync } from 'node:fs';
|
|
@@ -24,6 +35,8 @@ import { dirname, join } from 'node:path';
|
|
|
24
35
|
import { pathToFileURL } from 'node:url';
|
|
25
36
|
import { mapFirebaseSpecifier } from './mapping.js';
|
|
26
37
|
import { resolveEsmOnlySubpath } from './esm-exports.js';
|
|
38
|
+
import { installNetGuard, parseGuardMode, type GuardMode } from './net-guard.js';
|
|
39
|
+
import { emitBeacon } from './beacon.js';
|
|
27
40
|
import { remoteSandbox } from '../remote/index.js';
|
|
28
41
|
|
|
29
42
|
/** The shared seam with pyric-admin's ambient init: a synchronous factory
|
|
@@ -89,7 +102,30 @@ function resolveEsmOnlyForRequire(mapped: string): string | null {
|
|
|
89
102
|
}
|
|
90
103
|
|
|
91
104
|
function activate(): void {
|
|
105
|
+
// FIRST, before any hook or global: the network guard.
|
|
106
|
+
//
|
|
107
|
+
// Order matters in one direction only. Everything after this line makes the
|
|
108
|
+
// process load MORE code (the resolution hooks pull in the pyric mirrors,
|
|
109
|
+
// the factory global pulls in the remote sandbox) and any of it could open
|
|
110
|
+
// a socket. Installing the guard first leaves no window in which
|
|
111
|
+
// sandbox-substituted code runs unguarded. The reverse ordering buys
|
|
112
|
+
// nothing: the guard mutates globals only (`undici.globalDispatcher.1`,
|
|
113
|
+
// `net`/`tls` connect) and depends on nothing the hooks establish.
|
|
114
|
+
//
|
|
115
|
+
// It stays BELOW the NODE_ENV=production refusal, deliberately. A refused
|
|
116
|
+
// process is a real production run that we declined to touch, and warning
|
|
117
|
+
// about its perfectly legitimate Google traffic, let alone blocking it,
|
|
118
|
+
// would be actively harmful. `PYRIC_SANDBOX` plus no refusal is the only
|
|
119
|
+
// state in which "traffic to live Google is a bug" is a true statement.
|
|
120
|
+
const guard = installNetGuard();
|
|
121
|
+
|
|
122
|
+
// Whether module resolution is actually being intercepted. Both branches
|
|
123
|
+
// below install SOMETHING, but a runtime with neither API installs nothing,
|
|
124
|
+
// which is precisely the state the beacon exists to make visible.
|
|
125
|
+
let hooksInstalled = false;
|
|
126
|
+
|
|
92
127
|
if (typeof moduleApi.registerHooks === 'function') {
|
|
128
|
+
hooksInstalled = true;
|
|
93
129
|
moduleApi.registerHooks({
|
|
94
130
|
resolve(specifier, context, nextResolve) {
|
|
95
131
|
const mapped = mapFirebaseSpecifier(specifier, context.parentURL);
|
|
@@ -112,10 +148,11 @@ function activate(): void {
|
|
|
112
148
|
});
|
|
113
149
|
} else {
|
|
114
150
|
process.stderr.write(
|
|
115
|
-
'@pyric/cli/register: this Node version lacks module.registerHooks (needs >= 22.15)
|
|
116
|
-
'
|
|
151
|
+
'@pyric/cli/register: this Node version lacks module.registerHooks (needs >= 22.15). ' +
|
|
152
|
+
'Falling back to module.register: ESM imports of firebase-admin/firebase are rewritten, ' +
|
|
117
153
|
"but CJS require('firebase-admin') is NOT intercepted. Upgrade Node to >= 22.15 for full coverage.\n",
|
|
118
154
|
);
|
|
155
|
+
hooksInstalled = typeof moduleApi.register === 'function';
|
|
119
156
|
moduleApi.register?.(new URL('./hooks.js', import.meta.url));
|
|
120
157
|
}
|
|
121
158
|
|
|
@@ -125,9 +162,34 @@ function activate(): void {
|
|
|
125
162
|
remoteSandbox(opts);
|
|
126
163
|
|
|
127
164
|
process.stderr.write(
|
|
128
|
-
`@pyric/cli/register: active
|
|
165
|
+
`@pyric/cli/register: active. firebase-admin/firebase imports now resolve to the ` +
|
|
129
166
|
`pyric sandbox (PYRIC_SANDBOX=${process.env.PYRIC_SANDBOX}).\n`,
|
|
130
167
|
);
|
|
168
|
+
|
|
169
|
+
// LAST: the handshake beacon, after the guard, the hooks and the factory
|
|
170
|
+
// global are all in place. Its whole claim is "interception is live in this
|
|
171
|
+
// process", so it must not be able to run before that is true. See
|
|
172
|
+
// `./beacon.js` for the two channels and why the POST is fire-and-forget.
|
|
173
|
+
emitBeacon({
|
|
174
|
+
pid: process.pid,
|
|
175
|
+
guard: installedGuardMode(guard),
|
|
176
|
+
hooks: hooksInstalled,
|
|
177
|
+
sandbox: process.env.PYRIC_SANDBOX ?? '',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The net-guard mode actually in force, for the beacon to report.
|
|
183
|
+
*
|
|
184
|
+
* Policy: the installed guard is the authority when there is one. There is no
|
|
185
|
+
* guard object in exactly one case, `PYRIC_GUARD=off` (the `PYRIC_SANDBOX`
|
|
186
|
+
* gate `installNetGuard` shares with this module has already passed by the
|
|
187
|
+
* time it runs), and re-parsing the env is how that case names itself rather
|
|
188
|
+
* than guessing a default.
|
|
189
|
+
*/
|
|
190
|
+
function installedGuardMode(guard: { mode: GuardMode } | null): GuardMode {
|
|
191
|
+
if (guard !== null) return guard.mode;
|
|
192
|
+
return parseGuardMode(process.env.PYRIC_GUARD);
|
|
131
193
|
}
|
|
132
194
|
|
|
133
195
|
/** Whether this process's firebase-admin/firebase imports are being rewritten
|
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime network guard: the enforcement half of the production-leak
|
|
3
|
+
* invariant.
|
|
4
|
+
*
|
|
5
|
+
* A sandboxed app's Firebase traffic all routes to the local `/__pyric/*`
|
|
6
|
+
* namespace. So a pyric-launched process that opens a connection to a real
|
|
7
|
+
* Google/Firebase endpoint has escaped the sandbox: it is reading or writing
|
|
8
|
+
* live production data with the developer believing otherwise. This module
|
|
9
|
+
* detects that egress and, depending on one knob, warns about it or fails it.
|
|
10
|
+
*
|
|
11
|
+
* Where it hooks, and why exactly there
|
|
12
|
+
* -------------------------------------
|
|
13
|
+
* 1. `Symbol.for('undici.globalDispatcher.1')`, the undici global dispatcher.
|
|
14
|
+
* Measured against Next 15.5 / Node 24 / undici 7, this one seam covers
|
|
15
|
+
* Node route handlers, edge route handlers and middleware, under both the
|
|
16
|
+
* webpack and turbopack dev servers. Patching `globalThis.fetch` does not:
|
|
17
|
+
* the edge sandbox bundles its own undici, and that copy's
|
|
18
|
+
* `getGlobalDispatcher()` reads the host realm's symbol, which is precisely
|
|
19
|
+
* why hooking the dispatcher reaches it and hooking `fetch` does not.
|
|
20
|
+
*
|
|
21
|
+
* Three mechanics the seam depends on:
|
|
22
|
+
* - undici installs the property `configurable: false, writable: true`, so
|
|
23
|
+
* we install by plain assignment. A `defineProperty` with
|
|
24
|
+
* `configurable: true` throws a TypeError and takes the dev server down
|
|
25
|
+
* with it. Accessor traps are useless anyway, because
|
|
26
|
+
* `setGlobalDispatcher` uses `defineProperty`, which bypasses setters.
|
|
27
|
+
* - The property does not exist until undici is first touched, and undici
|
|
28
|
+
* only installs a default agent when it finds the slot empty. So we
|
|
29
|
+
* materialize it first with `new Headers()` (loads undici, zero
|
|
30
|
+
* network) and wrap whatever real Agent that produces.
|
|
31
|
+
* - The `handler` argument of `dispatch(opts, handler)` must pass through
|
|
32
|
+
* opaque and by identity. Edge hands a v6-shaped handler to the host's
|
|
33
|
+
* v7 Agent and that cross-version handoff only survives untouched. We
|
|
34
|
+
* read `opts.origin` and nothing else.
|
|
35
|
+
*
|
|
36
|
+
* 2. `net.connect` / `net.createConnection` / `tls.connect`, plus the
|
|
37
|
+
* `createConnection` on the `http.Agent` and `https.Agent` prototypes: the
|
|
38
|
+
* backstop for traffic that never goes through undici, such as
|
|
39
|
+
* `http.request`, gRPC, database drivers, anything holding a raw socket.
|
|
40
|
+
* Same catalog, same policy. (undici itself connects through `net.connect`,
|
|
41
|
+
* so a warn-mode fetch would report twice; the once-per-host dedupe below
|
|
42
|
+
* collapses that.)
|
|
43
|
+
*
|
|
44
|
+
* The Agent prototypes need their own patch because
|
|
45
|
+
* `http.Agent.prototype.createConnection` is a copied reference to
|
|
46
|
+
* `net.createConnection`, taken when `_http_agent` first loaded. If anything
|
|
47
|
+
* loaded `node:http` before this module ran, that copy is the unpatched
|
|
48
|
+
* function and every plain `http.request` would sail past the backstop,
|
|
49
|
+
* including a request to the metadata server. It is also why the socket
|
|
50
|
+
* patches are installed BEFORE the dispatcher is materialized: materializing
|
|
51
|
+
* loads undici, which loads `_http_agent`.
|
|
52
|
+
*
|
|
53
|
+
* Policy
|
|
54
|
+
* ------
|
|
55
|
+
* One knob, `PYRIC_GUARD=warn|block|off`, default `warn`:
|
|
56
|
+
* warn report the egress, let it through
|
|
57
|
+
* block report it and fail the request
|
|
58
|
+
* off no hooks at all, one notice line at install time
|
|
59
|
+
* The GCE metadata IP (`169.254.169.254`, `alwaysBlock` in the catalog) is
|
|
60
|
+
* refused in warn mode and cannot be allowlisted, since its only use from a
|
|
61
|
+
* dev process is credential theft. `off` is genuinely off, metadata IP
|
|
62
|
+
* included; the off notice says so out loud.
|
|
63
|
+
*
|
|
64
|
+
* A blocked fetch surfaces to app code as a bare `TypeError: fetch failed`
|
|
65
|
+
* (the reason is buried on `error.cause`), so the guard must log its own
|
|
66
|
+
* denial: the app's error will never explain itself.
|
|
67
|
+
*
|
|
68
|
+
* The allowlist seam
|
|
69
|
+
* ------------------
|
|
70
|
+
* `PYRIC_GUARD_ALLOW` is a comma/whitespace separated list of hosts or URLs,
|
|
71
|
+
* matched on label boundaries, permitting an otherwise-flagged catalog host
|
|
72
|
+
* (an allowlisted hit is still reported once). Env is the seam by design:
|
|
73
|
+
* - the AI engine baseUrls live in the user's Vite config
|
|
74
|
+
* (`PyricAiOptions.engine.baseUrl`, `serve/vite-ai-config.ts`), which is
|
|
75
|
+
* read by the Vite plugin inside the serve host, a different process from
|
|
76
|
+
* the one this module loads into, and not parsed by the CLI at all;
|
|
77
|
+
* - `pyric.json` is read asynchronously by `runServe` (`cli/pyric-config.ts`)
|
|
78
|
+
* and this module runs on the `--import` hot path of every child, where a
|
|
79
|
+
* synchronous config-file read has no business being.
|
|
80
|
+
* `cli/sandbox-runner.ts:buildChildEnv` spreads the parent env into the child,
|
|
81
|
+
* so anything the pyric process exports reaches every descendant for free
|
|
82
|
+
* (`NODE_OPTIONS` already propagates the register import the same way). To
|
|
83
|
+
* wire a `pyric.json` `guardAllow` through, the whole change is: add the field
|
|
84
|
+
* to `PyricConfig`, and have `buildChildEnv` set `PYRIC_GUARD_ALLOW` from it
|
|
85
|
+
* at the `cli/serve.ts` call site, where `pyricConfig` is already in scope.
|
|
86
|
+
*
|
|
87
|
+
* Bun and Deno are out of scope: neither evaluates Node loader hooks (the
|
|
88
|
+
* register module never loads there) and neither routes `fetch` through
|
|
89
|
+
* undici's global dispatcher. `installNetGuard` degrades to the socket
|
|
90
|
+
* backstop instead of throwing.
|
|
91
|
+
*/
|
|
92
|
+
import { createRequire } from 'node:module';
|
|
93
|
+
import {
|
|
94
|
+
lookupGoogleEndpoint,
|
|
95
|
+
matchesHostSuffix,
|
|
96
|
+
normalizeHostname,
|
|
97
|
+
type GoogleEndpoint,
|
|
98
|
+
} from '../google-endpoints.js';
|
|
99
|
+
|
|
100
|
+
/** undici's global-dispatcher slot. Version-suffixed by undici itself. */
|
|
101
|
+
const UNDICI_GLOBAL_DISPATCHER = Symbol.for('undici.globalDispatcher.1');
|
|
102
|
+
|
|
103
|
+
/** Marks a rejection as the guard's, so callers can tell it from a DNS/TLS
|
|
104
|
+
* failure. A blocked `fetch` only exposes it as `error.cause.code`. */
|
|
105
|
+
export const GUARD_BLOCKED_CODE = 'PYRIC_GUARD_BLOCKED';
|
|
106
|
+
|
|
107
|
+
const LOG_PREFIX = '@pyric/cli/register: net-guard';
|
|
108
|
+
|
|
109
|
+
/** How often to check that nobody replaced the global dispatcher under us. */
|
|
110
|
+
const REASSERT_INTERVAL_MS = 5_000;
|
|
111
|
+
|
|
112
|
+
export type GuardMode = 'warn' | 'block' | 'off';
|
|
113
|
+
|
|
114
|
+
/** What the guard decided about one outbound connection. */
|
|
115
|
+
export interface EgressVerdict {
|
|
116
|
+
/** `warn` reported-and-permitted, `block` refused, `allow` allowlisted. */
|
|
117
|
+
readonly verdict: 'warn' | 'block' | 'allow';
|
|
118
|
+
/** Whether the connection may proceed. */
|
|
119
|
+
readonly permitted: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* The hostname actually being contacted, which is what the developer needs
|
|
122
|
+
* in order to find the call. Not the catalog suffix: `cloudfunctions.net`
|
|
123
|
+
* does not tell you which region or project a callable went to.
|
|
124
|
+
*/
|
|
125
|
+
readonly host: string;
|
|
126
|
+
/** The catalog suffix that matched (`host` when the match was exact). */
|
|
127
|
+
readonly endpoint: string;
|
|
128
|
+
/** Human service label, verbatim from the shared catalog. */
|
|
129
|
+
readonly service: string;
|
|
130
|
+
/** Present only for catalog entries that can never be a false positive. */
|
|
131
|
+
readonly alwaysBlock?: true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `PYRIC_GUARD` → mode. Unset, empty or unrecognised all mean the safe
|
|
135
|
+
* default: report, do not break the developer's app. */
|
|
136
|
+
export function parseGuardMode(raw: string | undefined): GuardMode {
|
|
137
|
+
const value = (raw ?? '').trim().toLowerCase();
|
|
138
|
+
if (value === 'block') return 'block';
|
|
139
|
+
if (value === 'off') return 'off';
|
|
140
|
+
return 'warn';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** `PYRIC_GUARD_ALLOW` → hostnames. Accepts bare hosts and full URLs, because
|
|
144
|
+
* the values it carries are configured as URLs (AI engine baseUrls). */
|
|
145
|
+
export function parseAllowHosts(raw: string | undefined): string[] {
|
|
146
|
+
if (!raw) return [];
|
|
147
|
+
const out: string[] = [];
|
|
148
|
+
for (const token of raw.split(/[\s,]+/)) {
|
|
149
|
+
const entry = token.trim();
|
|
150
|
+
if (entry.length === 0) continue;
|
|
151
|
+
out.push(hostnameOf(entry));
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Only a trailing `:port` is stripped; a bare IPv6 address is left alone. */
|
|
157
|
+
const HOST_WITH_PORT = /^(.+):\d+$/;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Best-effort hostname from a host, `host:port`, or full URL. Normalization
|
|
161
|
+
* and suffix matching are the catalog's, so the guard and the catalog can
|
|
162
|
+
* never disagree about what a hostname is.
|
|
163
|
+
*/
|
|
164
|
+
function hostnameOf(value: string): string {
|
|
165
|
+
const trimmed = value.trim();
|
|
166
|
+
if (trimmed.includes('://')) {
|
|
167
|
+
try {
|
|
168
|
+
return normalizeHostname(new URL(trimmed).hostname).replace(/^\[|\]$/g, '');
|
|
169
|
+
} catch {
|
|
170
|
+
// Not a parseable URL: fall through to the textual forms.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const withoutPath = trimmed.split('/')[0] ?? trimmed;
|
|
174
|
+
const portMatch = HOST_WITH_PORT.exec(withoutPath);
|
|
175
|
+
let hostPart: string;
|
|
176
|
+
if (portMatch === null) {
|
|
177
|
+
hostPart = withoutPath;
|
|
178
|
+
} else {
|
|
179
|
+
hostPart = portMatch[1]!;
|
|
180
|
+
}
|
|
181
|
+
return normalizeHostname(hostPart);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The whole verdict, pure: catalog lookup, then `alwaysBlock`, then the
|
|
186
|
+
* allowlist, then the mode. `null` means nothing to say: either not a
|
|
187
|
+
* production endpoint, or the guard is off.
|
|
188
|
+
*/
|
|
189
|
+
export function evaluateEgress(
|
|
190
|
+
hostname: string,
|
|
191
|
+
policy: { mode: GuardMode; allow: readonly string[] },
|
|
192
|
+
): EgressVerdict | null {
|
|
193
|
+
if (policy.mode === 'off') return null;
|
|
194
|
+
const host = hostnameOf(hostname);
|
|
195
|
+
if (host.length === 0) return null;
|
|
196
|
+
const entry: GoogleEndpoint | undefined = lookupGoogleEndpoint(host);
|
|
197
|
+
if (entry === undefined) return null;
|
|
198
|
+
|
|
199
|
+
// `alwaysBlock` outranks both the mode and the allowlist: the metadata
|
|
200
|
+
// server is never a legitimate destination for a sandboxed dev process, so
|
|
201
|
+
// there is no configuration that should be able to permit it.
|
|
202
|
+
if (entry.alwaysBlock === true) {
|
|
203
|
+
return {
|
|
204
|
+
verdict: 'block',
|
|
205
|
+
permitted: false,
|
|
206
|
+
host,
|
|
207
|
+
endpoint: entry.host,
|
|
208
|
+
service: entry.service,
|
|
209
|
+
alwaysBlock: true,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (policy.allow.some((allowed) => matchesHostSuffix(host, allowed))) {
|
|
214
|
+
return { verdict: 'allow', permitted: true, host, endpoint: entry.host, service: entry.service };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (policy.mode === 'block') {
|
|
218
|
+
return {
|
|
219
|
+
verdict: 'block',
|
|
220
|
+
permitted: false,
|
|
221
|
+
host,
|
|
222
|
+
endpoint: entry.host,
|
|
223
|
+
service: entry.service,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return { verdict: 'warn', permitted: true, host, endpoint: entry.host, service: entry.service };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** One stderr line per verdict: structured (fixed leading fields, so it is
|
|
230
|
+
* greppable) and attributable (service + transport + initiating command).
|
|
231
|
+
* The request PATH is deliberately never logged: it carries ids and tokens. */
|
|
232
|
+
export function formatGuardLine(
|
|
233
|
+
verdict: EgressVerdict,
|
|
234
|
+
transport: 'fetch' | 'socket',
|
|
235
|
+
context: string | undefined,
|
|
236
|
+
): string {
|
|
237
|
+
let where = `via ${transport}`;
|
|
238
|
+
if (context !== undefined && context.length > 0) where = `${where} from ${context}`;
|
|
239
|
+
const head = `${LOG_PREFIX} ${verdict.verdict.toUpperCase()} ${verdict.host} (${verdict.service}) ${where}:`;
|
|
240
|
+
const tail = 'Further attempts to this host are not logged.';
|
|
241
|
+
if (verdict.verdict === 'allow') {
|
|
242
|
+
return `${head} live production egress permitted by PYRIC_GUARD_ALLOW. ${tail}\n`;
|
|
243
|
+
}
|
|
244
|
+
if (verdict.verdict === 'warn') {
|
|
245
|
+
return (
|
|
246
|
+
`${head} LIVE production egress. A sandboxed app routes Firebase traffic to /__pyric/*, ` +
|
|
247
|
+
`so this is reaching real data. Set PYRIC_GUARD=block to fail these requests instead. ${tail}\n`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
let why: string;
|
|
251
|
+
if (verdict.alwaysBlock === true) {
|
|
252
|
+
why = 'the credential metadata server is refused in every mode except PYRIC_GUARD=off';
|
|
253
|
+
} else {
|
|
254
|
+
why = 'live production egress refused (PYRIC_GUARD=block)';
|
|
255
|
+
}
|
|
256
|
+
// What the app actually observes differs by seam: undici swallows our throw
|
|
257
|
+
// into the opaque `TypeError: fetch failed`, while a raw socket caller gets
|
|
258
|
+
// the error itself. Say which, or the developer cannot connect the two.
|
|
259
|
+
let surfaces: string;
|
|
260
|
+
if (transport === 'fetch') {
|
|
261
|
+
surfaces = `the caller sees \`TypeError: fetch failed\` with cause ${GUARD_BLOCKED_CODE}`;
|
|
262
|
+
} else {
|
|
263
|
+
surfaces = `the caller sees an error with code ${GUARD_BLOCKED_CODE}`;
|
|
264
|
+
}
|
|
265
|
+
return `${head} ${why}; ${surfaces}. ${tail}\n`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function blockedError(verdict: EgressVerdict, transport: 'fetch' | 'socket'): Error {
|
|
269
|
+
return Object.assign(
|
|
270
|
+
new Error(
|
|
271
|
+
`pyric net-guard blocked ${transport} egress to ${verdict.host} (${verdict.service}): ` +
|
|
272
|
+
`this is LIVE production, not the pyric sandbox. ` +
|
|
273
|
+
`Set PYRIC_GUARD=warn to allow it, or PYRIC_GUARD_ALLOW to permit this host.`,
|
|
274
|
+
),
|
|
275
|
+
{ code: GUARD_BLOCKED_CODE, host: verdict.host, service: verdict.service },
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ─── the reporter: evaluate, log once, permit or refuse ───────────────────────
|
|
280
|
+
|
|
281
|
+
export interface ReporterOptions {
|
|
282
|
+
readonly mode: GuardMode;
|
|
283
|
+
readonly allow: readonly string[];
|
|
284
|
+
readonly write?: (line: string) => void;
|
|
285
|
+
/** Initiating command, for attribution. Usually `basename(argv[1])`. */
|
|
286
|
+
readonly context?: string;
|
|
287
|
+
/**
|
|
288
|
+
* The shared "already reported" ledger. `installNetGuard` hands the SAME set
|
|
289
|
+
* to the dispatcher wrapper and the socket backstop, because undici connects
|
|
290
|
+
* through `net.connect`: a warn-mode fetch trips both seams and would
|
|
291
|
+
* otherwise print the same host twice. It also survives a re-assert, so
|
|
292
|
+
* being re-wrapped does not restart the noise.
|
|
293
|
+
*/
|
|
294
|
+
readonly reported?: Set<string>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface Reporter {
|
|
298
|
+
/** Returns the verdict, having logged it at most once per host, and throws
|
|
299
|
+
* when the verdict refuses the connection. */
|
|
300
|
+
check(hostname: string | undefined, transport: 'fetch' | 'socket'): void;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function createReporter(options: ReporterOptions): Reporter {
|
|
304
|
+
const write = options.write ?? ((line: string) => void process.stderr.write(line));
|
|
305
|
+
const policy = { mode: options.mode, allow: options.allow };
|
|
306
|
+
const reported = options.reported ?? new Set<string>();
|
|
307
|
+
return {
|
|
308
|
+
check(hostname, transport) {
|
|
309
|
+
if (hostname === undefined) return;
|
|
310
|
+
const verdict = evaluateEgress(hostname, policy);
|
|
311
|
+
if (verdict === null) return;
|
|
312
|
+
// A dev server retries relentlessly; one line per host is the signal,
|
|
313
|
+
// and it also collapses the undici-over-net.connect double report.
|
|
314
|
+
const key = `${verdict.verdict}:${verdict.host}`;
|
|
315
|
+
if (!reported.has(key)) {
|
|
316
|
+
reported.add(key);
|
|
317
|
+
write(formatGuardLine(verdict, transport, options.context));
|
|
318
|
+
}
|
|
319
|
+
if (!verdict.permitted) throw blockedError(verdict, transport);
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ─── the undici dispatcher wrapper ─────────────────────────────────────────
|
|
325
|
+
|
|
326
|
+
interface Dispatcher {
|
|
327
|
+
dispatch(opts: unknown, handler: unknown): unknown;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** `opts.origin` is a URL or an origin string; anything else means "no idea",
|
|
331
|
+
* and an unrecognisable origin is passed through rather than guessed at. */
|
|
332
|
+
function originHost(opts: unknown): string | undefined {
|
|
333
|
+
const origin = (opts as { origin?: unknown } | null | undefined)?.origin;
|
|
334
|
+
if (origin === undefined || origin === null) return undefined;
|
|
335
|
+
if (typeof origin === 'object' && 'hostname' in origin) {
|
|
336
|
+
const hostname = (origin as { hostname?: unknown }).hostname;
|
|
337
|
+
return typeof hostname === 'string' ? hostname.toLowerCase() : undefined;
|
|
338
|
+
}
|
|
339
|
+
if (typeof origin !== 'string') return undefined;
|
|
340
|
+
try {
|
|
341
|
+
return new URL(origin).hostname.toLowerCase();
|
|
342
|
+
} catch {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Wrap a dispatcher so `dispatch` is guarded and every other member still
|
|
349
|
+
* belongs to the real instance.
|
|
350
|
+
*
|
|
351
|
+
* A `Proxy` rather than a subclass or a copy: undici's Agent keeps state in
|
|
352
|
+
* private fields and internal symbols, and every forwarded call must run with
|
|
353
|
+
* `this` bound to the REAL instance (hence `Reflect.get(target, prop, target)`
|
|
354
|
+
* and the bind) or those fields are not there. `instanceof` keeps working.
|
|
355
|
+
*/
|
|
356
|
+
export function wrapDispatcher<T extends Dispatcher>(real: T, options: ReporterOptions): T {
|
|
357
|
+
const reporter = createReporter(options);
|
|
358
|
+
const guardedDispatch = (opts: unknown, handler: unknown): unknown => {
|
|
359
|
+
reporter.check(originHost(opts), 'fetch');
|
|
360
|
+
// Both arguments cross UNTOUCHED. Edge hands a v6 handler to the host's
|
|
361
|
+
// v7 Agent, and that handoff only survives by identity.
|
|
362
|
+
return real.dispatch(opts, handler);
|
|
363
|
+
};
|
|
364
|
+
return new Proxy(real, {
|
|
365
|
+
get(target, prop) {
|
|
366
|
+
if (prop === 'dispatch') return guardedDispatch;
|
|
367
|
+
const value = Reflect.get(target, prop, target);
|
|
368
|
+
return typeof value === 'function' ? (value as (...a: unknown[]) => unknown).bind(target) : value;
|
|
369
|
+
},
|
|
370
|
+
}) as T;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// ─── install ───────────────────────────────────────────────────────────────
|
|
374
|
+
|
|
375
|
+
type ConnectFn = (...args: unknown[]) => unknown;
|
|
376
|
+
|
|
377
|
+
/** A `createConnection`-bearing object: an `http.Agent`/`https.Agent`
|
|
378
|
+
* prototype in production, a stand-in under test. */
|
|
379
|
+
type AgentPrototype = { createConnection?: unknown };
|
|
380
|
+
|
|
381
|
+
export interface NetGuardHooks {
|
|
382
|
+
/** Object carrying the undici dispatcher symbol. Defaults to `globalThis`. */
|
|
383
|
+
scope?: Record<symbol, unknown>;
|
|
384
|
+
env?: Record<string, string | undefined>;
|
|
385
|
+
argv?: readonly string[];
|
|
386
|
+
write?: (line: string) => void;
|
|
387
|
+
net?: { connect: ConnectFn; createConnection: ConnectFn };
|
|
388
|
+
tls?: { connect: ConnectFn };
|
|
389
|
+
/** Prototypes whose `createConnection` is patched. Defaults to the
|
|
390
|
+
* `http.Agent` and `https.Agent` prototypes. */
|
|
391
|
+
agentPrototypes?: readonly AgentPrototype[];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface NetGuard {
|
|
395
|
+
readonly mode: GuardMode;
|
|
396
|
+
readonly allow: readonly string[];
|
|
397
|
+
/** Re-wrap the global dispatcher if something replaced it (a future Next
|
|
398
|
+
* calling `setGlobalDispatcher` would otherwise silently unhook us). */
|
|
399
|
+
reassert(): void;
|
|
400
|
+
/** Stop the periodic re-assert. Used by the CLI's own tests. */
|
|
401
|
+
stop(): void;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** `basename(argv[1])`, the cheapest honest attribution available. */
|
|
405
|
+
function contextFrom(argv: readonly string[] | undefined): string | undefined {
|
|
406
|
+
const entry = argv?.[1];
|
|
407
|
+
if (typeof entry !== 'string' || entry.length === 0) return undefined;
|
|
408
|
+
const parts = entry.split(/[\\/]/);
|
|
409
|
+
return parts[parts.length - 1] || undefined;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Materialize undici's lazy global dispatcher without touching the network.
|
|
414
|
+
* `new Headers()` loads Node's undici, whose module body installs a default
|
|
415
|
+
* Agent into the symbol only if the slot is still empty, so this must run
|
|
416
|
+
* before we put anything there. It also loads `_http_agent`, which is why the
|
|
417
|
+
* socket patches go in first.
|
|
418
|
+
*/
|
|
419
|
+
function materializeGlobalDispatcher(): void {
|
|
420
|
+
try {
|
|
421
|
+
new Headers();
|
|
422
|
+
} catch {
|
|
423
|
+
// No WHATWG Headers, or a runtime that never had undici. The socket
|
|
424
|
+
// backstop still applies.
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* The `http.Agent` and `https.Agent` prototypes, or an empty list on a runtime
|
|
430
|
+
* without them. Each carries its own `createConnection`: `http`'s is a copied
|
|
431
|
+
* reference to `net.createConnection` snapshotted at `_http_agent` load time,
|
|
432
|
+
* so patching `net` alone leaves it unguarded whenever `node:http` loaded
|
|
433
|
+
* first.
|
|
434
|
+
*/
|
|
435
|
+
function nodeAgentPrototypes(): AgentPrototype[] {
|
|
436
|
+
const require = createRequire(import.meta.url);
|
|
437
|
+
const prototypes: AgentPrototype[] = [];
|
|
438
|
+
for (const id of ['node:http', 'node:https']) {
|
|
439
|
+
try {
|
|
440
|
+
const mod = require(id) as { Agent?: { prototype?: unknown } };
|
|
441
|
+
const prototype = mod.Agent?.prototype;
|
|
442
|
+
if (typeof prototype === 'object' && prototype !== null) {
|
|
443
|
+
prototypes.push(prototype as AgentPrototype);
|
|
444
|
+
}
|
|
445
|
+
} catch {
|
|
446
|
+
// Runtime without that module: the other seams still apply.
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return prototypes;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Install the guard. Gated on `PYRIC_SANDBOX` exactly like the rest of the
|
|
454
|
+
* register module: without the activator this is a no-op, so the module stays
|
|
455
|
+
* safe to import anywhere. Returns `null` when nothing was installed.
|
|
456
|
+
*/
|
|
457
|
+
export function installNetGuard(hooks: NetGuardHooks = {}): NetGuard | null {
|
|
458
|
+
const env = hooks.env ?? process.env;
|
|
459
|
+
if (!env.PYRIC_SANDBOX) return null;
|
|
460
|
+
|
|
461
|
+
const write = hooks.write ?? ((line: string) => void process.stderr.write(line));
|
|
462
|
+
const mode = parseGuardMode(env.PYRIC_GUARD);
|
|
463
|
+
|
|
464
|
+
if (mode === 'off') {
|
|
465
|
+
write(
|
|
466
|
+
`${LOG_PREFIX} disabled (PYRIC_GUARD=off): egress from this process to live ` +
|
|
467
|
+
`Google/Firebase endpoints is neither reported nor blocked, not even the GCE ` +
|
|
468
|
+
`metadata server (169.254.169.254).\n`,
|
|
469
|
+
);
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const allow = parseAllowHosts(env.PYRIC_GUARD_ALLOW);
|
|
474
|
+
const context = contextFrom(hooks.argv ?? process.argv);
|
|
475
|
+
const reporterOptions: ReporterOptions = { mode, allow, write, context, reported: new Set() };
|
|
476
|
+
|
|
477
|
+
const scope = hooks.scope ?? (globalThis as unknown as Record<symbol, unknown>);
|
|
478
|
+
|
|
479
|
+
// ── socket backstop: http.request, gRPC, DB drivers, raw sockets ──
|
|
480
|
+
//
|
|
481
|
+
// This runs FIRST, before the dispatcher is materialized. Materializing
|
|
482
|
+
// loads undici, which loads `_http_agent`, which snapshots
|
|
483
|
+
// `net.createConnection` onto `http.Agent.prototype.createConnection`. With
|
|
484
|
+
// the order reversed, that snapshot is the unpatched function and every
|
|
485
|
+
// plain `http.request` escapes the guard, the metadata server included.
|
|
486
|
+
const require = createRequire(import.meta.url);
|
|
487
|
+
const netModule =
|
|
488
|
+
hooks.net ?? (require('node:net') as { connect: ConnectFn; createConnection: ConnectFn });
|
|
489
|
+
const tlsModule = hooks.tls ?? (require('node:tls') as { connect: ConnectFn });
|
|
490
|
+
const reporter = createReporter(reporterOptions);
|
|
491
|
+
|
|
492
|
+
const guardConnect = (target: { [k: string]: unknown }, name: string): void => {
|
|
493
|
+
const original = target[name];
|
|
494
|
+
if (typeof original !== 'function') return;
|
|
495
|
+
const wrapped = function (this: unknown, ...args: unknown[]): unknown {
|
|
496
|
+
reporter.check(connectHost(args), 'socket');
|
|
497
|
+
return (original as ConnectFn).apply(this, args);
|
|
498
|
+
};
|
|
499
|
+
target[name] = wrapped;
|
|
500
|
+
};
|
|
501
|
+
guardConnect(netModule as unknown as { [k: string]: unknown }, 'connect');
|
|
502
|
+
guardConnect(netModule as unknown as { [k: string]: unknown }, 'createConnection');
|
|
503
|
+
guardConnect(tlsModule as unknown as { [k: string]: unknown }, 'connect');
|
|
504
|
+
// And the Agent prototypes, so a `node:http` that loaded before this module
|
|
505
|
+
// is still covered. `https.Agent` also reaches the patched `tls.connect`, so
|
|
506
|
+
// its own patch is a second check on the same egress; the once-per-host
|
|
507
|
+
// dedupe keeps that from printing twice.
|
|
508
|
+
for (const prototype of hooks.agentPrototypes ?? nodeAgentPrototypes()) {
|
|
509
|
+
guardConnect(prototype as { [k: string]: unknown }, 'createConnection');
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
let installed: unknown;
|
|
513
|
+
const wrapGlobalDispatcher = (): void => {
|
|
514
|
+
const current = scope[UNDICI_GLOBAL_DISPATCHER];
|
|
515
|
+
if (current === undefined || current === null) return;
|
|
516
|
+
if (current === installed) return;
|
|
517
|
+
if (typeof (current as Dispatcher).dispatch !== 'function') return;
|
|
518
|
+
// PLAIN ASSIGNMENT. undici's own property is
|
|
519
|
+
// `configurable: false, writable: true`; a `defineProperty` that tries to
|
|
520
|
+
// make it configurable throws and takes the process down.
|
|
521
|
+
installed = wrapDispatcher(current as Dispatcher, reporterOptions);
|
|
522
|
+
scope[UNDICI_GLOBAL_DISPATCHER] = installed;
|
|
523
|
+
};
|
|
524
|
+
if (hooks.scope === undefined) materializeGlobalDispatcher();
|
|
525
|
+
wrapGlobalDispatcher();
|
|
526
|
+
|
|
527
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
528
|
+
if (hooks.scope === undefined) {
|
|
529
|
+
timer = setInterval(wrapGlobalDispatcher, REASSERT_INTERVAL_MS);
|
|
530
|
+
// Never hold the event loop open: a guarded child must still exit.
|
|
531
|
+
timer.unref?.();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return {
|
|
535
|
+
mode,
|
|
536
|
+
allow,
|
|
537
|
+
reassert: wrapGlobalDispatcher,
|
|
538
|
+
stop(): void {
|
|
539
|
+
if (timer !== undefined) clearInterval(timer);
|
|
540
|
+
},
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Extract the destination host from `net.connect` / `tls.connect` arguments,
|
|
546
|
+
* across all of their overloads: `(options[, cb])`, `(port[, host][, cb])`,
|
|
547
|
+
* `(path[, cb])`. An IPC path or a portless local socket has no host, which is
|
|
548
|
+
* exactly the "nothing to say" answer.
|
|
549
|
+
*/
|
|
550
|
+
function connectHost(args: readonly unknown[]): string | undefined {
|
|
551
|
+
const first = args[0];
|
|
552
|
+
if (typeof first === 'object' && first !== null) {
|
|
553
|
+
const host = (first as { host?: unknown; hostname?: unknown }).host ??
|
|
554
|
+
(first as { hostname?: unknown }).hostname;
|
|
555
|
+
return typeof host === 'string' ? host : undefined;
|
|
556
|
+
}
|
|
557
|
+
if (typeof first === 'number' || (typeof first === 'string' && /^\d+$/.test(first))) {
|
|
558
|
+
// (port, host?, ...): the host, when given, is the next string argument.
|
|
559
|
+
const second = args[1];
|
|
560
|
+
if (typeof second === 'string') return second;
|
|
561
|
+
if (typeof second === 'object' && second !== null) {
|
|
562
|
+
const host = (second as { host?: unknown }).host;
|
|
563
|
+
return typeof host === 'string' ? host : undefined;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return undefined;
|
|
567
|
+
}
|