loadwise 0.7.0 → 0.8.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 +23 -15
- package/dist/bin/loadwise.js +12 -24
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +5 -3
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +7 -2
- package/dist/lib/editor/language-server.js +64 -25
- package/dist/lib/editor/native-setup.js +3 -2
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +36 -9
- package/dist/lib/editor/setup-server.js +1 -1
- package/dist/lib/editor/setup-vim.js +6 -4
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +9 -1
- package/dist/lib/maintainability/cli.js +4 -0
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/cli-output.js +1 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +8 -3
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +61 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +56 -2
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +72 -57
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/mongoose-lean.js +175 -10
- package/dist/lib/performance/request/phase5-rules.js +74 -13
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +18 -4
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +6 -2
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +2 -1
- package/dist/lib/shared/agent/agent-verify.js +4 -1
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +96 -12
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +5 -3
- package/dist/lib/shared/fix/fix-imports.js +4 -171
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation.js +5 -3
- package/dist/lib/shared/fix/fix-safety.js +7 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix.js +31 -7
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +6 -2
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +9 -3
- package/dist/lib/shared/reporting/source-report.js +1 -0
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +26 -7
- package/dist/lib/shared/workspaces.js +15 -3
- package/package.json +5 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +554 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
package/README.md
CHANGED
|
@@ -684,6 +684,7 @@ Some rules moved here from the performance and maintainability checkers and kept
|
|
|
684
684
|
| <a id="crlf-unsafe-line-split"></a>[`crlf-unsafe-line-split`](docs/rules/reliability/crlf-unsafe-line-split.md) | medium | Splitting file text on a bare newline leaves carriage returns on CRLF lines and can change exact comparisons. |
|
|
685
685
|
| <a id="csharp-async-void"></a>[`csharp-async-void`](docs/rules/reliability/csharp-async-void.md) | high | An async void method cannot be awaited and can crash the process on unhandled exceptions. |
|
|
686
686
|
| <a id="csharp-disposable-without-using"></a>[`csharp-disposable-without-using`](docs/rules/reliability/csharp-disposable-without-using.md) | medium | A C# stream, connection or other IDisposable is created without using, so an exception leaks it. |
|
|
687
|
+
| <a id="db-pool-client-not-released"></a>[`db-pool-client-not-released`](docs/rules/reliability/db-pool-client-not-released.md) | high | A locally checked-out database connection can leave its scope without being released. |
|
|
687
688
|
| <a id="discarded-error-result"></a>[`discarded-error-result`](docs/rules/reliability/discarded-error-result.md) | high | A call discards a typed Either or Result that can carry a failure as a value. |
|
|
688
689
|
| <a id="drizzle-unfiltered-write"></a>[`drizzle-unfiltered-write`](docs/rules/reliability/drizzle-unfiltered-write.md) | critical | A Drizzle update or delete executes without an effective where clause. |
|
|
689
690
|
| <a id="drizzle-write-preflight"></a>[`drizzle-write-preflight`](docs/rules/reliability/drizzle-write-preflight.md) | medium | A separate existence check before a Drizzle write can race with another request. |
|
|
@@ -705,6 +706,8 @@ Some rules moved here from the performance and maintainability checkers and kept
|
|
|
705
706
|
| <a id="next-server-env-in-client"></a>[`next-server-env-in-client`](docs/rules/reliability/next-server-env-in-client.md) | high | A 'use client' file reads a process.env variable without the NEXT_PUBLIC_ prefix, so it is unavailable in the browser by default. |
|
|
706
707
|
| <a id="parse-failure-resets-file"></a>[`parse-failure-resets-file`](docs/rules/reliability/parse-failure-resets-file.md) | high | A write after a read or parse failure can replace unreadable contents at the same path. |
|
|
707
708
|
| <a id="payment-missing-idempotency-key"></a>[`payment-missing-idempotency-key`](docs/rules/reliability/payment-missing-idempotency-key.md) | high | A Stripe call that moves money has no idempotency key, so a retry can charge or pay out twice. |
|
|
709
|
+
| <a id="pg-advisory-lock-session"></a>[`pg-advisory-lock-session`](docs/rules/reliability/pg-advisory-lock-session.md) | high | A PostgreSQL session can return to the pool while it holds an advisory lock. |
|
|
710
|
+
| <a id="pg-listen-session"></a>[`pg-listen-session`](docs/rules/reliability/pg-listen-session.md) | high | A PostgreSQL listener connection can return to the pool while it is still subscribed. |
|
|
708
711
|
| <a id="pg-transaction-on-pool"></a>[`pg-transaction-on-pool`](docs/rules/reliability/pg-transaction-on-pool.md) | critical | A transaction statement is sent to a pool, so its statements can run on different connections. |
|
|
709
712
|
| <a id="pool-without-connection-timeout"></a>[`pool-without-connection-timeout`](docs/rules/reliability/pool-without-connection-timeout.md) | medium | A pg Pool or Client sets no connectionTimeoutMillis, so its default of 0 waits for a connection forever. |
|
|
710
713
|
| <a id="prisma-dependent-writes"></a>[`prisma-dependent-writes`](docs/rules/reliability/prisma-dependent-writes.md) | high | Adjacent Prisma creates pass a value from the first record into the next write. |
|
|
@@ -736,7 +739,7 @@ Some rules moved here from the performance and maintainability checkers and kept
|
|
|
736
739
|
| <a id="unguarded-boundary-access"></a>[`unguarded-boundary-access`](docs/rules/reliability/unguarded-boundary-access.md) | medium | A nested property is read from outside input or a lookup that can be missing, so absent data throws a TypeError. |
|
|
737
740
|
| <a id="unreachable-code"></a>[`unreachable-code`](docs/rules/reliability/unreachable-code.md) | medium | Statements follow a return, throw, break or continue in the same block and never run. |
|
|
738
741
|
| <a id="upload-without-size-limit"></a>[`upload-without-size-limit`](docs/rules/reliability/upload-without-size-limit.md) | high | A multer or Nest upload interceptor has no file size limit. |
|
|
739
|
-
| <a id="webhook-missing-idempotency-check"></a>[`webhook-missing-idempotency-check`](docs/rules/reliability/webhook-missing-idempotency-check.md) | medium | A webhook route inserts rows without
|
|
742
|
+
| <a id="webhook-missing-idempotency-check"></a>[`webhook-missing-idempotency-check`](docs/rules/reliability/webhook-missing-idempotency-check.md) | medium | A webhook route inserts rows without visible atomic deduplication by event ID. |
|
|
740
743
|
|
|
741
744
|
<!-- loadwise:rules:end -->
|
|
742
745
|
|
|
@@ -921,6 +924,7 @@ It accepts the source-check flags of `loadwise perf`, including `--format`, `--m
|
|
|
921
924
|
| <a id="jwt-verify-without-algorithms"></a>[`jwt-verify-without-algorithms`](docs/rules/security/jwt-verify-without-algorithms.md) | high | JWT verification does not restrict the accepted signing algorithms. |
|
|
922
925
|
| <a id="jwt-weak-secret-literal"></a>[`jwt-weak-secret-literal`](docs/rules/security/jwt-weak-secret-literal.md) | high | JWT signing or verification uses a short (< 32 chars) or weak literal secret susceptible to brute-force forgery. |
|
|
923
926
|
| <a id="knex-raw-dynamic-text"></a>[`knex-raw-dynamic-text`](docs/rules/security/knex-raw-dynamic-text.md) | critical | A dynamic SQL fragment reaches Knex without parameter binding. |
|
|
927
|
+
| <a id="ldap-filter-injection"></a>[`ldap-filter-injection`](docs/rules/security/ldap-filter-injection.md) | high | Request data reaches an LDAP search filter without RFC 4515 filter escaping or a filter builder. |
|
|
924
928
|
| <a id="mass-assignment"></a>[`mass-assignment`](docs/rules/security/mass-assignment.md) | high | An unfiltered request body reaches a persistence operation. |
|
|
925
929
|
| <a id="mysql-dynamic-query-text"></a>[`mysql-dynamic-query-text`](docs/rules/security/mysql-dynamic-query-text.md) | critical | Dynamic SQL text reaches a MySQL client without parameter binding. |
|
|
926
930
|
| <a id="nest-validation-without-whitelist"></a>[`nest-validation-without-whitelist`](docs/rules/security/nest-validation-without-whitelist.md) | medium | A NestJS ValidationPipe permits properties outside the validated DTO. |
|
|
@@ -968,25 +972,28 @@ It accepts the source-check flags of `loadwise perf`, including `--format`, `--m
|
|
|
968
972
|
|
|
969
973
|
<!-- loadwise:rules:start checker=security group=polyglot-source-checks -->
|
|
970
974
|
|
|
971
|
-
| Rule
|
|
972
|
-
|
|
|
973
|
-
| <a id="csharp-ef-from-sql-raw"></a>[`csharp-ef-from-sql-raw`](docs/rules/security/csharp-ef-from-sql-raw.md)
|
|
974
|
-
| <a id="csharp-process-start"></a>[`csharp-process-start`](docs/rules/security/csharp-process-start.md)
|
|
975
|
-
| <a id="go-exec-command-shell"></a>[`go-exec-command-shell`](docs/rules/security/go-exec-command-shell.md)
|
|
976
|
-
| <a id="go-sql-sprintf-injection"></a>[`go-sql-sprintf-injection`](docs/rules/security/go-sql-sprintf-injection.md)
|
|
977
|
-
| <a id="
|
|
978
|
-
| <a id="java-
|
|
979
|
-
| <a id="
|
|
980
|
-
| <a id="python-
|
|
981
|
-
| <a id="python-
|
|
982
|
-
| <a id="
|
|
983
|
-
| <a id="
|
|
975
|
+
| Rule | Impact | What it flags |
|
|
976
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------- |
|
|
977
|
+
| <a id="csharp-ef-from-sql-raw"></a>[`csharp-ef-from-sql-raw`](docs/rules/security/csharp-ef-from-sql-raw.md) | high | FromSqlRaw or ExecuteSqlRaw receives a concatenated or interpolated string, risking SQL injection. |
|
|
978
|
+
| <a id="csharp-process-start"></a>[`csharp-process-start`](docs/rules/security/csharp-process-start.md) | medium | Process.Start launches an external process and risks command injection with untrusted arguments. |
|
|
979
|
+
| <a id="go-exec-command-shell"></a>[`go-exec-command-shell`](docs/rules/security/go-exec-command-shell.md) | high | exec.Command invokes a shell, which risks command injection. |
|
|
980
|
+
| <a id="go-sql-sprintf-injection"></a>[`go-sql-sprintf-injection`](docs/rules/security/go-sql-sprintf-injection.md) | high | SQL text formatted with fmt.Sprintf risks SQL injection. |
|
|
981
|
+
| <a id="go-tls-insecure-skip-verify"></a>[`go-tls-insecure-skip-verify`](docs/rules/security/go-tls-insecure-skip-verify.md) | high | Setting InsecureSkipVerify: true on tls.Config disables TLS certificate verification. |
|
|
982
|
+
| <a id="java-runtime-exec"></a>[`java-runtime-exec`](docs/rules/security/java-runtime-exec.md) | medium | Runtime.getRuntime().exec runs an OS command and risks command injection with untrusted arguments. |
|
|
983
|
+
| <a id="java-sql-string-concat"></a>[`java-sql-string-concat`](docs/rules/security/java-sql-string-concat.md) | high | A SQL query built by string concatenation risks SQL injection. |
|
|
984
|
+
| <a id="python-insecure-deserialization"></a>[`python-insecure-deserialization`](docs/rules/security/python-insecure-deserialization.md) | high | pickle or marshal deserialization of untrusted data can execute arbitrary code. |
|
|
985
|
+
| <a id="python-requests-tls-verify-disabled"></a>[`python-requests-tls-verify-disabled`](docs/rules/security/python-requests-tls-verify-disabled.md) | high | Calling Python requests with verify=False disables TLS certificate verification. |
|
|
986
|
+
| <a id="python-subprocess-shell-true"></a>[`python-subprocess-shell-true`](docs/rules/security/python-subprocess-shell-true.md) | high | subprocess with shell=True or os.system passes input through a shell, risking command injection. |
|
|
987
|
+
| <a id="python-unsafe-yaml-load"></a>[`python-unsafe-yaml-load`](docs/rules/security/python-unsafe-yaml-load.md) | high | yaml.load or yaml.load_all without SafeLoader can construct arbitrary Python objects. |
|
|
988
|
+
| <a id="rust-command-shell"></a>[`rust-command-shell`](docs/rules/security/rust-command-shell.md) | high | Command::new("sh") or Command::new("bash") spawns a shell and risks command injection. |
|
|
989
|
+
| <a id="rust-reqwest-danger-accept-invalid-certs"></a>[`rust-reqwest-danger-accept-invalid-certs`](docs/rules/security/rust-reqwest-danger-accept-invalid-certs.md) | high | Calling danger_accept_invalid_certs(true) on a reqwest client disables TLS certificate verification. |
|
|
990
|
+
| <a id="rust-unsafe-raw-pointer-deref"></a>[`rust-unsafe-raw-pointer-deref`](docs/rules/security/rust-unsafe-raw-pointer-deref.md) | medium | A raw pointer dereference in an unsafe block bypasses Rust memory safety guarantees. |
|
|
984
991
|
|
|
985
992
|
<!-- loadwise:rules:end -->
|
|
986
993
|
|
|
987
994
|
## Dependency checks
|
|
988
995
|
|
|
989
|
-
`loadwise sec deps --online [directory]` reads `package-lock.json` (lockfile version 2 or 3), `pnpm-lock.yaml` or `yarn.lock` (version 1 or Berry) from the directory or the nearest parent that has one, and asks the [OSV database](https://osv.dev) (which includes the GitHub Advisory Database) about every pinned package version. It sends package names and versions and nothing else. Answers are cached for 24 hours in the `loadwise` folder of the OS cache directory. It takes `--format text|json` (or `--json`), `--include-contextual`, `--ignore` and `--fail-on`. A network failure exits 2 rather than passing. The network is opt-in: `loadwise sec --online` and `loadwise check --online` add these findings to their security report, and without `--online` they print one note that dependency checks were skipped.
|
|
996
|
+
`loadwise sec deps --online [directory]` reads `npm-shrinkwrap.json` in preference to `package-lock.json` (npm lockfile version 2 or 3), `pnpm-lock.yaml` or `yarn.lock` (version 1 or Berry) from the directory or the nearest parent that has one, and asks the [OSV database](https://osv.dev) (which includes the GitHub Advisory Database) about every pinned package version. It sends package names and versions and nothing else. Answers are cached for 24 hours in the `loadwise` folder of the OS cache directory. It takes `--format text|json` (or `--json`), `--include-contextual`, `--ignore` and `--fail-on`. A network failure exits 2 rather than passing. The network is opt-in: `loadwise sec --online` and `loadwise check --online` add these findings to their security report, and without `--online` they print one note that dependency checks were skipped.
|
|
990
997
|
|
|
991
998
|
<!-- loadwise:rules:start checker=security group=dependency-checks -->
|
|
992
999
|
|
|
@@ -1016,6 +1023,7 @@ npx loadwise a11y --fix --only <id> # apply one generated fix
|
|
|
1016
1023
|
|
|
1017
1024
|
| Rule | Impact | What it flags |
|
|
1018
1025
|
| -------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
1026
|
+
| <a id="a11y-aria-hidden-focus"></a>[`a11y-aria-hidden-focus`](docs/rules/accessibility/a11y-aria-hidden-focus.md) | high | A control in the Tab order is hidden from assistive technology by aria-hidden. |
|
|
1019
1027
|
| <a id="a11y-button-missing-type"></a>[`a11y-button-missing-type`](docs/rules/accessibility/a11y-button-missing-type.md) | medium | A button associated with a form has a click handler but no explicit type, so clicking it can also submit the form. |
|
|
1020
1028
|
| <a id="a11y-clickable-non-interactive"></a>[`a11y-clickable-non-interactive`](docs/rules/accessibility/a11y-clickable-non-interactive.md) | high | A click handler sits on a non-interactive element without a role and keyboard support, so keyboard users cannot activate it. |
|
|
1021
1029
|
| <a id="a11y-heading-level-skipped"></a>[`a11y-heading-level-skipped`](docs/rules/accessibility/a11y-heading-level-skipped.md) | low | A heading jumps more than one level down, which leaves a gap in the page outline. |
|
package/dist/bin/loadwise.js
CHANGED
|
@@ -74,43 +74,31 @@ Use loadwise fix --help for fix options.`;
|
|
|
74
74
|
// the scanners.
|
|
75
75
|
async function main(args) {
|
|
76
76
|
const [command, ...rest] = args;
|
|
77
|
-
if (command === 'perf')
|
|
78
|
-
return (await import('../lib/performance/cli.js')).main(rest);
|
|
79
|
-
if (command === 'rel')
|
|
80
|
-
return (await import('../lib/reliability/cli.js')).main(rest);
|
|
81
|
-
if (command === 'maint')
|
|
82
|
-
return (await import('../lib/maintainability/cli.js')).main(rest);
|
|
83
|
-
if (command === 'sec')
|
|
84
|
-
return (await import('../lib/security/cli.js')).main(rest);
|
|
85
|
-
if (command === 'a11y')
|
|
86
|
-
return (await import('../lib/accessibility/cli.js')).main(rest);
|
|
87
|
-
if (command === 'fix')
|
|
88
|
-
return (await import('../lib/shared/fix.js')).runFix(rest);
|
|
89
|
-
if (command === 'explain')
|
|
90
|
-
return (await import('../lib/shared/explain.js')).runExplain(rest);
|
|
91
|
-
if (command === 'report-fp')
|
|
92
|
-
return (await import('../lib/shared/report-fp.js')).runReportFp(rest);
|
|
93
|
-
if (command === 'lsp')
|
|
94
|
-
return (await import('../lib/editor/language-server.js')).runLanguageServer(rest);
|
|
95
|
-
if (command === 'editor')
|
|
96
|
-
return (await import('../lib/editor/setup.js')).runEditor(rest);
|
|
97
77
|
if (command === '--version' || command === '-v') {
|
|
98
78
|
if (rest.length)
|
|
99
79
|
throw new Error('Usage: loadwise --version');
|
|
100
80
|
console.log(version);
|
|
101
81
|
return 0;
|
|
102
82
|
}
|
|
103
|
-
if (command === 'agent')
|
|
104
|
-
return (await import('../lib/shared/agent/agent-init.js')).runAgentCommand(rest);
|
|
105
83
|
if (command === '--help' || command === '-h') {
|
|
106
84
|
console.log(usage);
|
|
107
85
|
return 0;
|
|
108
86
|
}
|
|
109
|
-
if (command === 'check' && rest.
|
|
87
|
+
if (command === 'check' && (rest.includes('--help') || rest.includes('-h'))) {
|
|
110
88
|
console.log(checkUsage);
|
|
111
89
|
return 0;
|
|
112
90
|
}
|
|
113
|
-
|
|
91
|
+
if (command === 'explain')
|
|
92
|
+
return (await import('../lib/shared/explain.js')).runExplain(rest);
|
|
93
|
+
if (command === 'report-fp')
|
|
94
|
+
return (await import('../lib/shared/report-fp.js')).runReportFp(rest);
|
|
95
|
+
if (command === 'lsp')
|
|
96
|
+
return (await import('../lib/editor/language-server.js')).runLanguageServer(rest);
|
|
97
|
+
if (command === 'editor')
|
|
98
|
+
return (await import('../lib/editor/setup.js')).runEditor(rest);
|
|
99
|
+
if (command === 'agent')
|
|
100
|
+
return (await import('../lib/shared/agent/agent-init.js')).runAgentCommand(rest);
|
|
101
|
+
return (await import('../lib/shared/cli-dispatch.js')).dispatch(args, checkUsage);
|
|
114
102
|
}
|
|
115
103
|
// perf, rel, maint, sec and a11y run in this process, whose default heap limit is too small for very large
|
|
116
104
|
// projects. One re-spawn with a larger limit keeps their output and exit code the same; a limit the
|
|
@@ -2,21 +2,23 @@ import { isVendoredMinified } from '../shared/analysis/execution-context.js';
|
|
|
2
2
|
import { relativeToProject, reviewedReason, reviewMarkers } from '../performance/analysis/review-context.js';
|
|
3
3
|
import { jsxDocument } from './jsx-elements.js';
|
|
4
4
|
import { inlineAngularTemplates } from './angular-inline.js';
|
|
5
|
+
import { contextualizeFrameViewports } from './frame-viewport.js';
|
|
5
6
|
import { checkMarkup } from './rules.js';
|
|
6
|
-
const angularDecorator = '@Component';
|
|
7
7
|
function analyzeFile(program, sourceFile) {
|
|
8
8
|
if (sourceFile.isDeclarationFile || isVendoredMinified(sourceFile.fileName))
|
|
9
9
|
return [];
|
|
10
10
|
const hasJsx = /\.[jt]sx$/i.test(sourceFile.fileName);
|
|
11
|
-
const hasAngularComponent = sourceFile.text.includes(
|
|
11
|
+
const hasAngularComponent = sourceFile.text.includes('@angular/core') && sourceFile.text.includes('template');
|
|
12
12
|
if (!hasJsx && !hasAngularComponent)
|
|
13
13
|
return [];
|
|
14
14
|
const file = relativeToProject(sourceFile.fileName).split('\\').join('/');
|
|
15
15
|
const documents = [
|
|
16
16
|
...(hasJsx ? [jsxDocument(sourceFile, file, program.getTypeChecker())] : []),
|
|
17
|
-
...(hasAngularComponent ? inlineAngularTemplates(sourceFile, file) : []),
|
|
17
|
+
...(hasAngularComponent ? inlineAngularTemplates(sourceFile, file, program.getTypeChecker()) : []),
|
|
18
18
|
];
|
|
19
19
|
const findings = documents.flatMap((document) => checkMarkup(document));
|
|
20
|
+
if (hasJsx)
|
|
21
|
+
contextualizeFrameViewports(findings, sourceFile, program);
|
|
20
22
|
const hasReviewComments = reviewMarkers.some((marker) => sourceFile.text.includes(marker));
|
|
21
23
|
return findings.map((finding) => {
|
|
22
24
|
const reason = hasReviewComments ? reviewedReason(sourceFile, (finding.line ?? 1) - 1, finding.ruleId) : undefined;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ts } from '../performance/engine/compiler.js';
|
|
2
2
|
import { walkNodes } from '../reliability/walk.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
function componentOptions(node) {
|
|
3
|
+
import { angularLiteralDocument } from './angular-literal.js';
|
|
4
|
+
import { ANGULAR_MODULES, importedName } from '../performance/frontend/frontend-helpers.js';
|
|
5
|
+
function componentOptions(node, checker) {
|
|
6
6
|
if (!ts.isDecorator(node) || !ts.isCallExpression(node.expression))
|
|
7
7
|
return undefined;
|
|
8
8
|
const call = node.expression;
|
|
9
|
-
if (
|
|
9
|
+
if (importedName(call.expression, checker, ANGULAR_MODULES) !== 'Component')
|
|
10
10
|
return undefined;
|
|
11
11
|
return call.arguments[0];
|
|
12
12
|
}
|
|
@@ -25,18 +25,16 @@ function templateLiteral(options) {
|
|
|
25
25
|
}
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
* Parses each static inline template with the Angular dialect. The region is the literal's raw source between its
|
|
30
|
-
* quotes, so positions point into the .ts file.
|
|
31
|
-
*/
|
|
32
|
-
function inlineAngularTemplates(sourceFile, file) {
|
|
28
|
+
function inlineAngularTemplates(sourceFile, file, checker) {
|
|
33
29
|
const documents = [];
|
|
34
30
|
walkNodes(sourceFile, (node) => {
|
|
35
|
-
const options = componentOptions(node);
|
|
31
|
+
const options = componentOptions(node, checker);
|
|
36
32
|
const literal = options && templateLiteral(options);
|
|
37
33
|
if (!literal)
|
|
38
34
|
return;
|
|
39
|
-
|
|
35
|
+
const document = angularLiteralDocument(file, sourceFile, literal);
|
|
36
|
+
if (document)
|
|
37
|
+
documents.push(document);
|
|
40
38
|
});
|
|
41
39
|
return documents;
|
|
42
40
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mappedAngularDocument, templateDocument } from './template-elements.js';
|
|
2
|
+
// A TypeScript escape consumes one cooked UTF-16 unit except for line continuations (zero)
|
|
3
|
+
// and a braced Unicode code point outside the BMP (two). CRLF in a template cooks to LF.
|
|
4
|
+
const sourceEscape = /\\(?:\r\n|u\{[\da-fA-F]+\}|u[\da-fA-F]{4}|x[\da-fA-F]{2}|[0-3][0-7]{0,2}|[4-7][0-7]?|[\s\S])|\r\n?/g;
|
|
5
|
+
function cookedWidth(spelling) {
|
|
6
|
+
if (/^\\[\r\n\u2028\u2029]/.test(spelling))
|
|
7
|
+
return 0;
|
|
8
|
+
if (spelling.startsWith('\\u{') && Number.parseInt(spelling.slice(3, -1), 16) > 0xffff)
|
|
9
|
+
return 2;
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
function angularLiteralDocument(file, sourceFile, literal) {
|
|
13
|
+
const start = literal.getStart(sourceFile) + 1;
|
|
14
|
+
const end = literal.getEnd() - 1;
|
|
15
|
+
const raw = sourceFile.text.slice(start, end);
|
|
16
|
+
if (raw === literal.text)
|
|
17
|
+
return templateDocument(file, sourceFile.text, 'angular', start, end);
|
|
18
|
+
const sourceOffsets = [];
|
|
19
|
+
let rawOffset = 0;
|
|
20
|
+
for (const escape of raw.matchAll(sourceEscape)) {
|
|
21
|
+
while (rawOffset < escape.index)
|
|
22
|
+
sourceOffsets.push(start + rawOffset++);
|
|
23
|
+
for (let unit = 0; unit < cookedWidth(escape[0]); unit++)
|
|
24
|
+
sourceOffsets.push(start + rawOffset);
|
|
25
|
+
rawOffset += escape[0].length;
|
|
26
|
+
}
|
|
27
|
+
while (rawOffset < raw.length)
|
|
28
|
+
sourceOffsets.push(start + rawOffset++);
|
|
29
|
+
// Invalid/unfinished literals can appear in editor buffers. Suppress uncertain locations.
|
|
30
|
+
if (sourceOffsets.length !== literal.text.length)
|
|
31
|
+
return;
|
|
32
|
+
sourceOffsets.push(end);
|
|
33
|
+
const positionAt = (cookedOffset) => {
|
|
34
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(sourceOffsets[cookedOffset]);
|
|
35
|
+
return { line: line + 1, column: character + 1 };
|
|
36
|
+
};
|
|
37
|
+
return mappedAngularDocument(file, literal.text, positionAt);
|
|
38
|
+
}
|
|
39
|
+
export { angularLiteralDocument };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { attributeNamed, staticAttributeText, walkElements } from './markup.js';
|
|
2
|
+
function isLabelLike(element) {
|
|
3
|
+
return element.tagName === 'label' || !element.isIntrinsic;
|
|
4
|
+
}
|
|
5
|
+
// Labels of components count too: a `<Label htmlFor="x">` names the control with that id just as a `<label>` does.
|
|
6
|
+
function formAndLabelTargets(document) {
|
|
7
|
+
const formsById = new Map();
|
|
8
|
+
const labelledIds = new Set();
|
|
9
|
+
let hasDynamicLabelFor = false;
|
|
10
|
+
for (const element of walkElements(document.roots)) {
|
|
11
|
+
if (element.isIntrinsic && element.tagName === 'form') {
|
|
12
|
+
const id = staticAttributeText(element, 'id');
|
|
13
|
+
if (id)
|
|
14
|
+
formsById.set(id, formsById.has(id) ? undefined : element);
|
|
15
|
+
}
|
|
16
|
+
const target = isLabelLike(element) ? attributeNamed(element, 'for') : undefined;
|
|
17
|
+
if (target?.value.kind === 'static')
|
|
18
|
+
labelledIds.add(target.value.text);
|
|
19
|
+
else if (target)
|
|
20
|
+
hasDynamicLabelFor = true;
|
|
21
|
+
}
|
|
22
|
+
return { labelledIds, hasDynamicLabelFor, formsById };
|
|
23
|
+
}
|
|
24
|
+
function formMayDisableAutocomplete(element, { ancestors, formsById }) {
|
|
25
|
+
const form = attributeNamed(element, 'form');
|
|
26
|
+
if (form?.value.kind === 'dynamic')
|
|
27
|
+
return true;
|
|
28
|
+
const owner = form?.value.kind === 'static'
|
|
29
|
+
? formsById.get(form.value.text)
|
|
30
|
+
: ancestors.findLast((ancestor) => ancestor.isIntrinsic && ancestor.tagName === 'form');
|
|
31
|
+
if (!owner)
|
|
32
|
+
return !!form;
|
|
33
|
+
const policy = attributeNamed(owner, 'autocomplete');
|
|
34
|
+
return (owner.hasSpreadAttributes || policy?.value.kind === 'dynamic' || policy?.value.text.trim().toLowerCase() === 'off');
|
|
35
|
+
}
|
|
36
|
+
export { formAndLabelTargets, formMayDisableAutocomplete };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ts } from '../performance/engine/compiler.js';
|
|
2
|
+
import { importedFrom } from '../security/bindings.js';
|
|
3
|
+
import { walkNodes } from '../reliability/walk.js';
|
|
4
|
+
function isContentDocument(value) {
|
|
5
|
+
return ts.isPropertyAccessExpression(value) && value.name.text === 'contentDocument';
|
|
6
|
+
}
|
|
7
|
+
function initializedFromFrame(value, checker) {
|
|
8
|
+
if (isContentDocument(value))
|
|
9
|
+
return true;
|
|
10
|
+
if (!ts.isIdentifier(value))
|
|
11
|
+
return false;
|
|
12
|
+
const declaration = checker.getSymbolAtLocation(value)?.valueDeclaration;
|
|
13
|
+
return (!!declaration &&
|
|
14
|
+
ts.isVariableDeclaration(declaration) &&
|
|
15
|
+
!!(declaration.parent.flags & ts.NodeFlags.Const) &&
|
|
16
|
+
!!declaration.initializer &&
|
|
17
|
+
isContentDocument(declaration.initializer));
|
|
18
|
+
}
|
|
19
|
+
function stateInitializer(binding, checker) {
|
|
20
|
+
if (!ts.isVariableDeclaration(binding) || !binding.initializer || !ts.isCallExpression(binding.initializer))
|
|
21
|
+
return;
|
|
22
|
+
const hook = importedFrom(binding.initializer.expression, checker);
|
|
23
|
+
if (hook?.exported !== 'useState' || !['react', 'preact/hooks'].includes(hook.module))
|
|
24
|
+
return;
|
|
25
|
+
const initial = binding.initializer.arguments[0];
|
|
26
|
+
return !initial || initial.kind === ts.SyntaxKind.NullKeyword ? null : initial;
|
|
27
|
+
}
|
|
28
|
+
function frameDocumentState(value, component, checker) {
|
|
29
|
+
if (!ts.isIdentifier(value))
|
|
30
|
+
return false;
|
|
31
|
+
const binding = checker.getSymbolAtLocation(value)?.valueDeclaration;
|
|
32
|
+
if (!binding || !ts.isBindingElement(binding) || !ts.isArrayBindingPattern(binding.parent))
|
|
33
|
+
return false;
|
|
34
|
+
const [document, setter] = binding.parent.elements;
|
|
35
|
+
if (binding !== document || !setter || !ts.isBindingElement(setter) || !ts.isIdentifier(setter.name))
|
|
36
|
+
return false;
|
|
37
|
+
const setterSymbol = checker.getSymbolAtLocation(setter.name);
|
|
38
|
+
const initial = stateInitializer(binding.parent.parent, checker);
|
|
39
|
+
if (initial === undefined || (initial && !initializedFromFrame(initial, checker)))
|
|
40
|
+
return false;
|
|
41
|
+
let assignedFrame = !!initial;
|
|
42
|
+
let assignedOther = false;
|
|
43
|
+
walkNodes(component, (node) => {
|
|
44
|
+
if (!ts.isIdentifier(node) || node === setter.name || checker.getSymbolAtLocation(node) !== setterSymbol)
|
|
45
|
+
return;
|
|
46
|
+
const call = node.parent;
|
|
47
|
+
if (!ts.isCallExpression(call) || call.expression !== node) {
|
|
48
|
+
assignedOther = true;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const [next] = call.arguments;
|
|
52
|
+
if (next && initializedFromFrame(next, checker))
|
|
53
|
+
assignedFrame = true;
|
|
54
|
+
else
|
|
55
|
+
assignedOther = true;
|
|
56
|
+
});
|
|
57
|
+
return assignedFrame && !assignedOther;
|
|
58
|
+
}
|
|
59
|
+
function frameHeadProperty(value) {
|
|
60
|
+
return ts.isPropertyAccessExpression(value) && value.name.text === 'head' && isContentDocument(value.expression);
|
|
61
|
+
}
|
|
62
|
+
function frameHeadField(component, field) {
|
|
63
|
+
const property = component.members.find((member) => ts.isPropertyDeclaration(member) && ts.isIdentifier(member.name) && member.name.text === field);
|
|
64
|
+
const initial = property && ts.isPropertyDeclaration(property) ? property.initializer : undefined;
|
|
65
|
+
if (initial && initial.kind !== ts.SyntaxKind.NullKeyword && !frameHeadProperty(initial))
|
|
66
|
+
return false;
|
|
67
|
+
let assignedFrame = !!initial && frameHeadProperty(initial);
|
|
68
|
+
let assignedOther = false;
|
|
69
|
+
walkNodes(component, (node) => {
|
|
70
|
+
if (!ts.isBinaryExpression(node) || node.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
71
|
+
return;
|
|
72
|
+
const { left, right } = node;
|
|
73
|
+
if (!ts.isPropertyAccessExpression(left) ||
|
|
74
|
+
left.expression.kind !== ts.SyntaxKind.ThisKeyword ||
|
|
75
|
+
left.name.text !== field)
|
|
76
|
+
return;
|
|
77
|
+
if (frameHeadProperty(right))
|
|
78
|
+
assignedFrame = true;
|
|
79
|
+
else
|
|
80
|
+
assignedOther = true;
|
|
81
|
+
});
|
|
82
|
+
return assignedFrame && !assignedOther;
|
|
83
|
+
}
|
|
84
|
+
export function isFrameHead(value, component, checker) {
|
|
85
|
+
if (!ts.isPropertyAccessExpression(value))
|
|
86
|
+
return false;
|
|
87
|
+
if (value.name.text === 'head')
|
|
88
|
+
return initializedFromFrame(value.expression, checker) || frameDocumentState(value.expression, component, checker);
|
|
89
|
+
return (ts.isClassDeclaration(component) &&
|
|
90
|
+
value.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
91
|
+
frameHeadField(component, value.name.text));
|
|
92
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ts } from '../performance/engine/compiler.js';
|
|
3
|
+
import { importedFrom } from '../security/bindings.js';
|
|
4
|
+
import { walkNodes } from '../reliability/walk.js';
|
|
5
|
+
import { isFrameHead } from './frame-head.js';
|
|
6
|
+
function defaultComponent(file, checker) {
|
|
7
|
+
for (const statement of file.statements) {
|
|
8
|
+
if ((ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement)) &&
|
|
9
|
+
statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword))
|
|
10
|
+
return statement;
|
|
11
|
+
if (!ts.isExportAssignment(statement) || !ts.isIdentifier(statement.expression))
|
|
12
|
+
continue;
|
|
13
|
+
const declaration = checker.getSymbolAtLocation(statement.expression)?.valueDeclaration;
|
|
14
|
+
if (!declaration || declaration.getSourceFile() !== file)
|
|
15
|
+
return;
|
|
16
|
+
if (ts.isClassDeclaration(declaration) || ts.isFunctionDeclaration(declaration))
|
|
17
|
+
return declaration;
|
|
18
|
+
if (!ts.isVariableDeclaration(declaration) || !declaration.initializer)
|
|
19
|
+
return;
|
|
20
|
+
const initializer = declaration.initializer;
|
|
21
|
+
if (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))
|
|
22
|
+
return initializer;
|
|
23
|
+
if (!ts.isCallExpression(initializer))
|
|
24
|
+
return;
|
|
25
|
+
const wrapper = importedFrom(initializer.expression, checker);
|
|
26
|
+
const render = initializer.arguments[0];
|
|
27
|
+
if (wrapper?.module !== 'react' || wrapper.exported !== 'forwardRef' || !render || !ts.isFunctionExpression(render))
|
|
28
|
+
return;
|
|
29
|
+
const [returned] = render.body.statements;
|
|
30
|
+
if (render.body.statements.length !== 1 || !ts.isReturnStatement(returned) || !returned.expression)
|
|
31
|
+
return;
|
|
32
|
+
const element = ts.skipOuterExpressions(returned.expression);
|
|
33
|
+
if (!ts.isJsxSelfClosingElement(element) || !ts.isIdentifier(element.tagName))
|
|
34
|
+
return;
|
|
35
|
+
const inner = checker.getSymbolAtLocation(element.tagName)?.valueDeclaration;
|
|
36
|
+
if (inner?.getSourceFile() === file && (ts.isClassDeclaration(inner) || ts.isFunctionDeclaration(inner)))
|
|
37
|
+
return inner;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function belongsToComponent(node, component) {
|
|
41
|
+
for (let parent = node.parent; parent && parent !== component; parent = parent.parent) {
|
|
42
|
+
if (ts.isFunctionDeclaration(parent) || ts.isClassLike(parent))
|
|
43
|
+
return false;
|
|
44
|
+
if ((ts.isFunctionExpression(parent) || ts.isArrowFunction(parent)) && ts.isVariableDeclaration(parent.parent))
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const viewportRule = 'a11y-viewport-zoom-disabled';
|
|
50
|
+
function isFrameModule(module, sourceFile, program) {
|
|
51
|
+
if (module === 'react-frame-component')
|
|
52
|
+
return true;
|
|
53
|
+
if (!module.startsWith('.'))
|
|
54
|
+
return false;
|
|
55
|
+
const target = path.resolve(path.dirname(sourceFile.fileName), module).replace(/\.[cm]?[jt]sx?$/, '');
|
|
56
|
+
const implementation = program
|
|
57
|
+
.getSourceFiles?.()
|
|
58
|
+
.find((candidate) => path.normalize(candidate.fileName).replace(/\.[cm]?[jt]sx?$/, '') === target);
|
|
59
|
+
if (!implementation || !implementation.text.includes('iframe'))
|
|
60
|
+
return false;
|
|
61
|
+
const checker = program.getTypeChecker();
|
|
62
|
+
const component = defaultComponent(implementation, checker);
|
|
63
|
+
if (!component)
|
|
64
|
+
return false;
|
|
65
|
+
let hasIframe = false;
|
|
66
|
+
let rendersHead = false;
|
|
67
|
+
walkNodes(component, (node) => {
|
|
68
|
+
if (!belongsToComponent(node, component))
|
|
69
|
+
return;
|
|
70
|
+
if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
|
|
71
|
+
ts.isIdentifier(node.tagName) &&
|
|
72
|
+
node.tagName.text === 'iframe')
|
|
73
|
+
hasIframe = true;
|
|
74
|
+
if (!ts.isCallExpression(node) || node.arguments.length < 2)
|
|
75
|
+
return;
|
|
76
|
+
const [head, container] = node.arguments;
|
|
77
|
+
if (!ts.isIdentifier(head) || head.text !== 'head' || !isFrameHead(container, component, checker))
|
|
78
|
+
return;
|
|
79
|
+
const render = importedFrom(node.expression, checker);
|
|
80
|
+
if ((render?.module === 'react-dom' && render.exported === 'createPortal') ||
|
|
81
|
+
(render?.module === 'preact' && render.exported === 'render'))
|
|
82
|
+
rendersHead = true;
|
|
83
|
+
});
|
|
84
|
+
return hasIframe && rendersHead;
|
|
85
|
+
}
|
|
86
|
+
// Common head slots contain a JSX literal, a local fragment variable, or a local method/component result.
|
|
87
|
+
function headSource(value, checker, sourceFile) {
|
|
88
|
+
const expression = ts.skipOuterExpressions(value);
|
|
89
|
+
const reference = ts.isCallExpression(expression)
|
|
90
|
+
? expression.expression
|
|
91
|
+
: ts.isJsxSelfClosingElement(expression)
|
|
92
|
+
? expression.tagName
|
|
93
|
+
: expression;
|
|
94
|
+
const name = ts.isPropertyAccessExpression(reference) ? reference.name : reference;
|
|
95
|
+
if (!ts.isIdentifier(name))
|
|
96
|
+
return expression;
|
|
97
|
+
const declaration = checker.getSymbolAtLocation(name)?.declarations?.[0];
|
|
98
|
+
if (!declaration || declaration.getSourceFile() !== sourceFile)
|
|
99
|
+
return;
|
|
100
|
+
// A value also consumed by ordinary page code is not exclusively a frame head.
|
|
101
|
+
let shared = false;
|
|
102
|
+
walkNodes(sourceFile, (use) => {
|
|
103
|
+
if (shared || use === name || use.parent === declaration || !ts.isIdentifier(use) || use.text !== name.text)
|
|
104
|
+
return;
|
|
105
|
+
if (checker.getSymbolAtLocation(use)?.declarations?.includes(declaration))
|
|
106
|
+
shared = true;
|
|
107
|
+
});
|
|
108
|
+
if (shared)
|
|
109
|
+
return;
|
|
110
|
+
if (ts.isVariableDeclaration(declaration) && declaration.parent.flags & ts.NodeFlags.Const)
|
|
111
|
+
return declaration.initializer;
|
|
112
|
+
if (ts.isMethodDeclaration(declaration) || ts.isFunctionDeclaration(declaration)) {
|
|
113
|
+
const returned = declaration.body?.statements.filter(ts.isReturnStatement);
|
|
114
|
+
if (returned?.length === 1)
|
|
115
|
+
return returned[0].expression;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function contextualizeFrameViewports(findings, sourceFile, program) {
|
|
119
|
+
const viewports = findings.filter((finding) => finding.ruleId === viewportRule);
|
|
120
|
+
if (!viewports.length || !sourceFile.text.includes('head'))
|
|
121
|
+
return;
|
|
122
|
+
const checker = program.getTypeChecker();
|
|
123
|
+
const headSources = [];
|
|
124
|
+
walkNodes(sourceFile, (node) => {
|
|
125
|
+
if (!ts.isJsxAttribute(node) || node.name.getText(sourceFile) !== 'head')
|
|
126
|
+
return;
|
|
127
|
+
const owner = node.parent.parent.tagName;
|
|
128
|
+
const binding = importedFrom(owner, checker);
|
|
129
|
+
if (binding?.exported !== 'default' || !isFrameModule(binding.module, sourceFile, program))
|
|
130
|
+
return;
|
|
131
|
+
const value = node.initializer;
|
|
132
|
+
if (!value || !ts.isJsxExpression(value) || !value.expression)
|
|
133
|
+
return;
|
|
134
|
+
const head = headSource(value.expression, checker, sourceFile);
|
|
135
|
+
if (head)
|
|
136
|
+
headSources.push(head);
|
|
137
|
+
});
|
|
138
|
+
for (const finding of viewports) {
|
|
139
|
+
if (!finding.line || !finding.column)
|
|
140
|
+
continue;
|
|
141
|
+
const position = sourceFile.getPositionOfLineAndCharacter(finding.line - 1, finding.column - 1);
|
|
142
|
+
if (!headSources.some((head) => head.pos <= position && position < head.end))
|
|
143
|
+
continue;
|
|
144
|
+
finding.contextualReason = 'This viewport declaration is supplied to a frame component’s head.';
|
|
145
|
+
finding.message +=
|
|
146
|
+
' This head is passed to a frame component. Check the embedded document independently of its host page.';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export { contextualizeFrameViewports };
|
|
@@ -21,7 +21,8 @@ function staticExpressionText(expression) {
|
|
|
21
21
|
ts.isNumericLiteral(inner.operand);
|
|
22
22
|
return isNegatedNumber ? `-${inner.operand.text}` : undefined;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const nativeBooleans = new Set(['autoplay', 'controls', 'disabled', 'hidden', 'inert', 'muted', 'open', 'readonly']);
|
|
25
|
+
function attributeValue(attribute, name) {
|
|
25
26
|
const initializer = attribute.initializer;
|
|
26
27
|
if (!initializer)
|
|
27
28
|
return { kind: 'static', text: '' };
|
|
@@ -29,10 +30,12 @@ function attributeValue(attribute) {
|
|
|
29
30
|
return { kind: 'static', text: initializer.text };
|
|
30
31
|
if (!ts.isJsxExpression(initializer) || !initializer.expression)
|
|
31
32
|
return { kind: 'dynamic' };
|
|
32
|
-
//
|
|
33
|
+
// Native boolean false is omitted below; ARIA booleans are serialized as explicit tokens.
|
|
33
34
|
if (unwrapExpression(initializer.expression).kind === ts.SyntaxKind.TrueKeyword) {
|
|
34
35
|
return { kind: 'static', text: 'true' };
|
|
35
36
|
}
|
|
37
|
+
if (name.startsWith('aria-') && unwrapExpression(initializer.expression).kind === ts.SyntaxKind.FalseKeyword)
|
|
38
|
+
return { kind: 'static', text: 'false' };
|
|
36
39
|
const text = staticExpressionText(initializer.expression);
|
|
37
40
|
return text === undefined ? { kind: 'dynamic' } : { kind: 'static', text };
|
|
38
41
|
}
|
|
@@ -103,13 +106,20 @@ function translateAttributes(sourceFile, attributeNodes, checker) {
|
|
|
103
106
|
continue;
|
|
104
107
|
}
|
|
105
108
|
const name = htmlAttributeName(attribute.name.getText(sourceFile));
|
|
109
|
+
const initializer = attribute.initializer;
|
|
110
|
+
if (nativeBooleans.has(name) &&
|
|
111
|
+
initializer &&
|
|
112
|
+
ts.isJsxExpression(initializer) &&
|
|
113
|
+
initializer.expression &&
|
|
114
|
+
unwrapExpression(initializer.expression).kind === ts.SyntaxKind.FalseKeyword)
|
|
115
|
+
continue;
|
|
106
116
|
if (name === 'onclick' && isPropagationOnlyHandler(attribute))
|
|
107
117
|
continue;
|
|
108
118
|
if (name === 'autoplay' && isFalsyAutoplay(attribute))
|
|
109
119
|
continue;
|
|
110
120
|
if ((name === 'alt' || name === 'title') && isOmittedTextAttribute(attribute, checker))
|
|
111
121
|
continue;
|
|
112
|
-
attributes.push({ name, value: attributeValue(attribute), ...position(sourceFile, attribute.name) });
|
|
122
|
+
attributes.push({ name, value: attributeValue(attribute, name), ...position(sourceFile, attribute.name) });
|
|
113
123
|
}
|
|
114
124
|
return { attributes, hasSpreadAttributes };
|
|
115
125
|
}
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import { isVendoredMinified } from '../shared/analysis/execution-context.js';
|
|
7
7
|
import { recordSkippedFile } from '../shared/reporting/coverage-notes.js';
|
|
8
8
|
import { listFrontendCandidateFiles } from './frontend-detect.js';
|
|
9
|
-
import {
|
|
9
|
+
import { analyzeTemplateFile } from './template-file.js';
|
|
10
10
|
const markupFilePattern = /\.(?:html?|vue|svelte)$/i;
|
|
11
11
|
function isMarkupFile(filename) {
|
|
12
12
|
return markupFilePattern.test(filename);
|
|
@@ -23,7 +23,12 @@ function findingsOfFile(absolute, skippedFiles) {
|
|
|
23
23
|
try {
|
|
24
24
|
// The absolute path lets Angular .html templates find their component's sibling .ts file; findings report the path
|
|
25
25
|
// relative to the working directory, as program findings do.
|
|
26
|
-
|
|
26
|
+
const result = analyzeTemplateFile(absolute, fs.readFileSync(absolute, 'utf8'));
|
|
27
|
+
if (result.skipReason) {
|
|
28
|
+
recordSkippedFile(skippedFiles, { file, reason: result.skipReason }, `The accessibility analysis of ${file} was skipped (${result.skipReason}).`);
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return result.findings.map((finding) => ({ ...finding, file }));
|
|
27
32
|
}
|
|
28
33
|
catch (error) {
|
|
29
34
|
const message = error instanceof Error ? error.message : String(error);
|