@agent-native/core 0.96.0 → 0.97.0
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 +6 -0
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +39 -0
- package/corpus/core/docs/content/audit-log.mdx +2 -1
- package/corpus/core/docs/content/automations.mdx +7 -7
- package/corpus/core/docs/content/creating-templates.mdx +1 -1
- package/corpus/core/docs/content/internationalization.mdx +2 -1
- package/corpus/core/docs/content/locales/ar-SA/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/ar-SA/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/ar-SA/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/ar-SA/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/ar-SA/package-lifecycle.mdx +19 -0
- package/corpus/core/docs/content/locales/ar-SA/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/ar-SA/security.mdx +8 -0
- package/corpus/core/docs/content/locales/de-DE/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/de-DE/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/de-DE/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/de-DE/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/de-DE/package-lifecycle.mdx +22 -0
- package/corpus/core/docs/content/locales/de-DE/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/de-DE/security.mdx +8 -0
- package/corpus/core/docs/content/locales/es-ES/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/es-ES/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/es-ES/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/es-ES/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/es-ES/package-lifecycle.mdx +22 -0
- package/corpus/core/docs/content/locales/es-ES/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/es-ES/security.mdx +8 -0
- package/corpus/core/docs/content/locales/fr-FR/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/fr-FR/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/fr-FR/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/fr-FR/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/fr-FR/package-lifecycle.mdx +21 -0
- package/corpus/core/docs/content/locales/fr-FR/sandbox-adapters.mdx +19 -8
- package/corpus/core/docs/content/locales/fr-FR/security.mdx +8 -0
- package/corpus/core/docs/content/locales/hi-IN/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/hi-IN/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/hi-IN/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/hi-IN/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/hi-IN/package-lifecycle.mdx +20 -0
- package/corpus/core/docs/content/locales/hi-IN/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/hi-IN/security.mdx +8 -0
- package/corpus/core/docs/content/locales/ja-JP/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/ja-JP/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/ja-JP/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/ja-JP/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/ja-JP/package-lifecycle.mdx +21 -0
- package/corpus/core/docs/content/locales/ja-JP/sandbox-adapters.mdx +17 -6
- package/corpus/core/docs/content/locales/ja-JP/security.mdx +8 -0
- package/corpus/core/docs/content/locales/ko-KR/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/ko-KR/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/ko-KR/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/ko-KR/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/ko-KR/package-lifecycle.mdx +20 -0
- package/corpus/core/docs/content/locales/ko-KR/sandbox-adapters.mdx +17 -6
- package/corpus/core/docs/content/locales/ko-KR/security.mdx +8 -0
- package/corpus/core/docs/content/locales/pt-BR/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/pt-BR/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/pt-BR/getting-started.mdx +7 -1
- package/corpus/core/docs/content/locales/pt-BR/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/pt-BR/package-lifecycle.mdx +21 -0
- package/corpus/core/docs/content/locales/pt-BR/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/pt-BR/security.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-CN/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/zh-CN/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/zh-CN/getting-started.mdx +6 -4
- package/corpus/core/docs/content/locales/zh-CN/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/zh-CN/package-lifecycle.mdx +19 -0
- package/corpus/core/docs/content/locales/zh-CN/sandbox-adapters.mdx +17 -6
- package/corpus/core/docs/content/locales/zh-CN/security.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-TW/audit-log.mdx +2 -1
- package/corpus/core/docs/content/locales/zh-TW/automations.mdx +7 -7
- package/corpus/core/docs/content/locales/zh-TW/getting-started.mdx +6 -4
- package/corpus/core/docs/content/locales/zh-TW/internationalization.mdx +1 -1
- package/corpus/core/docs/content/locales/zh-TW/package-lifecycle.mdx +19 -0
- package/corpus/core/docs/content/locales/zh-TW/sandbox-adapters.mdx +18 -7
- package/corpus/core/docs/content/locales/zh-TW/security.mdx +8 -0
- package/corpus/core/docs/content/package-lifecycle.mdx +51 -0
- package/corpus/core/docs/content/sandbox-adapters.mdx +16 -5
- package/corpus/core/package.json +9 -2
- package/corpus/core/src/a2a/auth-policy.ts +33 -0
- package/corpus/core/src/agent/durable-background.ts +15 -7
- package/corpus/core/src/agent/run-store.ts +13 -4
- package/corpus/core/src/audit/actions/export-audit-events.ts +162 -0
- package/corpus/core/src/audit/store.ts +8 -3
- package/corpus/core/src/audit/types.ts +3 -0
- package/corpus/core/src/cli/doctor.ts +396 -0
- package/corpus/core/src/cli/index.ts +56 -0
- package/corpus/core/src/cli/info.ts +3 -3
- package/corpus/core/src/cli/package-lifecycle.ts +821 -0
- package/corpus/core/src/client/agent-chat-adapter.ts +9 -9
- package/corpus/core/src/guards/db-tool-scoping.ts +129 -0
- package/corpus/core/src/guards/index.ts +23 -0
- package/corpus/core/src/guards/no-drizzle-push.ts +116 -0
- package/corpus/core/src/guards/no-env-credentials.ts +229 -0
- package/corpus/core/src/guards/no-env-mutation.ts +114 -0
- package/corpus/core/src/guards/no-localhost-fallback.ts +124 -0
- package/corpus/core/src/guards/no-unscoped-credentials.ts +227 -0
- package/corpus/core/src/guards/no-unscoped-queries.ts +834 -0
- package/corpus/core/src/guards/scan-utils.ts +105 -0
- package/corpus/core/src/guards/types.ts +30 -0
- package/corpus/core/src/org/accept-pending.ts +9 -1
- package/corpus/core/src/org/migrations.ts +41 -0
- package/corpus/core/src/package-lifecycle/index.ts +1 -0
- package/corpus/core/src/package-lifecycle/manifest.ts +120 -0
- package/corpus/core/src/provider-api/custom-registry.ts +56 -0
- package/corpus/core/src/provider-api/index.ts +2 -0
- package/corpus/core/src/secrets/storage.ts +47 -27
- package/corpus/core/src/server/action-discovery.ts +4 -0
- package/corpus/core/src/server/agent-chat-plugin.ts +54 -12
- package/corpus/core/src/server/core-routes-plugin.ts +30 -14
- package/corpus/core/src/server/csrf.ts +24 -5
- package/corpus/core/src/server/framework-request-handler.ts +34 -0
- package/corpus/core/src/server/google-realtime-session.ts +1 -36
- package/corpus/core/src/server/poll.ts +24 -2
- package/corpus/core/src/server/realtime-voice.ts +9 -0
- package/corpus/core/src/server/request-origin.ts +63 -0
- package/corpus/core/src/server/transcribe-voice.ts +1 -50
- package/corpus/core/src/templates/default/package.json +2 -2
- package/corpus/core/src/templates/headless/package.json +0 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/audit-log/SKILL.md +3 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/automations/SKILL.md +1 -1
- package/corpus/core/src/templates/workspace-core/package.json +0 -1
- package/corpus/core/src/templates/workspace-root/package.json +0 -1
- package/corpus/core/src/triggers/actions.ts +11 -3
- package/corpus/core/src/triggers/types.ts +7 -1
- package/corpus/templates/analytics/actions/compose-dashboard.ts +65 -37
- package/corpus/templates/analytics/actions/mutate-dashboard.ts +73 -24
- package/corpus/templates/analytics/actions/reorder-dashboard-panels.ts +16 -13
- package/corpus/templates/analytics/actions/update-dashboard.ts +53 -42
- package/corpus/templates/analytics/changelog/2026-07-10-dashboard-edits-from-the-agent-and-the-ui-at-the-same-time-n.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-10-timed-out-bigquery-jobs-are-now-cancelled-so-they-stop-consu.md +6 -0
- package/corpus/templates/analytics/package.json +1 -2
- package/corpus/templates/analytics/server/lib/bigquery.ts +3 -2
- package/corpus/templates/analytics/server/lib/dashboards-store.ts +154 -11
- package/corpus/templates/assets/package.json +1 -2
- package/corpus/templates/brain/package.json +1 -2
- package/corpus/templates/calendar/package.json +1 -2
- package/corpus/templates/chat/package.json +1 -2
- package/corpus/templates/clips/changelog/2026-07-10-atomic-view-tracking.md +6 -0
- package/corpus/templates/clips/chrome-extension/package.json +3 -2
- package/corpus/templates/clips/desktop/package.json +6 -4
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +26 -13
- package/corpus/templates/clips/desktop/src/lib/voice-dictation.ts +4 -1
- package/corpus/templates/clips/package.json +1 -2
- package/corpus/templates/clips/server/db/schema.ts +29 -17
- package/corpus/templates/clips/server/plugins/db.ts +8 -0
- package/corpus/templates/clips/server/routes/api/view-event.post.ts +260 -105
- package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +16 -0
- package/corpus/templates/content/AGENTS.md +72 -62
- package/corpus/templates/content/actions/_content-database-source-adapters.ts +84 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +206 -96
- package/corpus/templates/content/actions/_notion-database-source-adapter.ts +216 -0
- package/corpus/templates/content/actions/_position-utils.ts +76 -0
- package/corpus/templates/content/actions/_property-utils.ts +31 -20
- package/corpus/templates/content/actions/add-database-item.ts +52 -39
- package/corpus/templates/content/actions/attach-content-database-source.ts +95 -11
- package/corpus/templates/content/actions/change-content-database-source-role.ts +24 -1
- package/corpus/templates/content/actions/configure-document-property.ts +36 -27
- package/corpus/templates/content/actions/create-content-database.ts +40 -30
- package/corpus/templates/content/actions/create-document.ts +39 -32
- package/corpus/templates/content/actions/duplicate-document-property.ts +37 -28
- package/corpus/templates/content/actions/list-notion-database-sources.ts +80 -0
- package/corpus/templates/content/actions/move-document.ts +64 -48
- package/corpus/templates/content/actions/refresh-content-database-source.ts +42 -3
- package/corpus/templates/content/actions/share-local-file-document.ts +36 -27
- package/corpus/templates/content/actions/suggest-source-join-key.ts +39 -16
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +89 -23
- package/corpus/templates/content/app/components/editor/database/settings.tsx +1 -1
- package/corpus/templates/content/app/hooks/use-content-database.ts +18 -1
- package/corpus/templates/content/app/i18n/zh-TW.ts +4 -0
- package/corpus/templates/content/app/i18n-data.ts +40 -0
- package/corpus/templates/content/changelog/2026-07-10-failed-row-creation-and-source-attach-now-show-an-error-inst.md +6 -0
- package/corpus/templates/content/changelog/2026-07-10-items-added-at-the-same-time-no-longer-end-up-with-identical.md +6 -0
- package/corpus/templates/content/changelog/2026-07-10-notion-databases-can-add-read-only-details-to-content-tables.md +6 -0
- package/corpus/templates/content/package.json +1 -2
- package/corpus/templates/content/parity/matrix.md +25 -25
- package/corpus/templates/content/parity/matrix.ts +1 -0
- package/corpus/templates/content/server/routes/api/documents/[id]/move.patch.ts +43 -26
- package/corpus/templates/content/shared/api.ts +16 -1
- package/corpus/templates/design/.agents/skills/visual-edit/SKILL.md +8 -4
- package/corpus/templates/design/AGENTS.md +12 -2
- package/corpus/templates/design/DEVELOPING.md +10 -6
- package/corpus/templates/design/actions/apply-visual-edit.ts +191 -6
- package/corpus/templates/design/actions/duplicate-design.ts +31 -25
- package/corpus/templates/design/app/pages/design-editor/pending-edits.ts +5 -1
- package/corpus/templates/design/changelog/2026-07-10-duplicating-a-design-can-no-longer-produce-a-copy-with-missi.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-local-visual-edits-can-now-save-safe-leaf-text-class-and.md +6 -0
- package/corpus/templates/design/package.json +1 -1
- package/corpus/templates/design/shared/local-jsx-visual-edit.ts +388 -0
- package/corpus/templates/dispatch/package.json +1 -2
- package/corpus/templates/forms/actions/patch-form-fields.ts +82 -44
- package/corpus/templates/forms/changelog/2026-07-10-simultaneous-edits-to-different-form-fields-no-longer-overwr.md +6 -0
- package/corpus/templates/forms/package.json +1 -2
- package/corpus/templates/macros/package.json +1 -2
- package/corpus/templates/mail/app/components/email/EmailThread.tsx +3 -1
- package/corpus/templates/mail/changelog/2026-07-10-fixed-calendar-rsvp-buttons-in-emails-firing-duplicate-respo.md +6 -0
- package/corpus/templates/mail/package.json +1 -2
- package/corpus/templates/plan/actions/restore-plan-version.ts +126 -96
- package/corpus/templates/plan/changelog/2026-07-10-restoring-a-plan-version-can-no-longer-leave-a-plan-half-res.md +6 -0
- package/corpus/templates/plan/package.json +1 -2
- package/corpus/templates/plan/server/plans.ts +9 -2
- package/corpus/templates/slides/actions/list-decks.ts +28 -0
- package/corpus/templates/slides/app/components/deck/MermaidRenderer.tsx +41 -26
- package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +4 -8
- package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +2 -4
- package/corpus/templates/slides/app/components/editor/EditorToolbar.tsx +4 -8
- package/corpus/templates/slides/app/components/editor/ExportMenu.tsx +5 -12
- package/corpus/templates/slides/app/components/editor/HistoryPanel.tsx +3 -6
- package/corpus/templates/slides/app/components/editor/ImageDropPromptPopover.tsx +3 -6
- package/corpus/templates/slides/app/components/editor/PromptDialog.tsx +2 -5
- package/corpus/templates/slides/app/context/DeckContext.tsx +47 -4
- package/corpus/templates/slides/app/pages/DeckEditor.tsx +11 -30
- package/corpus/templates/slides/app/pages/Index.tsx +2 -3
- package/corpus/templates/slides/app/root.tsx +0 -5
- package/corpus/templates/slides/changelog/2026-07-10-deck-lists-load-much-faster-and-no-longer-re-download-slide-.md +6 -0
- package/corpus/templates/slides/package.json +1 -2
- package/dist/a2a/auth-policy.d.ts +19 -0
- package/dist/a2a/auth-policy.d.ts.map +1 -1
- package/dist/a2a/auth-policy.js +32 -0
- package/dist/a2a/auth-policy.js.map +1 -1
- package/dist/agent/durable-background.d.ts +8 -5
- package/dist/agent/durable-background.d.ts.map +1 -1
- package/dist/agent/durable-background.js +15 -8
- package/dist/agent/durable-background.js.map +1 -1
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +9 -4
- package/dist/agent/run-store.js.map +1 -1
- package/dist/audit/actions/export-audit-events.d.ts +27 -0
- package/dist/audit/actions/export-audit-events.d.ts.map +1 -0
- package/dist/audit/actions/export-audit-events.js +144 -0
- package/dist/audit/actions/export-audit-events.js.map +1 -0
- package/dist/audit/store.d.ts +1 -0
- package/dist/audit/store.d.ts.map +1 -1
- package/dist/audit/store.js +8 -3
- package/dist/audit/store.js.map +1 -1
- package/dist/audit/types.d.ts +3 -0
- package/dist/audit/types.d.ts.map +1 -1
- package/dist/audit/types.js.map +1 -1
- package/dist/cli/doctor.d.ts +83 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +277 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/index.js +50 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/info.js +3 -3
- package/dist/cli/info.js.map +1 -1
- package/dist/cli/package-lifecycle.d.ts +50 -0
- package/dist/cli/package-lifecycle.d.ts.map +1 -0
- package/dist/cli/package-lifecycle.js +560 -0
- package/dist/cli/package-lifecycle.js.map +1 -0
- package/dist/client/agent-chat-adapter.js +7 -3
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/guards/db-tool-scoping.d.ts +38 -0
- package/dist/guards/db-tool-scoping.d.ts.map +1 -0
- package/dist/guards/db-tool-scoping.js +114 -0
- package/dist/guards/db-tool-scoping.js.map +1 -0
- package/dist/guards/index.d.ts +23 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +19 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/no-drizzle-push.d.ts +14 -0
- package/dist/guards/no-drizzle-push.d.ts.map +1 -0
- package/dist/guards/no-drizzle-push.js +97 -0
- package/dist/guards/no-drizzle-push.js.map +1 -0
- package/dist/guards/no-env-credentials.d.ts +36 -0
- package/dist/guards/no-env-credentials.d.ts.map +1 -0
- package/dist/guards/no-env-credentials.js +204 -0
- package/dist/guards/no-env-credentials.js.map +1 -0
- package/dist/guards/no-env-mutation.d.ts +23 -0
- package/dist/guards/no-env-mutation.d.ts.map +1 -0
- package/dist/guards/no-env-mutation.js +90 -0
- package/dist/guards/no-env-mutation.js.map +1 -0
- package/dist/guards/no-localhost-fallback.d.ts +30 -0
- package/dist/guards/no-localhost-fallback.d.ts.map +1 -0
- package/dist/guards/no-localhost-fallback.js +105 -0
- package/dist/guards/no-localhost-fallback.js.map +1 -0
- package/dist/guards/no-unscoped-credentials.d.ts +28 -0
- package/dist/guards/no-unscoped-credentials.d.ts.map +1 -0
- package/dist/guards/no-unscoped-credentials.js +199 -0
- package/dist/guards/no-unscoped-credentials.js.map +1 -0
- package/dist/guards/no-unscoped-queries.d.ts +32 -0
- package/dist/guards/no-unscoped-queries.d.ts.map +1 -0
- package/dist/guards/no-unscoped-queries.js +720 -0
- package/dist/guards/no-unscoped-queries.js.map +1 -0
- package/dist/guards/scan-utils.d.ts +28 -0
- package/dist/guards/scan-utils.d.ts.map +1 -0
- package/dist/guards/scan-utils.js +92 -0
- package/dist/guards/scan-utils.js.map +1 -0
- package/dist/guards/types.d.ts +28 -0
- package/dist/guards/types.d.ts.map +1 -0
- package/dist/guards/types.js +11 -0
- package/dist/guards/types.js.map +1 -0
- package/dist/org/accept-pending.d.ts.map +1 -1
- package/dist/org/accept-pending.js +9 -1
- package/dist/org/accept-pending.js.map +1 -1
- package/dist/org/migrations.d.ts +7 -2
- package/dist/org/migrations.d.ts.map +1 -1
- package/dist/org/migrations.js +41 -0
- package/dist/org/migrations.js.map +1 -1
- package/dist/package-lifecycle/index.d.ts +2 -0
- package/dist/package-lifecycle/index.d.ts.map +1 -0
- package/dist/package-lifecycle/index.js +2 -0
- package/dist/package-lifecycle/index.js.map +1 -0
- package/dist/package-lifecycle/manifest.d.ts +24 -0
- package/dist/package-lifecycle/manifest.d.ts.map +1 -0
- package/dist/package-lifecycle/manifest.js +81 -0
- package/dist/package-lifecycle/manifest.js.map +1 -0
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/custom-registry.d.ts +32 -1
- package/dist/provider-api/custom-registry.d.ts.map +1 -1
- package/dist/provider-api/custom-registry.js +41 -1
- package/dist/provider-api/custom-registry.js.map +1 -1
- package/dist/provider-api/index.d.ts +1 -1
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +1 -1
- package/dist/provider-api/index.js.map +1 -1
- package/dist/secrets/storage.d.ts.map +1 -1
- package/dist/secrets/storage.js +45 -27
- package/dist/secrets/storage.js.map +1 -1
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +4 -0
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +47 -13
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +23 -12
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/csrf.d.ts.map +1 -1
- package/dist/server/csrf.js +18 -5
- package/dist/server/csrf.js.map +1 -1
- package/dist/server/framework-request-handler.d.ts.map +1 -1
- package/dist/server/framework-request-handler.js +34 -0
- package/dist/server/framework-request-handler.js.map +1 -1
- package/dist/server/google-realtime-session.d.ts.map +1 -1
- package/dist/server/google-realtime-session.js +2 -34
- package/dist/server/google-realtime-session.js.map +1 -1
- package/dist/server/poll.d.ts.map +1 -1
- package/dist/server/poll.js +24 -2
- package/dist/server/poll.js.map +1 -1
- package/dist/server/realtime-voice.d.ts.map +1 -1
- package/dist/server/realtime-voice.js +9 -0
- package/dist/server/realtime-voice.js.map +1 -1
- package/dist/server/request-origin.d.ts +10 -0
- package/dist/server/request-origin.d.ts.map +1 -0
- package/dist/server/request-origin.js +60 -0
- package/dist/server/request-origin.js.map +1 -0
- package/dist/server/transcribe-voice.d.ts.map +1 -1
- package/dist/server/transcribe-voice.js +2 -48
- package/dist/server/transcribe-voice.js.map +1 -1
- package/dist/templates/default/package.json +2 -2
- package/dist/templates/headless/package.json +0 -1
- package/dist/templates/workspace-core/.agents/skills/audit-log/SKILL.md +3 -0
- package/dist/templates/workspace-core/.agents/skills/automations/SKILL.md +1 -1
- package/dist/templates/workspace-core/package.json +0 -1
- package/dist/templates/workspace-root/package.json +0 -1
- package/dist/triggers/actions.d.ts.map +1 -1
- package/dist/triggers/actions.js +8 -3
- package/dist/triggers/actions.js.map +1 -1
- package/dist/triggers/types.d.ts +7 -1
- package/dist/triggers/types.d.ts.map +1 -1
- package/dist/triggers/types.js.map +1 -1
- package/docs/content/audit-log.mdx +2 -1
- package/docs/content/automations.mdx +7 -7
- package/docs/content/creating-templates.mdx +1 -1
- package/docs/content/internationalization.mdx +2 -1
- package/docs/content/locales/ar-SA/audit-log.mdx +2 -1
- package/docs/content/locales/ar-SA/automations.mdx +7 -7
- package/docs/content/locales/ar-SA/getting-started.mdx +7 -1
- package/docs/content/locales/ar-SA/internationalization.mdx +1 -1
- package/docs/content/locales/ar-SA/package-lifecycle.mdx +19 -0
- package/docs/content/locales/ar-SA/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/ar-SA/security.mdx +8 -0
- package/docs/content/locales/de-DE/audit-log.mdx +2 -1
- package/docs/content/locales/de-DE/automations.mdx +7 -7
- package/docs/content/locales/de-DE/getting-started.mdx +7 -1
- package/docs/content/locales/de-DE/internationalization.mdx +1 -1
- package/docs/content/locales/de-DE/package-lifecycle.mdx +22 -0
- package/docs/content/locales/de-DE/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/de-DE/security.mdx +8 -0
- package/docs/content/locales/es-ES/audit-log.mdx +2 -1
- package/docs/content/locales/es-ES/automations.mdx +7 -7
- package/docs/content/locales/es-ES/getting-started.mdx +7 -1
- package/docs/content/locales/es-ES/internationalization.mdx +1 -1
- package/docs/content/locales/es-ES/package-lifecycle.mdx +22 -0
- package/docs/content/locales/es-ES/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/es-ES/security.mdx +8 -0
- package/docs/content/locales/fr-FR/audit-log.mdx +2 -1
- package/docs/content/locales/fr-FR/automations.mdx +7 -7
- package/docs/content/locales/fr-FR/getting-started.mdx +7 -1
- package/docs/content/locales/fr-FR/internationalization.mdx +1 -1
- package/docs/content/locales/fr-FR/package-lifecycle.mdx +21 -0
- package/docs/content/locales/fr-FR/sandbox-adapters.mdx +19 -8
- package/docs/content/locales/fr-FR/security.mdx +8 -0
- package/docs/content/locales/hi-IN/audit-log.mdx +2 -1
- package/docs/content/locales/hi-IN/automations.mdx +7 -7
- package/docs/content/locales/hi-IN/getting-started.mdx +7 -1
- package/docs/content/locales/hi-IN/internationalization.mdx +1 -1
- package/docs/content/locales/hi-IN/package-lifecycle.mdx +20 -0
- package/docs/content/locales/hi-IN/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/hi-IN/security.mdx +8 -0
- package/docs/content/locales/ja-JP/audit-log.mdx +2 -1
- package/docs/content/locales/ja-JP/automations.mdx +7 -7
- package/docs/content/locales/ja-JP/getting-started.mdx +7 -1
- package/docs/content/locales/ja-JP/internationalization.mdx +1 -1
- package/docs/content/locales/ja-JP/package-lifecycle.mdx +21 -0
- package/docs/content/locales/ja-JP/sandbox-adapters.mdx +17 -6
- package/docs/content/locales/ja-JP/security.mdx +8 -0
- package/docs/content/locales/ko-KR/audit-log.mdx +2 -1
- package/docs/content/locales/ko-KR/automations.mdx +7 -7
- package/docs/content/locales/ko-KR/getting-started.mdx +7 -1
- package/docs/content/locales/ko-KR/internationalization.mdx +1 -1
- package/docs/content/locales/ko-KR/package-lifecycle.mdx +20 -0
- package/docs/content/locales/ko-KR/sandbox-adapters.mdx +17 -6
- package/docs/content/locales/ko-KR/security.mdx +8 -0
- package/docs/content/locales/pt-BR/audit-log.mdx +2 -1
- package/docs/content/locales/pt-BR/automations.mdx +7 -7
- package/docs/content/locales/pt-BR/getting-started.mdx +7 -1
- package/docs/content/locales/pt-BR/internationalization.mdx +1 -1
- package/docs/content/locales/pt-BR/package-lifecycle.mdx +21 -0
- package/docs/content/locales/pt-BR/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/pt-BR/security.mdx +8 -0
- package/docs/content/locales/zh-CN/audit-log.mdx +2 -1
- package/docs/content/locales/zh-CN/automations.mdx +7 -7
- package/docs/content/locales/zh-CN/getting-started.mdx +6 -4
- package/docs/content/locales/zh-CN/internationalization.mdx +1 -1
- package/docs/content/locales/zh-CN/package-lifecycle.mdx +19 -0
- package/docs/content/locales/zh-CN/sandbox-adapters.mdx +17 -6
- package/docs/content/locales/zh-CN/security.mdx +8 -0
- package/docs/content/locales/zh-TW/audit-log.mdx +2 -1
- package/docs/content/locales/zh-TW/automations.mdx +7 -7
- package/docs/content/locales/zh-TW/getting-started.mdx +6 -4
- package/docs/content/locales/zh-TW/internationalization.mdx +1 -1
- package/docs/content/locales/zh-TW/package-lifecycle.mdx +19 -0
- package/docs/content/locales/zh-TW/sandbox-adapters.mdx +18 -7
- package/docs/content/locales/zh-TW/security.mdx +8 -0
- package/docs/content/package-lifecycle.mdx +51 -0
- package/docs/content/sandbox-adapters.mdx +16 -5
- package/package.json +10 -3
- package/src/templates/default/package.json +2 -2
- package/src/templates/headless/package.json +0 -1
- package/src/templates/workspace-core/.agents/skills/audit-log/SKILL.md +3 -0
- package/src/templates/workspace-core/.agents/skills/automations/SKILL.md +1 -1
- package/src/templates/workspace-core/package.json +0 -1
- package/src/templates/workspace-root/package.json +0 -1
- package/corpus/templates/slides/app/components/ui/toast.tsx +0 -1
- package/corpus/templates/slides/app/components/ui/toaster.tsx +0 -1
- package/corpus/templates/slides/app/hooks/use-toast.ts +0 -1
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scanUnscopedQueries — ported from `scripts/guard-no-unscoped-queries.mjs`.
|
|
3
|
+
*
|
|
4
|
+
* Refuse to let any code query an "ownable" resource table (one that
|
|
5
|
+
* spreads `...ownableColumns()`) without going through framework access
|
|
6
|
+
* control: `accessFilter` / `resolveAccess` / `assertAccess`, or an
|
|
7
|
+
* explicit `ownerEmail` / `userEmail` / `orgId` filter. The check is
|
|
8
|
+
* per-STATEMENT, scoped to the enclosing block, so a sibling `if` branch
|
|
9
|
+
* that correctly scopes its query does not defuse an unscoped sibling.
|
|
10
|
+
*
|
|
11
|
+
* Conditional guard — per report 005's V1 guard set table: the original
|
|
12
|
+
* restricts scanning to `templates/[^/]+/(server|actions)/` and
|
|
13
|
+
* `packages/[^/]+/src/`, and hardcodes a `FILE_ALLOWLIST` of this
|
|
14
|
+
* framework's own sharing-primitive implementation files. For a generated
|
|
15
|
+
* app (no `templates/`/`packages/` wrapper — source lives at `actions/`
|
|
16
|
+
* and `server/` under the app root), this port scans `actions/` and
|
|
17
|
+
* `server/` directly and drops the hardcoded allowlist in favor of an
|
|
18
|
+
* optional `extraExemptPaths` param (default `[]`).
|
|
19
|
+
*
|
|
20
|
+
* Opt-out (within the enclosing block, or as a file header for whole-file
|
|
21
|
+
* opt-outs):
|
|
22
|
+
* // guard:allow-unscoped — short reason
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { readFileSafe, relPosix, walk } from "./scan-utils.js";
|
|
26
|
+
import type { GuardFinding, GuardResult, GuardScanOptions } from "./types.js";
|
|
27
|
+
|
|
28
|
+
export interface UnscopedQueriesOptions extends GuardScanOptions {
|
|
29
|
+
/** Exact repo-relative paths to exempt from the per-statement scan
|
|
30
|
+
* (e.g. this app's own sharing-primitive implementation, if any).
|
|
31
|
+
* Default `[]`. */
|
|
32
|
+
extraExemptPaths?: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ACCESS_CONTROL_HELPERS = [
|
|
36
|
+
/\baccessFilter\s*\(/,
|
|
37
|
+
/\bresolveAccess\s*\(/,
|
|
38
|
+
/\bassertAccess\s*\(/,
|
|
39
|
+
/\bgetShareableResource\s*\(/,
|
|
40
|
+
/\baccessFilterForShares\s*\(/,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const EXPLICIT_OWNER_FILTERS = [
|
|
44
|
+
/\.\s*ownerEmail\b\s*[,)]/,
|
|
45
|
+
/\.\s*userEmail\b\s*[,)]/,
|
|
46
|
+
/\.\s*orgId\b\s*[,)]/,
|
|
47
|
+
/WHERE[\s\S]*?\bowner_email\b/i,
|
|
48
|
+
/WHERE[\s\S]*?\buser_email\b/i,
|
|
49
|
+
/WHERE[\s\S]*?\borg_id\b/i,
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const INSERT_OWNER_PATTERNS = [
|
|
53
|
+
/\bownerEmail\s*:/,
|
|
54
|
+
/\bownerEmail\s*[,}]/,
|
|
55
|
+
/\buserEmail\s*[:,}]/,
|
|
56
|
+
/\borgId\s*[:,}]/,
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const OPT_OUT_MARKER = /\/\/\s*guard:allow-unscoped\b/;
|
|
60
|
+
|
|
61
|
+
const BLOCK_OWNERSHIP_SIGNALS = [
|
|
62
|
+
/\bgetRequestUserEmail\s*\(/,
|
|
63
|
+
/\bgetRequestOrgId\s*\(/,
|
|
64
|
+
/\bgetCurrentUserEmail\s*\(/,
|
|
65
|
+
/\bgetCurrentOwnerEmail\s*\(/,
|
|
66
|
+
/\brunWithRequestContext\s*\(/,
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
interface TableCall {
|
|
70
|
+
exportName: string;
|
|
71
|
+
sqlName: string;
|
|
72
|
+
body: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function extractTableCalls(contents: string): TableCall[] {
|
|
76
|
+
const out: TableCall[] = [];
|
|
77
|
+
const headerRegex =
|
|
78
|
+
/export\s+const\s+([a-zA-Z_$][\w$]*)\s*=\s*(?:[a-zA-Z_$][\w$]*Table|table)\s*\(\s*"([^"]+)"\s*,\s*\{/gm;
|
|
79
|
+
let m: RegExpExecArray | null;
|
|
80
|
+
while ((m = headerRegex.exec(contents)) !== null) {
|
|
81
|
+
const exportName = m[1];
|
|
82
|
+
const sqlName = m[2];
|
|
83
|
+
const start = headerRegex.lastIndex - 1;
|
|
84
|
+
let depth = 0;
|
|
85
|
+
let inStr: string | null = null;
|
|
86
|
+
let i = start;
|
|
87
|
+
let bodyEnd = -1;
|
|
88
|
+
for (; i < contents.length; i++) {
|
|
89
|
+
const c = contents[i];
|
|
90
|
+
const prev = contents[i - 1];
|
|
91
|
+
if (inStr) {
|
|
92
|
+
if (c === inStr && prev !== "\\") inStr = null;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
96
|
+
inStr = c;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (c === "{") depth++;
|
|
100
|
+
else if (c === "}") {
|
|
101
|
+
depth--;
|
|
102
|
+
if (depth === 0) {
|
|
103
|
+
bodyEnd = i;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (bodyEnd === -1) continue;
|
|
109
|
+
const body = contents.slice(start + 1, bodyEnd);
|
|
110
|
+
out.push({ exportName, sqlName, body });
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extractOwnableExports(contents: string): Set<string> {
|
|
116
|
+
const exports = new Set<string>();
|
|
117
|
+
for (const { exportName, sqlName, body } of extractTableCalls(contents)) {
|
|
118
|
+
if (/\.\.\.ownableColumns\s*\(/.test(body)) {
|
|
119
|
+
exports.add(exportName);
|
|
120
|
+
exports.add(`__sql__${sqlName}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return exports;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function collectOwnableTables(root: string): Map<string, Set<string>> {
|
|
127
|
+
const byDir = new Map<string, Set<string>>();
|
|
128
|
+
for (const file of walk(root)) {
|
|
129
|
+
if (!file.endsWith("/db/schema.ts")) continue;
|
|
130
|
+
const contents = readFileSafe(file);
|
|
131
|
+
if (contents === null || !/ownableColumns\s*\(/.test(contents)) continue;
|
|
132
|
+
const ownables = extractOwnableExports(contents);
|
|
133
|
+
if (ownables.size > 0) {
|
|
134
|
+
byDir.set(relPosix(root, file), ownables);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return byDir;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface Block {
|
|
141
|
+
open: number;
|
|
142
|
+
close: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function buildBlockTree(contents: string): Block[] {
|
|
146
|
+
const blocks: Block[] = [];
|
|
147
|
+
const stack: number[] = [];
|
|
148
|
+
let i = 0;
|
|
149
|
+
const n = contents.length;
|
|
150
|
+
let inStr: string | null = null;
|
|
151
|
+
const templateStack: string[] = [];
|
|
152
|
+
|
|
153
|
+
while (i < n) {
|
|
154
|
+
const c = contents[i];
|
|
155
|
+
const next = contents[i + 1];
|
|
156
|
+
|
|
157
|
+
if (inStr) {
|
|
158
|
+
if (c === "\\") {
|
|
159
|
+
i += 2;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (inStr === "`") {
|
|
163
|
+
if (c === "`") {
|
|
164
|
+
inStr = null;
|
|
165
|
+
i++;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (c === "$" && next === "{") {
|
|
169
|
+
templateStack.push("`");
|
|
170
|
+
inStr = null;
|
|
171
|
+
stack.push(-1 - templateStack.length);
|
|
172
|
+
i += 2;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
} else if (c === inStr) {
|
|
176
|
+
inStr = null;
|
|
177
|
+
i++;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
i++;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (c === "/" && next === "/") {
|
|
185
|
+
while (i < n && contents[i] !== "\n") i++;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (c === "/" && next === "*") {
|
|
189
|
+
i += 2;
|
|
190
|
+
while (i < n - 1 && !(contents[i] === "*" && contents[i + 1] === "/"))
|
|
191
|
+
i++;
|
|
192
|
+
i += 2;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
197
|
+
inStr = c;
|
|
198
|
+
i++;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (c === "{") {
|
|
203
|
+
stack.push(i);
|
|
204
|
+
i++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (c === "}") {
|
|
208
|
+
const open = stack.pop();
|
|
209
|
+
if (open !== undefined && open >= 0) {
|
|
210
|
+
blocks.push({ open, close: i });
|
|
211
|
+
} else if (open !== undefined && open < 0) {
|
|
212
|
+
const kind = templateStack.pop();
|
|
213
|
+
inStr = kind ?? null;
|
|
214
|
+
}
|
|
215
|
+
i++;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
blocks.sort((a, b) => a.open - b.open);
|
|
221
|
+
return blocks;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function innermostBlock(
|
|
225
|
+
blocks: Block[],
|
|
226
|
+
offset: number,
|
|
227
|
+
fileLen: number,
|
|
228
|
+
): Block {
|
|
229
|
+
let best: Block | null = null;
|
|
230
|
+
for (const b of blocks) {
|
|
231
|
+
if (b.open <= offset && b.close >= offset) {
|
|
232
|
+
if (!best || b.open > best.open) best = b;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return best || { open: 0, close: fileLen };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function computeLineOffsets(contents: string): number[] {
|
|
239
|
+
const offsets = [0];
|
|
240
|
+
for (let i = 0; i < contents.length; i++) {
|
|
241
|
+
if (contents[i] === "\n") offsets.push(i + 1);
|
|
242
|
+
}
|
|
243
|
+
return offsets;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function offsetToLine(offsets: number[], offset: number): number {
|
|
247
|
+
let lo = 0;
|
|
248
|
+
let hi = offsets.length - 1;
|
|
249
|
+
while (lo < hi) {
|
|
250
|
+
const mid = (lo + hi + 1) >>> 1;
|
|
251
|
+
if (offsets[mid] <= offset) lo = mid;
|
|
252
|
+
else hi = mid - 1;
|
|
253
|
+
}
|
|
254
|
+
return lo + 1;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function findChainEnd(contents: string, startIdx: number): number {
|
|
258
|
+
let depth = 0;
|
|
259
|
+
let inStr: string | null = null;
|
|
260
|
+
let templateDepth = 0;
|
|
261
|
+
const limit = Math.min(contents.length, startIdx + 10000);
|
|
262
|
+
let sawOpen = false;
|
|
263
|
+
for (let i = startIdx; i < limit; i++) {
|
|
264
|
+
const c = contents[i];
|
|
265
|
+
const prev = contents[i - 1];
|
|
266
|
+
if (inStr) {
|
|
267
|
+
if (inStr === "`") {
|
|
268
|
+
if (c === "`") inStr = null;
|
|
269
|
+
else if (c === "$" && contents[i + 1] === "{") {
|
|
270
|
+
templateDepth++;
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
} else if (c === inStr && prev !== "\\") {
|
|
274
|
+
inStr = null;
|
|
275
|
+
}
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (templateDepth > 0 && c === "}") {
|
|
279
|
+
templateDepth--;
|
|
280
|
+
inStr = "`";
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
284
|
+
inStr = c;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (c === "(" || c === "{" || c === "[") {
|
|
288
|
+
depth++;
|
|
289
|
+
sawOpen = true;
|
|
290
|
+
} else if (c === ")" || c === "}" || c === "]") {
|
|
291
|
+
depth--;
|
|
292
|
+
} else if (c === ";" && depth <= 0) {
|
|
293
|
+
return i + 1;
|
|
294
|
+
} else if (c === "\n" && sawOpen && depth <= 0) {
|
|
295
|
+
let j = i + 1;
|
|
296
|
+
while (j < limit && /[ \t]/.test(contents[j])) j++;
|
|
297
|
+
if (j >= limit || (contents[j] !== "." && contents[j] !== ")")) {
|
|
298
|
+
return i + 1;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return limit;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
interface Statement {
|
|
306
|
+
kind: "drizzle" | "raw-sql";
|
|
307
|
+
op: string;
|
|
308
|
+
name: string;
|
|
309
|
+
line: number;
|
|
310
|
+
queryStart: number;
|
|
311
|
+
queryEnd: number;
|
|
312
|
+
snippet: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function walkBackToChainHead(contents: string, idx: number): number {
|
|
316
|
+
let i = idx;
|
|
317
|
+
while (i > 0) {
|
|
318
|
+
const c = contents[i];
|
|
319
|
+
if (c === ";" || c === "{" || c === "}") return i + 1;
|
|
320
|
+
if (c === "\n") {
|
|
321
|
+
let j = i + 1;
|
|
322
|
+
while (j < contents.length && /[ \t]/.test(contents[j])) j++;
|
|
323
|
+
if (contents[j] !== "." && contents[j] !== ")") return i + 1;
|
|
324
|
+
}
|
|
325
|
+
i--;
|
|
326
|
+
}
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function findStatements(
|
|
331
|
+
contents: string,
|
|
332
|
+
ownableNames: Set<string>,
|
|
333
|
+
ownableSqlNames: Set<string>,
|
|
334
|
+
): Statement[] {
|
|
335
|
+
const statements: Statement[] = [];
|
|
336
|
+
const lineOffsets = computeLineOffsets(contents);
|
|
337
|
+
|
|
338
|
+
const namesAlt = [...ownableNames]
|
|
339
|
+
.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
340
|
+
.join("|");
|
|
341
|
+
|
|
342
|
+
if (namesAlt.length > 0) {
|
|
343
|
+
const fromRe = new RegExp(
|
|
344
|
+
`\\.\\s*from\\s*\\(\\s*(?:[a-zA-Z_$][\\w$]*\\s*\\.\\s*)?(${namesAlt})\\b`,
|
|
345
|
+
"g",
|
|
346
|
+
);
|
|
347
|
+
let fromMatch: RegExpExecArray | null;
|
|
348
|
+
while ((fromMatch = fromRe.exec(contents)) !== null) {
|
|
349
|
+
const name = fromMatch[1];
|
|
350
|
+
const queryStart = walkBackToChainHead(contents, fromMatch.index);
|
|
351
|
+
const queryEnd = findChainEnd(contents, fromMatch.index);
|
|
352
|
+
const snippet = contents.slice(queryStart, queryEnd);
|
|
353
|
+
statements.push({
|
|
354
|
+
kind: "drizzle",
|
|
355
|
+
op: "select",
|
|
356
|
+
name,
|
|
357
|
+
line: offsetToLine(lineOffsets, fromMatch.index),
|
|
358
|
+
queryStart,
|
|
359
|
+
queryEnd,
|
|
360
|
+
snippet,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
for (const op of ["update", "delete", "insert"]) {
|
|
365
|
+
const re = new RegExp(
|
|
366
|
+
`\\bdb\\s*\\.\\s*${op}\\s*\\(\\s*(?:[a-zA-Z_$][\\w$]*\\s*\\.\\s*)?(${namesAlt})\\b`,
|
|
367
|
+
"g",
|
|
368
|
+
);
|
|
369
|
+
let m: RegExpExecArray | null;
|
|
370
|
+
while ((m = re.exec(contents)) !== null) {
|
|
371
|
+
const name = m[1];
|
|
372
|
+
const queryStart = walkBackToChainHead(contents, m.index);
|
|
373
|
+
const queryEnd = findChainEnd(contents, m.index);
|
|
374
|
+
const snippet = contents.slice(queryStart, queryEnd);
|
|
375
|
+
statements.push({
|
|
376
|
+
kind: "drizzle",
|
|
377
|
+
op,
|
|
378
|
+
name,
|
|
379
|
+
line: offsetToLine(lineOffsets, m.index),
|
|
380
|
+
queryStart,
|
|
381
|
+
queryEnd,
|
|
382
|
+
snippet,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
for (const sqlName of ownableSqlNames) {
|
|
389
|
+
const escaped = sqlName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
390
|
+
const verbs: Array<[string, string]> = [
|
|
391
|
+
["select", `\\bFROM\\s+${escaped}\\b`],
|
|
392
|
+
["update", `\\bUPDATE\\s+${escaped}\\b`],
|
|
393
|
+
["delete", `\\bDELETE\\s+FROM\\s+${escaped}\\b`],
|
|
394
|
+
["insert", `\\bINSERT\\s+INTO\\s+${escaped}\\b`],
|
|
395
|
+
];
|
|
396
|
+
for (const [op, body] of verbs) {
|
|
397
|
+
const re = new RegExp(`["'\`][^"'\`]*${body}[\\s\\S]*?["'\`]`, "gi");
|
|
398
|
+
let m: RegExpExecArray | null;
|
|
399
|
+
while ((m = re.exec(contents)) !== null) {
|
|
400
|
+
const matchStart = m.index;
|
|
401
|
+
statements.push({
|
|
402
|
+
kind: "raw-sql",
|
|
403
|
+
op,
|
|
404
|
+
name: sqlName,
|
|
405
|
+
line: offsetToLine(lineOffsets, matchStart),
|
|
406
|
+
queryStart: matchStart,
|
|
407
|
+
queryEnd: matchStart + m[0].length,
|
|
408
|
+
snippet: m[0],
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return statements;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function isControlFlowBlock(contents: string, block: Block): boolean {
|
|
418
|
+
let i = block.open - 1;
|
|
419
|
+
while (i > 0 && /[ \t\n\r]/.test(contents[i])) i--;
|
|
420
|
+
if (contents[i] === ")") {
|
|
421
|
+
let depth = 1;
|
|
422
|
+
let j = i - 1;
|
|
423
|
+
while (j > 0 && depth > 0) {
|
|
424
|
+
if (contents[j] === ")") depth++;
|
|
425
|
+
else if (contents[j] === "(") depth--;
|
|
426
|
+
if (depth === 0) break;
|
|
427
|
+
j--;
|
|
428
|
+
}
|
|
429
|
+
j--;
|
|
430
|
+
while (j > 0 && /[ \t\n\r]/.test(contents[j])) j--;
|
|
431
|
+
let end = j + 1;
|
|
432
|
+
while (j > 0 && /[a-zA-Z_$]/.test(contents[j])) j--;
|
|
433
|
+
const word = contents.slice(j + 1, end);
|
|
434
|
+
return ["if", "for", "while", "switch", "catch"].includes(word);
|
|
435
|
+
}
|
|
436
|
+
let end = i + 1;
|
|
437
|
+
while (i > 0 && /[a-zA-Z_$]/.test(contents[i])) i--;
|
|
438
|
+
const word = contents.slice(i + 1, end);
|
|
439
|
+
return ["else", "try", "do", "finally"].includes(word);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function directBlockText(
|
|
443
|
+
contents: string,
|
|
444
|
+
block: Block,
|
|
445
|
+
blocks: Block[],
|
|
446
|
+
queryOffset: number,
|
|
447
|
+
): string {
|
|
448
|
+
const candidates = blocks.filter(
|
|
449
|
+
(b) =>
|
|
450
|
+
b.open > block.open &&
|
|
451
|
+
b.close < block.close &&
|
|
452
|
+
!(b.open <= queryOffset && b.close >= queryOffset) &&
|
|
453
|
+
isControlFlowBlock(contents, b),
|
|
454
|
+
);
|
|
455
|
+
const descendants = candidates
|
|
456
|
+
.filter(
|
|
457
|
+
(b) =>
|
|
458
|
+
!candidates.some(
|
|
459
|
+
(p) => p !== b && p.open < b.open && p.close > b.close,
|
|
460
|
+
),
|
|
461
|
+
)
|
|
462
|
+
.sort((a, b) => b.open - a.open);
|
|
463
|
+
|
|
464
|
+
let result = contents.slice(block.open, block.close + 1);
|
|
465
|
+
for (const child of descendants) {
|
|
466
|
+
const start = child.open - block.open;
|
|
467
|
+
const end = child.close - block.open;
|
|
468
|
+
if (start < 0 || end >= result.length) continue;
|
|
469
|
+
const inner = result.slice(start + 1, end);
|
|
470
|
+
const blanked = inner.replace(/[^\n]/g, " ");
|
|
471
|
+
result = result.slice(0, start + 1) + blanked + result.slice(end);
|
|
472
|
+
}
|
|
473
|
+
return result;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function blockHasAccessControl(blockText: string): boolean {
|
|
477
|
+
if (ACCESS_CONTROL_HELPERS.some((re) => re.test(blockText))) return true;
|
|
478
|
+
if (EXPLICIT_OWNER_FILTERS.some((re) => re.test(blockText))) return true;
|
|
479
|
+
if (BLOCK_OWNERSHIP_SIGNALS.some((re) => re.test(blockText))) return true;
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function collectAccessControlBindings(contents: string): Set<string> {
|
|
484
|
+
const names = new Set<string>();
|
|
485
|
+
const bindRe =
|
|
486
|
+
/\b(?:const|let|var)\s+([a-zA-Z_$][\w$]*)\s*(?::[^=]+)?\s*=\s*([\s\S]{0,400}?)(?:;|\n\s*(?:const|let|var|if|return|await|function|export|}|\/\/))/g;
|
|
487
|
+
let m: RegExpExecArray | null;
|
|
488
|
+
while ((m = bindRe.exec(contents)) !== null) {
|
|
489
|
+
const name = m[1];
|
|
490
|
+
const rhs = m[2];
|
|
491
|
+
if (
|
|
492
|
+
ACCESS_CONTROL_HELPERS.some((re) => re.test(rhs)) ||
|
|
493
|
+
EXPLICIT_OWNER_FILTERS.some((re) => re.test(rhs))
|
|
494
|
+
) {
|
|
495
|
+
names.add(name);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const pushRe = /\b([a-zA-Z_$][\w$]*)\.push\s*\(([^;]{0,400})\)/g;
|
|
499
|
+
while ((m = pushRe.exec(contents)) !== null) {
|
|
500
|
+
const name = m[1];
|
|
501
|
+
const arg = m[2];
|
|
502
|
+
if (
|
|
503
|
+
ACCESS_CONTROL_HELPERS.some((re) => re.test(arg)) ||
|
|
504
|
+
EXPLICIT_OWNER_FILTERS.some((re) => re.test(arg))
|
|
505
|
+
) {
|
|
506
|
+
names.add(name);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return names;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function statementHasInlineAccessControl(stmt: Statement): boolean {
|
|
513
|
+
const snippet = stmt.snippet;
|
|
514
|
+
if (ACCESS_CONTROL_HELPERS.some((re) => re.test(snippet))) return true;
|
|
515
|
+
if (
|
|
516
|
+
stmt.kind === "drizzle" &&
|
|
517
|
+
EXPLICIT_OWNER_FILTERS.some((re) => re.test(snippet))
|
|
518
|
+
)
|
|
519
|
+
return true;
|
|
520
|
+
if (stmt.op === "insert") {
|
|
521
|
+
if (INSERT_OWNER_PATTERNS.some((re) => re.test(snippet))) return true;
|
|
522
|
+
}
|
|
523
|
+
if (stmt.kind === "raw-sql") {
|
|
524
|
+
if (
|
|
525
|
+
/\bowner_email\b/i.test(snippet) ||
|
|
526
|
+
/\buser_email\b/i.test(snippet) ||
|
|
527
|
+
/\borg_id\b/i.test(snippet)
|
|
528
|
+
) {
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function isOptedOutWithinBlock(blockText: string): boolean {
|
|
536
|
+
return OPT_OUT_MARKER.test(blockText);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function isEligibleScanPath(rel: string): boolean {
|
|
540
|
+
return /^actions\//.test(rel) || /^server\//.test(rel);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function scanFiles(
|
|
544
|
+
root: string,
|
|
545
|
+
ownablesByDir: Map<string, Set<string>>,
|
|
546
|
+
extraExemptPaths: string[],
|
|
547
|
+
): Array<{ file: string; hits: Statement[] }> {
|
|
548
|
+
const allOwnableNames = new Set<string>();
|
|
549
|
+
const allOwnableSqlNames = new Set<string>();
|
|
550
|
+
for (const set of ownablesByDir.values()) {
|
|
551
|
+
for (const name of set) {
|
|
552
|
+
if (name.startsWith("__sql__")) allOwnableSqlNames.add(name.slice(7));
|
|
553
|
+
else allOwnableNames.add(name);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const violations: Array<{ file: string; hits: Statement[] }> = [];
|
|
558
|
+
|
|
559
|
+
for (const file of walk(root)) {
|
|
560
|
+
if (!file.endsWith(".ts") && !file.endsWith(".tsx")) continue;
|
|
561
|
+
if (file.endsWith(".d.ts")) continue;
|
|
562
|
+
const rel = relPosix(root, file);
|
|
563
|
+
if (extraExemptPaths.includes(rel)) continue;
|
|
564
|
+
if (rel.endsWith("/db/schema.ts")) continue;
|
|
565
|
+
if (!isEligibleScanPath(rel)) continue;
|
|
566
|
+
|
|
567
|
+
const contents = readFileSafe(file);
|
|
568
|
+
if (contents === null) continue;
|
|
569
|
+
|
|
570
|
+
if (
|
|
571
|
+
!/\bfrom\s*\(/.test(contents) &&
|
|
572
|
+
!/\bdb\s*\.\s*(update|delete|insert)\b/.test(contents) &&
|
|
573
|
+
!/\b(FROM|UPDATE|INSERT INTO|DELETE FROM)\b/i.test(contents)
|
|
574
|
+
) {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const head = contents.split("\n").slice(0, 30).join("\n");
|
|
579
|
+
if (OPT_OUT_MARKER.test(head)) continue;
|
|
580
|
+
|
|
581
|
+
const statements = findStatements(
|
|
582
|
+
contents,
|
|
583
|
+
allOwnableNames,
|
|
584
|
+
allOwnableSqlNames,
|
|
585
|
+
);
|
|
586
|
+
if (statements.length === 0) continue;
|
|
587
|
+
|
|
588
|
+
const fileHasAccessControl =
|
|
589
|
+
ACCESS_CONTROL_HELPERS.some((re) => re.test(contents)) ||
|
|
590
|
+
EXPLICIT_OWNER_FILTERS.some((re) => re.test(contents));
|
|
591
|
+
if (!fileHasAccessControl) continue;
|
|
592
|
+
|
|
593
|
+
const blocks = buildBlockTree(contents);
|
|
594
|
+
const accessControlBindings = collectAccessControlBindings(contents);
|
|
595
|
+
|
|
596
|
+
const fileViolations: Statement[] = [];
|
|
597
|
+
for (const stmt of statements) {
|
|
598
|
+
if (statementHasInlineAccessControl(stmt)) continue;
|
|
599
|
+
|
|
600
|
+
let scoped = false;
|
|
601
|
+
let cur = innermostBlock(blocks, stmt.queryStart, contents.length);
|
|
602
|
+
let levels = 0;
|
|
603
|
+
while (cur && levels < 8) {
|
|
604
|
+
const directText = directBlockText(
|
|
605
|
+
contents,
|
|
606
|
+
cur,
|
|
607
|
+
blocks,
|
|
608
|
+
stmt.queryStart,
|
|
609
|
+
);
|
|
610
|
+
if (isOptedOutWithinBlock(directText)) {
|
|
611
|
+
scoped = true;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
if (blockHasAccessControl(directText)) {
|
|
615
|
+
scoped = true;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
if (
|
|
619
|
+
accessControlBindings.size > 0 &&
|
|
620
|
+
[...accessControlBindings].some((name) =>
|
|
621
|
+
new RegExp(`\\b${name}\\b`).test(stmt.snippet),
|
|
622
|
+
)
|
|
623
|
+
) {
|
|
624
|
+
scoped = true;
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
const parents = blocks.filter(
|
|
628
|
+
(b) => b.open < cur.open && b.close > cur.close,
|
|
629
|
+
);
|
|
630
|
+
const parent =
|
|
631
|
+
parents.length > 0
|
|
632
|
+
? parents.reduce((a, b) => (a.open > b.open ? a : b))
|
|
633
|
+
: null;
|
|
634
|
+
if (!parent) break;
|
|
635
|
+
cur = parent;
|
|
636
|
+
levels++;
|
|
637
|
+
}
|
|
638
|
+
if (scoped) continue;
|
|
639
|
+
|
|
640
|
+
fileViolations.push(stmt);
|
|
641
|
+
}
|
|
642
|
+
if (fileViolations.length > 0) {
|
|
643
|
+
violations.push({ file: rel, hits: fileViolations });
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return violations;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
interface MentionViolation {
|
|
651
|
+
file: string;
|
|
652
|
+
line: number;
|
|
653
|
+
table: string;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function scanMentionProviders(
|
|
657
|
+
root: string,
|
|
658
|
+
ownablesByDir: Map<string, Set<string>>,
|
|
659
|
+
extraExemptPaths: string[],
|
|
660
|
+
): MentionViolation[] {
|
|
661
|
+
const allOwnableNames = new Set<string>();
|
|
662
|
+
for (const set of ownablesByDir.values()) {
|
|
663
|
+
for (const name of set) {
|
|
664
|
+
if (!name.startsWith("__sql__")) allOwnableNames.add(name);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (allOwnableNames.size === 0) return [];
|
|
668
|
+
|
|
669
|
+
const namesAlt = [...allOwnableNames]
|
|
670
|
+
.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
671
|
+
.join("|");
|
|
672
|
+
|
|
673
|
+
const fromOwnableRe = new RegExp(
|
|
674
|
+
`\\.\\s*from\\s*\\(\\s*(?:[a-zA-Z_$][\\w$]*\\s*\\.\\s*)?(${namesAlt})\\b`,
|
|
675
|
+
"g",
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
const CLOSURE_ACCESS_PATTERNS = [
|
|
679
|
+
...ACCESS_CONTROL_HELPERS,
|
|
680
|
+
...EXPLICIT_OWNER_FILTERS,
|
|
681
|
+
...BLOCK_OWNERSHIP_SIGNALS,
|
|
682
|
+
];
|
|
683
|
+
|
|
684
|
+
const violations: MentionViolation[] = [];
|
|
685
|
+
|
|
686
|
+
for (const file of walk(root)) {
|
|
687
|
+
if (!file.endsWith(".ts") && !file.endsWith(".tsx")) continue;
|
|
688
|
+
if (file.endsWith(".d.ts")) continue;
|
|
689
|
+
const rel = relPosix(root, file);
|
|
690
|
+
if (extraExemptPaths.includes(rel)) continue;
|
|
691
|
+
if (!/^server\//.test(rel)) continue;
|
|
692
|
+
|
|
693
|
+
const contents = readFileSafe(file);
|
|
694
|
+
if (contents === null) continue;
|
|
695
|
+
if (
|
|
696
|
+
!/\bmentionProviders\b/.test(contents) ||
|
|
697
|
+
!/\bfrom\s*\(/.test(contents)
|
|
698
|
+
) {
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const head = contents.split("\n").slice(0, 30).join("\n");
|
|
703
|
+
if (OPT_OUT_MARKER.test(head)) continue;
|
|
704
|
+
|
|
705
|
+
const lineOffsets = computeLineOffsets(contents);
|
|
706
|
+
|
|
707
|
+
const mpHeaderRe = /\bmentionProviders\s*:/g;
|
|
708
|
+
while (mpHeaderRe.exec(contents) !== null) {
|
|
709
|
+
let i = mpHeaderRe.lastIndex;
|
|
710
|
+
while (i < contents.length && contents[i] !== "{" && contents[i] !== "\n")
|
|
711
|
+
i++;
|
|
712
|
+
if (i >= contents.length || contents[i] !== "{") continue;
|
|
713
|
+
|
|
714
|
+
let depth = 0;
|
|
715
|
+
let inStr: string | null = null;
|
|
716
|
+
const mpStart = i;
|
|
717
|
+
let mpEnd = -1;
|
|
718
|
+
for (let j = i; j < contents.length; j++) {
|
|
719
|
+
const c = contents[j];
|
|
720
|
+
if (inStr) {
|
|
721
|
+
if (c === "\\" && inStr !== "`") {
|
|
722
|
+
j++;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
if (c === inStr) inStr = null;
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
729
|
+
inStr = c;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
if (c === "{") depth++;
|
|
733
|
+
else if (c === "}") {
|
|
734
|
+
depth--;
|
|
735
|
+
if (depth === 0) {
|
|
736
|
+
mpEnd = j;
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (mpEnd === -1) continue;
|
|
742
|
+
|
|
743
|
+
const mpBody = contents.slice(mpStart, mpEnd + 1);
|
|
744
|
+
|
|
745
|
+
const searchRe = /\bsearch\s*:\s*async\s*\([^)]*\)\s*=>\s*\{/g;
|
|
746
|
+
let searchMatch: RegExpExecArray | null;
|
|
747
|
+
while ((searchMatch = searchRe.exec(mpBody)) !== null) {
|
|
748
|
+
const closureStart =
|
|
749
|
+
mpStart + searchMatch.index + searchMatch[0].length - 1;
|
|
750
|
+
let closureDepth = 0;
|
|
751
|
+
let closureEnd = -1;
|
|
752
|
+
let closureInStr: string | null = null;
|
|
753
|
+
for (let j = closureStart; j < mpEnd; j++) {
|
|
754
|
+
const c = contents[j];
|
|
755
|
+
if (closureInStr) {
|
|
756
|
+
if (c === "\\" && closureInStr !== "`") {
|
|
757
|
+
j++;
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
if (c === closureInStr) closureInStr = null;
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
764
|
+
closureInStr = c;
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
if (c === "{") closureDepth++;
|
|
768
|
+
else if (c === "}") {
|
|
769
|
+
closureDepth--;
|
|
770
|
+
if (closureDepth === 0) {
|
|
771
|
+
closureEnd = j;
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (closureEnd === -1) continue;
|
|
777
|
+
|
|
778
|
+
const closureBody = contents.slice(closureStart, closureEnd + 1);
|
|
779
|
+
if (OPT_OUT_MARKER.test(closureBody)) continue;
|
|
780
|
+
|
|
781
|
+
fromOwnableRe.lastIndex = 0;
|
|
782
|
+
let fromMatch: RegExpExecArray | null;
|
|
783
|
+
while ((fromMatch = fromOwnableRe.exec(closureBody)) !== null) {
|
|
784
|
+
const tableName = fromMatch[1];
|
|
785
|
+
if (CLOSURE_ACCESS_PATTERNS.some((re) => re.test(closureBody)))
|
|
786
|
+
continue;
|
|
787
|
+
const absOffset = closureStart + fromMatch.index;
|
|
788
|
+
const line = offsetToLine(lineOffsets, absOffset);
|
|
789
|
+
violations.push({ file: rel, line, table: tableName });
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return violations;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export function scanUnscopedQueries(
|
|
799
|
+
options: UnscopedQueriesOptions,
|
|
800
|
+
): GuardResult {
|
|
801
|
+
const { root, extraExemptPaths = [] } = options;
|
|
802
|
+
const findings: GuardFinding[] = [];
|
|
803
|
+
|
|
804
|
+
const ownablesByDir = collectOwnableTables(root);
|
|
805
|
+
if (ownablesByDir.size === 0) {
|
|
806
|
+
return { name: "no-unscoped-queries", findings };
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const violations = scanFiles(root, ownablesByDir, extraExemptPaths);
|
|
810
|
+
for (const v of violations) {
|
|
811
|
+
for (const hit of v.hits) {
|
|
812
|
+
findings.push({
|
|
813
|
+
file: v.file,
|
|
814
|
+
line: hit.line,
|
|
815
|
+
message: `unscoped ${hit.op} on "${hit.name}" (${hit.kind}) — add accessFilter/resolveAccess/assertAccess or an explicit ownerEmail/userEmail/orgId filter.`,
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const mentionViolations = scanMentionProviders(
|
|
821
|
+
root,
|
|
822
|
+
ownablesByDir,
|
|
823
|
+
extraExemptPaths,
|
|
824
|
+
);
|
|
825
|
+
for (const v of mentionViolations) {
|
|
826
|
+
findings.push({
|
|
827
|
+
file: v.file,
|
|
828
|
+
line: v.line,
|
|
829
|
+
message: `mentionProviders search closure queries "${v.table}" without access control — every user who types @ in chat would see rows owned by other users.`,
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
return { name: "no-unscoped-queries", findings };
|
|
834
|
+
}
|