eslint-plugin-secure-coding 2.3.2 → 2.3.3
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 +1 -0
- package/package.json +3 -10
- package/src/index.ts +605 -0
- package/src/rules/__tests__/integration-demo.test.ts +290 -0
- package/src/rules/__tests__/integration-llm.test.ts +89 -0
- package/src/rules/database-injection/database-injection.test.ts +456 -0
- package/src/rules/database-injection/index.ts +488 -0
- package/src/rules/detect-child-process/detect-child-process.test.ts +207 -0
- package/src/rules/detect-child-process/index.ts +634 -0
- package/src/rules/detect-eval-with-expression/detect-eval-with-expression.test.ts +416 -0
- package/src/rules/detect-eval-with-expression/index.ts +463 -0
- package/src/rules/detect-mixed-content/detect-mixed-content.test.ts +28 -0
- package/src/rules/detect-mixed-content/index.ts +52 -0
- package/src/rules/detect-non-literal-fs-filename/detect-non-literal-fs-filename.test.ts +269 -0
- package/src/rules/detect-non-literal-fs-filename/index.ts +551 -0
- package/src/rules/detect-non-literal-regexp/detect-non-literal-regexp.test.ts +189 -0
- package/src/rules/detect-non-literal-regexp/index.ts +490 -0
- package/src/rules/detect-object-injection/detect-object-injection.test.ts +440 -0
- package/src/rules/detect-object-injection/index.ts +674 -0
- package/src/rules/detect-suspicious-dependencies/detect-suspicious-dependencies.test.ts +32 -0
- package/src/rules/detect-suspicious-dependencies/index.ts +84 -0
- package/src/rules/detect-weak-password-validation/detect-weak-password-validation.test.ts +31 -0
- package/src/rules/detect-weak-password-validation/index.ts +68 -0
- package/src/rules/no-allow-arbitrary-loads/index.ts +54 -0
- package/src/rules/no-allow-arbitrary-loads/no-allow-arbitrary-loads.test.ts +28 -0
- package/src/rules/no-arbitrary-file-access/index.ts +238 -0
- package/src/rules/no-arbitrary-file-access/no-arbitrary-file-access.test.ts +119 -0
- package/src/rules/no-buffer-overread/index.ts +724 -0
- package/src/rules/no-buffer-overread/no-buffer-overread.test.ts +313 -0
- package/src/rules/no-clickjacking/index.ts +481 -0
- package/src/rules/no-clickjacking/no-clickjacking.test.ts +253 -0
- package/src/rules/no-client-side-auth-logic/index.ts +81 -0
- package/src/rules/no-client-side-auth-logic/no-client-side-auth-logic.test.ts +33 -0
- package/src/rules/no-credentials-in-query-params/index.ts +69 -0
- package/src/rules/no-credentials-in-query-params/no-credentials-in-query-params.test.ts +33 -0
- package/src/rules/no-credentials-in-storage-api/index.ts +64 -0
- package/src/rules/no-credentials-in-storage-api/no-credentials-in-storage-api.test.ts +31 -0
- package/src/rules/no-data-in-temp-storage/index.ts +75 -0
- package/src/rules/no-data-in-temp-storage/no-data-in-temp-storage.test.ts +33 -0
- package/src/rules/no-debug-code-in-production/index.ts +59 -0
- package/src/rules/no-debug-code-in-production/no-debug-code-in-production.test.ts +26 -0
- package/src/rules/no-directive-injection/index.ts +551 -0
- package/src/rules/no-directive-injection/no-directive-injection.test.ts +305 -0
- package/src/rules/no-disabled-certificate-validation/index.ts +72 -0
- package/src/rules/no-disabled-certificate-validation/no-disabled-certificate-validation.test.ts +33 -0
- package/src/rules/no-document-cookie/index.ts +113 -0
- package/src/rules/no-document-cookie/no-document-cookie.test.ts +382 -0
- package/src/rules/no-dynamic-dependency-loading/index.ts +60 -0
- package/src/rules/no-dynamic-dependency-loading/no-dynamic-dependency-loading.test.ts +27 -0
- package/src/rules/no-electron-security-issues/index.ts +504 -0
- package/src/rules/no-electron-security-issues/no-electron-security-issues.test.ts +324 -0
- package/src/rules/no-exposed-debug-endpoints/index.ts +73 -0
- package/src/rules/no-exposed-debug-endpoints/no-exposed-debug-endpoints.test.ts +40 -0
- package/src/rules/no-exposed-sensitive-data/index.ts +428 -0
- package/src/rules/no-exposed-sensitive-data/no-exposed-sensitive-data.test.ts +75 -0
- package/src/rules/no-format-string-injection/index.ts +801 -0
- package/src/rules/no-format-string-injection/no-format-string-injection.test.ts +437 -0
- package/src/rules/no-graphql-injection/index.ts +508 -0
- package/src/rules/no-graphql-injection/no-graphql-injection.test.ts +371 -0
- package/src/rules/no-hardcoded-credentials/index.ts +478 -0
- package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +639 -0
- package/src/rules/no-hardcoded-session-tokens/index.ts +69 -0
- package/src/rules/no-hardcoded-session-tokens/no-hardcoded-session-tokens.test.ts +42 -0
- package/src/rules/no-http-urls/index.ts +131 -0
- package/src/rules/no-http-urls/no-http-urls.test.ts +60 -0
- package/src/rules/no-improper-sanitization/index.ts +502 -0
- package/src/rules/no-improper-sanitization/no-improper-sanitization.test.ts +156 -0
- package/src/rules/no-improper-type-validation/index.ts +572 -0
- package/src/rules/no-improper-type-validation/no-improper-type-validation.test.ts +372 -0
- package/src/rules/no-insecure-comparison/index.ts +232 -0
- package/src/rules/no-insecure-comparison/no-insecure-comparison.test.ts +218 -0
- package/src/rules/no-insecure-cookie-settings/index.ts +391 -0
- package/src/rules/no-insecure-cookie-settings/no-insecure-cookie-settings.test.ts +409 -0
- package/src/rules/no-insecure-jwt/index.ts +467 -0
- package/src/rules/no-insecure-jwt/no-insecure-jwt.test.ts +259 -0
- package/src/rules/no-insecure-redirects/index.ts +267 -0
- package/src/rules/no-insecure-redirects/no-insecure-redirects.test.ts +108 -0
- package/src/rules/no-insecure-websocket/index.ts +72 -0
- package/src/rules/no-insecure-websocket/no-insecure-websocket.test.ts +42 -0
- package/src/rules/no-insufficient-postmessage-validation/index.ts +497 -0
- package/src/rules/no-insufficient-postmessage-validation/no-insufficient-postmessage-validation.test.ts +360 -0
- package/src/rules/no-insufficient-random/index.ts +288 -0
- package/src/rules/no-insufficient-random/no-insufficient-random.test.ts +246 -0
- package/src/rules/no-ldap-injection/index.ts +547 -0
- package/src/rules/no-ldap-injection/no-ldap-injection.test.ts +317 -0
- package/src/rules/no-missing-authentication/index.ts +408 -0
- package/src/rules/no-missing-authentication/no-missing-authentication.test.ts +350 -0
- package/src/rules/no-missing-cors-check/index.ts +453 -0
- package/src/rules/no-missing-cors-check/no-missing-cors-check.test.ts +392 -0
- package/src/rules/no-missing-csrf-protection/index.ts +229 -0
- package/src/rules/no-missing-csrf-protection/no-missing-csrf-protection.test.ts +222 -0
- package/src/rules/no-missing-security-headers/index.ts +266 -0
- package/src/rules/no-missing-security-headers/no-missing-security-headers.test.ts +98 -0
- package/src/rules/no-password-in-url/index.ts +64 -0
- package/src/rules/no-password-in-url/no-password-in-url.test.ts +27 -0
- package/src/rules/no-permissive-cors/index.ts +78 -0
- package/src/rules/no-permissive-cors/no-permissive-cors.test.ts +28 -0
- package/src/rules/no-pii-in-logs/index.ts +83 -0
- package/src/rules/no-pii-in-logs/no-pii-in-logs.test.ts +26 -0
- package/src/rules/no-postmessage-origin-wildcard/index.ts +67 -0
- package/src/rules/no-postmessage-origin-wildcard/no-postmessage-origin-wildcard.test.ts +27 -0
- package/src/rules/no-privilege-escalation/index.ts +403 -0
- package/src/rules/no-privilege-escalation/no-privilege-escalation.test.ts +306 -0
- package/src/rules/no-redos-vulnerable-regex/index.ts +379 -0
- package/src/rules/no-redos-vulnerable-regex/no-redos-vulnerable-regex.test.ts +83 -0
- package/src/rules/no-sensitive-data-exposure/index.ts +294 -0
- package/src/rules/no-sensitive-data-exposure/no-sensitive-data-exposure.test.ts +262 -0
- package/src/rules/no-sensitive-data-in-analytics/index.ts +73 -0
- package/src/rules/no-sensitive-data-in-analytics/no-sensitive-data-in-analytics.test.ts +42 -0
- package/src/rules/no-sensitive-data-in-cache/index.ts +59 -0
- package/src/rules/no-sensitive-data-in-cache/no-sensitive-data-in-cache.test.ts +32 -0
- package/src/rules/no-sql-injection/index.ts +424 -0
- package/src/rules/no-sql-injection/no-sql-injection.test.ts +303 -0
- package/src/rules/no-timing-attack/index.ts +552 -0
- package/src/rules/no-timing-attack/no-timing-attack.test.ts +348 -0
- package/src/rules/no-toctou-vulnerability/index.ts +250 -0
- package/src/rules/no-toctou-vulnerability/no-toctou-vulnerability.test.ts +60 -0
- package/src/rules/no-tracking-without-consent/index.ts +78 -0
- package/src/rules/no-tracking-without-consent/no-tracking-without-consent.test.ts +34 -0
- package/src/rules/no-unchecked-loop-condition/index.ts +781 -0
- package/src/rules/no-unchecked-loop-condition/no-unchecked-loop-condition.test.ts +459 -0
- package/src/rules/no-unencrypted-local-storage/index.ts +73 -0
- package/src/rules/no-unencrypted-local-storage/no-unencrypted-local-storage.test.ts +41 -0
- package/src/rules/no-unencrypted-transmission/index.ts +296 -0
- package/src/rules/no-unencrypted-transmission/no-unencrypted-transmission.test.ts +287 -0
- package/src/rules/no-unescaped-url-parameter/index.ts +424 -0
- package/src/rules/no-unescaped-url-parameter/no-unescaped-url-parameter.test.ts +263 -0
- package/src/rules/no-unlimited-resource-allocation/index.ts +767 -0
- package/src/rules/no-unlimited-resource-allocation/no-unlimited-resource-allocation.test.ts +544 -0
- package/src/rules/no-unsafe-deserialization/index.ts +593 -0
- package/src/rules/no-unsafe-deserialization/no-unsafe-deserialization.test.ts +310 -0
- package/src/rules/no-unsafe-dynamic-require/index.ts +125 -0
- package/src/rules/no-unsafe-dynamic-require/no-unsafe-dynamic-require.test.ts +151 -0
- package/src/rules/no-unsafe-regex-construction/index.ts +370 -0
- package/src/rules/no-unsafe-regex-construction/no-unsafe-regex-construction.test.ts +181 -0
- package/src/rules/no-unsanitized-html/index.ts +400 -0
- package/src/rules/no-unsanitized-html/no-unsanitized-html.test.ts +488 -0
- package/src/rules/no-unvalidated-deeplinks/index.ts +73 -0
- package/src/rules/no-unvalidated-deeplinks/no-unvalidated-deeplinks.test.ts +29 -0
- package/src/rules/no-unvalidated-user-input/index.ts +498 -0
- package/src/rules/no-unvalidated-user-input/no-unvalidated-user-input.test.ts +463 -0
- package/src/rules/no-verbose-error-messages/index.ts +83 -0
- package/src/rules/no-verbose-error-messages/no-verbose-error-messages.test.ts +34 -0
- package/src/rules/no-weak-crypto/index.ts +447 -0
- package/src/rules/no-weak-crypto/no-weak-crypto.test.ts +297 -0
- package/src/rules/no-weak-password-recovery/index.ts +509 -0
- package/src/rules/no-weak-password-recovery/no-weak-password-recovery.test.ts +184 -0
- package/src/rules/no-xpath-injection/index.ts +596 -0
- package/src/rules/no-xpath-injection/no-xpath-injection.test.ts +405 -0
- package/src/rules/no-xxe-injection/index.ts +342 -0
- package/src/rules/no-xxe-injection/no-xxe-injection.test.ts +122 -0
- package/src/rules/no-zip-slip/index.ts +526 -0
- package/src/rules/no-zip-slip/no-zip-slip.test.ts +305 -0
- package/src/rules/require-backend-authorization/index.ts +71 -0
- package/src/rules/require-backend-authorization/require-backend-authorization.test.ts +31 -0
- package/src/rules/require-code-minification/index.ts +54 -0
- package/src/rules/require-code-minification/require-code-minification.test.ts +30 -0
- package/src/rules/require-csp-headers/index.ts +74 -0
- package/src/rules/require-csp-headers/require-csp-headers.test.ts +34 -0
- package/src/rules/require-data-minimization/index.ts +65 -0
- package/src/rules/require-data-minimization/require-data-minimization.test.ts +31 -0
- package/src/rules/require-dependency-integrity/index.ts +78 -0
- package/src/rules/require-dependency-integrity/require-dependency-integrity.test.ts +44 -0
- package/src/rules/require-https-only/index.ts +75 -0
- package/src/rules/require-https-only/require-https-only.test.ts +26 -0
- package/src/rules/require-mime-type-validation/index.ts +77 -0
- package/src/rules/require-mime-type-validation/require-mime-type-validation.test.ts +32 -0
- package/src/rules/require-network-timeout/index.ts +58 -0
- package/src/rules/require-network-timeout/require-network-timeout.test.ts +26 -0
- package/src/rules/require-package-lock/index.ts +75 -0
- package/src/rules/require-package-lock/require-package-lock.test.ts +27 -0
- package/src/rules/require-secure-credential-storage/index.ts +60 -0
- package/src/rules/require-secure-credential-storage/require-secure-credential-storage.test.ts +26 -0
- package/src/rules/require-secure-defaults/index.ts +54 -0
- package/src/rules/require-secure-defaults/require-secure-defaults.test.ts +26 -0
- package/src/rules/require-secure-deletion/index.ts +52 -0
- package/src/rules/require-secure-deletion/require-secure-deletion.test.ts +29 -0
- package/src/rules/require-storage-encryption/index.ts +60 -0
- package/src/rules/require-storage-encryption/require-storage-encryption.test.ts +26 -0
- package/src/rules/require-url-validation/index.ts +85 -0
- package/src/rules/require-url-validation/require-url-validation.test.ts +32 -0
- package/src/types/{index.d.ts → index.ts} +157 -53
- package/src/index.d.ts +0 -32
- package/src/index.js +0 -465
- package/src/rules/database-injection/index.d.ts +0 -13
- package/src/rules/database-injection/index.js +0 -406
- package/src/rules/detect-child-process/index.d.ts +0 -11
- package/src/rules/detect-child-process/index.js +0 -529
- package/src/rules/detect-eval-with-expression/index.d.ts +0 -9
- package/src/rules/detect-eval-with-expression/index.js +0 -392
- package/src/rules/detect-mixed-content/index.d.ts +0 -8
- package/src/rules/detect-mixed-content/index.js +0 -44
- package/src/rules/detect-non-literal-fs-filename/index.d.ts +0 -7
- package/src/rules/detect-non-literal-fs-filename/index.js +0 -454
- package/src/rules/detect-non-literal-regexp/index.d.ts +0 -9
- package/src/rules/detect-non-literal-regexp/index.js +0 -403
- package/src/rules/detect-object-injection/index.d.ts +0 -11
- package/src/rules/detect-object-injection/index.js +0 -560
- package/src/rules/detect-suspicious-dependencies/index.d.ts +0 -8
- package/src/rules/detect-suspicious-dependencies/index.js +0 -71
- package/src/rules/detect-weak-password-validation/index.d.ts +0 -6
- package/src/rules/detect-weak-password-validation/index.js +0 -58
- package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -8
- package/src/rules/no-allow-arbitrary-loads/index.js +0 -47
- package/src/rules/no-arbitrary-file-access/index.d.ts +0 -13
- package/src/rules/no-arbitrary-file-access/index.js +0 -195
- package/src/rules/no-buffer-overread/index.d.ts +0 -29
- package/src/rules/no-buffer-overread/index.js +0 -606
- package/src/rules/no-clickjacking/index.d.ts +0 -10
- package/src/rules/no-clickjacking/index.js +0 -396
- package/src/rules/no-client-side-auth-logic/index.d.ts +0 -6
- package/src/rules/no-client-side-auth-logic/index.js +0 -69
- package/src/rules/no-credentials-in-query-params/index.d.ts +0 -8
- package/src/rules/no-credentials-in-query-params/index.js +0 -57
- package/src/rules/no-credentials-in-storage-api/index.d.ts +0 -6
- package/src/rules/no-credentials-in-storage-api/index.js +0 -54
- package/src/rules/no-data-in-temp-storage/index.d.ts +0 -6
- package/src/rules/no-data-in-temp-storage/index.js +0 -64
- package/src/rules/no-debug-code-in-production/index.d.ts +0 -8
- package/src/rules/no-debug-code-in-production/index.js +0 -51
- package/src/rules/no-directive-injection/index.d.ts +0 -12
- package/src/rules/no-directive-injection/index.js +0 -457
- package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -6
- package/src/rules/no-disabled-certificate-validation/index.js +0 -61
- package/src/rules/no-document-cookie/index.d.ts +0 -5
- package/src/rules/no-document-cookie/index.js +0 -89
- package/src/rules/no-dynamic-dependency-loading/index.d.ts +0 -8
- package/src/rules/no-dynamic-dependency-loading/index.js +0 -51
- package/src/rules/no-electron-security-issues/index.d.ts +0 -10
- package/src/rules/no-electron-security-issues/index.js +0 -423
- package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -6
- package/src/rules/no-exposed-debug-endpoints/index.js +0 -62
- package/src/rules/no-exposed-sensitive-data/index.d.ts +0 -11
- package/src/rules/no-exposed-sensitive-data/index.js +0 -340
- package/src/rules/no-format-string-injection/index.d.ts +0 -17
- package/src/rules/no-format-string-injection/index.js +0 -660
- package/src/rules/no-graphql-injection/index.d.ts +0 -12
- package/src/rules/no-graphql-injection/index.js +0 -411
- package/src/rules/no-hardcoded-credentials/index.d.ts +0 -26
- package/src/rules/no-hardcoded-credentials/index.js +0 -376
- package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -6
- package/src/rules/no-hardcoded-session-tokens/index.js +0 -59
- package/src/rules/no-http-urls/index.d.ts +0 -12
- package/src/rules/no-http-urls/index.js +0 -114
- package/src/rules/no-improper-sanitization/index.d.ts +0 -12
- package/src/rules/no-improper-sanitization/index.js +0 -411
- package/src/rules/no-improper-type-validation/index.d.ts +0 -10
- package/src/rules/no-improper-type-validation/index.js +0 -475
- package/src/rules/no-insecure-comparison/index.d.ts +0 -7
- package/src/rules/no-insecure-comparison/index.js +0 -193
- package/src/rules/no-insecure-cookie-settings/index.d.ts +0 -9
- package/src/rules/no-insecure-cookie-settings/index.js +0 -306
- package/src/rules/no-insecure-jwt/index.d.ts +0 -10
- package/src/rules/no-insecure-jwt/index.js +0 -380
- package/src/rules/no-insecure-redirects/index.d.ts +0 -7
- package/src/rules/no-insecure-redirects/index.js +0 -216
- package/src/rules/no-insecure-websocket/index.d.ts +0 -6
- package/src/rules/no-insecure-websocket/index.js +0 -61
- package/src/rules/no-insufficient-postmessage-validation/index.d.ts +0 -14
- package/src/rules/no-insufficient-postmessage-validation/index.js +0 -392
- package/src/rules/no-insufficient-random/index.d.ts +0 -9
- package/src/rules/no-insufficient-random/index.js +0 -208
- package/src/rules/no-ldap-injection/index.d.ts +0 -10
- package/src/rules/no-ldap-injection/index.js +0 -455
- package/src/rules/no-missing-authentication/index.d.ts +0 -13
- package/src/rules/no-missing-authentication/index.js +0 -333
- package/src/rules/no-missing-cors-check/index.d.ts +0 -9
- package/src/rules/no-missing-cors-check/index.js +0 -399
- package/src/rules/no-missing-csrf-protection/index.d.ts +0 -11
- package/src/rules/no-missing-csrf-protection/index.js +0 -180
- package/src/rules/no-missing-security-headers/index.d.ts +0 -7
- package/src/rules/no-missing-security-headers/index.js +0 -218
- package/src/rules/no-password-in-url/index.d.ts +0 -8
- package/src/rules/no-password-in-url/index.js +0 -54
- package/src/rules/no-permissive-cors/index.d.ts +0 -8
- package/src/rules/no-permissive-cors/index.js +0 -65
- package/src/rules/no-pii-in-logs/index.d.ts +0 -8
- package/src/rules/no-pii-in-logs/index.js +0 -70
- package/src/rules/no-postmessage-origin-wildcard/index.d.ts +0 -8
- package/src/rules/no-postmessage-origin-wildcard/index.js +0 -56
- package/src/rules/no-privilege-escalation/index.d.ts +0 -13
- package/src/rules/no-privilege-escalation/index.js +0 -321
- package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -7
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -306
- package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -11
- package/src/rules/no-sensitive-data-exposure/index.js +0 -250
- package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -8
- package/src/rules/no-sensitive-data-in-analytics/index.js +0 -62
- package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -8
- package/src/rules/no-sensitive-data-in-cache/index.js +0 -52
- package/src/rules/no-sql-injection/index.d.ts +0 -10
- package/src/rules/no-sql-injection/index.js +0 -335
- package/src/rules/no-timing-attack/index.d.ts +0 -10
- package/src/rules/no-timing-attack/index.js +0 -447
- package/src/rules/no-toctou-vulnerability/index.d.ts +0 -7
- package/src/rules/no-toctou-vulnerability/index.js +0 -208
- package/src/rules/no-tracking-without-consent/index.d.ts +0 -6
- package/src/rules/no-tracking-without-consent/index.js +0 -67
- package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -12
- package/src/rules/no-unchecked-loop-condition/index.js +0 -646
- package/src/rules/no-unencrypted-local-storage/index.d.ts +0 -8
- package/src/rules/no-unencrypted-local-storage/index.js +0 -61
- package/src/rules/no-unencrypted-transmission/index.d.ts +0 -11
- package/src/rules/no-unencrypted-transmission/index.js +0 -236
- package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -9
- package/src/rules/no-unescaped-url-parameter/index.js +0 -355
- package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -12
- package/src/rules/no-unlimited-resource-allocation/index.js +0 -643
- package/src/rules/no-unsafe-deserialization/index.d.ts +0 -10
- package/src/rules/no-unsafe-deserialization/index.js +0 -491
- package/src/rules/no-unsafe-dynamic-require/index.d.ts +0 -5
- package/src/rules/no-unsafe-dynamic-require/index.js +0 -106
- package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -9
- package/src/rules/no-unsafe-regex-construction/index.js +0 -291
- package/src/rules/no-unsanitized-html/index.d.ts +0 -9
- package/src/rules/no-unsanitized-html/index.js +0 -335
- package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -6
- package/src/rules/no-unvalidated-deeplinks/index.js +0 -62
- package/src/rules/no-unvalidated-user-input/index.d.ts +0 -9
- package/src/rules/no-unvalidated-user-input/index.js +0 -420
- package/src/rules/no-verbose-error-messages/index.d.ts +0 -8
- package/src/rules/no-verbose-error-messages/index.js +0 -68
- package/src/rules/no-weak-crypto/index.d.ts +0 -11
- package/src/rules/no-weak-crypto/index.js +0 -351
- package/src/rules/no-weak-password-recovery/index.d.ts +0 -12
- package/src/rules/no-weak-password-recovery/index.js +0 -424
- package/src/rules/no-xpath-injection/index.d.ts +0 -10
- package/src/rules/no-xpath-injection/index.js +0 -487
- package/src/rules/no-xxe-injection/index.d.ts +0 -7
- package/src/rules/no-xxe-injection/index.js +0 -266
- package/src/rules/no-zip-slip/index.d.ts +0 -9
- package/src/rules/no-zip-slip/index.js +0 -445
- package/src/rules/require-backend-authorization/index.d.ts +0 -6
- package/src/rules/require-backend-authorization/index.js +0 -60
- package/src/rules/require-code-minification/index.d.ts +0 -8
- package/src/rules/require-code-minification/index.js +0 -47
- package/src/rules/require-csp-headers/index.d.ts +0 -6
- package/src/rules/require-csp-headers/index.js +0 -64
- package/src/rules/require-data-minimization/index.d.ts +0 -8
- package/src/rules/require-data-minimization/index.js +0 -53
- package/src/rules/require-dependency-integrity/index.d.ts +0 -6
- package/src/rules/require-dependency-integrity/index.js +0 -64
- package/src/rules/require-https-only/index.d.ts +0 -8
- package/src/rules/require-https-only/index.js +0 -62
- package/src/rules/require-mime-type-validation/index.d.ts +0 -6
- package/src/rules/require-mime-type-validation/index.js +0 -66
- package/src/rules/require-network-timeout/index.d.ts +0 -8
- package/src/rules/require-network-timeout/index.js +0 -50
- package/src/rules/require-package-lock/index.d.ts +0 -8
- package/src/rules/require-package-lock/index.js +0 -63
- package/src/rules/require-secure-credential-storage/index.d.ts +0 -8
- package/src/rules/require-secure-credential-storage/index.js +0 -50
- package/src/rules/require-secure-defaults/index.d.ts +0 -8
- package/src/rules/require-secure-defaults/index.js +0 -47
- package/src/rules/require-secure-deletion/index.d.ts +0 -8
- package/src/rules/require-secure-deletion/index.js +0 -44
- package/src/rules/require-storage-encryption/index.d.ts +0 -8
- package/src/rules/require-storage-encryption/index.js +0 -50
- package/src/rules/require-url-validation/index.d.ts +0 -6
- package/src/rules/require-url-validation/index.js +0 -72
- package/src/types/index.js +0 -17
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnsafeRegexConstruction = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
/**
|
|
7
|
-
* Check if a node represents user input (variable, function call, template literal)
|
|
8
|
-
*/
|
|
9
|
-
function isUserInput(node) {
|
|
10
|
-
// Function calls might return user input
|
|
11
|
-
if (node.type === 'CallExpression') {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
// Template literals with expressions are dynamic
|
|
15
|
-
if (node.type === 'TemplateLiteral') {
|
|
16
|
-
return node.expressions.length > 0;
|
|
17
|
-
}
|
|
18
|
-
// Member expressions accessing user properties
|
|
19
|
-
if (node.type === 'MemberExpression') {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
// Variables are likely user input unless they are safe literals
|
|
23
|
-
if (node.type === 'Identifier') {
|
|
24
|
-
// Exclude common safe patterns, but be more restrictive
|
|
25
|
-
const safeIdentifiers = ['pattern', 'regex', 'regExp', 'regexp'];
|
|
26
|
-
if (safeIdentifiers.includes(node.name.toLowerCase())) {
|
|
27
|
-
// For these identifiers, check if they're assigned user input in scope
|
|
28
|
-
// For now, we'll be conservative and flag them as potentially unsafe
|
|
29
|
-
return true; // Changed from false to true - safer to flag as user input
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Check if a node is escaped (wrapped in an escaping function)
|
|
37
|
-
*/
|
|
38
|
-
function isEscaped(node, trustedFunctions, sourceCode) {
|
|
39
|
-
// Check if the node itself is a call to a trusted escaping function
|
|
40
|
-
if (node.type === 'CallExpression' && node.callee.type === 'Identifier') {
|
|
41
|
-
const functionName = node.callee.name;
|
|
42
|
-
if (trustedFunctions.includes(functionName)) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Also check if it's wrapped in a trusted function call (for complex cases)
|
|
47
|
-
let current = node;
|
|
48
|
-
let depth = 0;
|
|
49
|
-
const maxDepth = 5; // Prevent infinite loops
|
|
50
|
-
while (current && depth < maxDepth) {
|
|
51
|
-
const parent = sourceCode.getNodeByRangeIndex?.(current.range[0] - 1) ||
|
|
52
|
-
current.parent;
|
|
53
|
-
if (!parent)
|
|
54
|
-
break;
|
|
55
|
-
if (parent.type === 'CallExpression' && parent.callee.type === 'Identifier') {
|
|
56
|
-
const functionName = parent.callee.name;
|
|
57
|
-
if (trustedFunctions.includes(functionName)) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
current = parent;
|
|
62
|
-
depth++;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if regex flags are dynamic
|
|
68
|
-
*/
|
|
69
|
-
function hasDynamicFlags(node) {
|
|
70
|
-
// Check second argument (flags)
|
|
71
|
-
if (node.arguments.length > 1) {
|
|
72
|
-
const flagsNode = node.arguments[1];
|
|
73
|
-
return isUserInput(flagsNode);
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Extract pattern from RegExp construction
|
|
79
|
-
*/
|
|
80
|
-
function extractPattern(node, sourceCode, trustedFunctions) {
|
|
81
|
-
const patternNode = node.arguments.length > 0 ? node.arguments[0] : null;
|
|
82
|
-
if (!patternNode) {
|
|
83
|
-
return { patternNode: null, isUserInput: false, isEscaped: false };
|
|
84
|
-
}
|
|
85
|
-
const isUserInputValue = isUserInput(patternNode);
|
|
86
|
-
// Default trusted functions + user configured ones
|
|
87
|
-
const allTrustedFunctions = [...new Set([
|
|
88
|
-
'escapeRegex', 'escape', 'sanitize', 'RegExp.escape',
|
|
89
|
-
...trustedFunctions
|
|
90
|
-
])];
|
|
91
|
-
const isEscapedValue = isEscaped(patternNode, allTrustedFunctions, sourceCode);
|
|
92
|
-
return {
|
|
93
|
-
patternNode,
|
|
94
|
-
isUserInput: isUserInputValue,
|
|
95
|
-
isEscaped: isEscapedValue,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
exports.noUnsafeRegexConstruction = (0, eslint_devkit_2.createRule)({
|
|
99
|
-
name: 'no-unsafe-regex-construction',
|
|
100
|
-
meta: {
|
|
101
|
-
type: 'problem',
|
|
102
|
-
docs: {
|
|
103
|
-
description: 'Detects unsafe regex construction patterns (user input without escaping, dynamic flags)',
|
|
104
|
-
},
|
|
105
|
-
hasSuggestions: true,
|
|
106
|
-
messages: {
|
|
107
|
-
unsafeRegexConstruction: (0, eslint_devkit_1.formatLLMMessage)({
|
|
108
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
109
|
-
issueName: 'Unsafe regex construction',
|
|
110
|
-
cwe: 'CWE-400',
|
|
111
|
-
description: '{{issue}}: {{details}}',
|
|
112
|
-
severity: 'HIGH',
|
|
113
|
-
fix: '{{fix}}',
|
|
114
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS',
|
|
115
|
-
}),
|
|
116
|
-
escapeUserInput: (0, eslint_devkit_1.formatLLMMessage)({
|
|
117
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
118
|
-
issueName: 'Escape User Input',
|
|
119
|
-
description: 'Escape user input for regex',
|
|
120
|
-
severity: 'LOW',
|
|
121
|
-
fix: 'input.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")',
|
|
122
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping',
|
|
123
|
-
}),
|
|
124
|
-
validatePattern: (0, eslint_devkit_1.formatLLMMessage)({
|
|
125
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
126
|
-
issueName: 'Validate Pattern',
|
|
127
|
-
description: 'Validate pattern against whitelist',
|
|
128
|
-
severity: 'LOW',
|
|
129
|
-
fix: 'Validate pattern before creating RegExp',
|
|
130
|
-
documentationLink: 'https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS',
|
|
131
|
-
}),
|
|
132
|
-
useSafeLibrary: (0, eslint_devkit_1.formatLLMMessage)({
|
|
133
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
134
|
-
issueName: 'Use safe-regex',
|
|
135
|
-
description: 'Use safe-regex library for validation',
|
|
136
|
-
severity: 'LOW',
|
|
137
|
-
fix: 'if (safeRegex(pattern)) { new RegExp(pattern) }',
|
|
138
|
-
documentationLink: 'https://github.com/substack/safe-regex',
|
|
139
|
-
}),
|
|
140
|
-
avoidDynamicFlags: (0, eslint_devkit_1.formatLLMMessage)({
|
|
141
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
142
|
-
issueName: 'Use Static Flags',
|
|
143
|
-
description: 'Use static flags instead of dynamic',
|
|
144
|
-
severity: 'LOW',
|
|
145
|
-
fix: 'new RegExp(pattern, "gi") with static flags',
|
|
146
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp',
|
|
147
|
-
}),
|
|
148
|
-
},
|
|
149
|
-
schema: [
|
|
150
|
-
{
|
|
151
|
-
type: 'object',
|
|
152
|
-
properties: {
|
|
153
|
-
allowLiterals: {
|
|
154
|
-
type: 'boolean',
|
|
155
|
-
default: true,
|
|
156
|
-
description: 'Allow literal string patterns',
|
|
157
|
-
},
|
|
158
|
-
trustedEscapingFunctions: {
|
|
159
|
-
type: 'array',
|
|
160
|
-
items: { type: 'string' },
|
|
161
|
-
default: ['escapeRegex', 'escape', 'sanitize'],
|
|
162
|
-
description: 'Trusted functions that escape input',
|
|
163
|
-
},
|
|
164
|
-
maxPatternLength: {
|
|
165
|
-
type: 'number',
|
|
166
|
-
default: 100,
|
|
167
|
-
minimum: 1,
|
|
168
|
-
description: 'Maximum pattern length for dynamic regex',
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
additionalProperties: false,
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
},
|
|
175
|
-
defaultOptions: [
|
|
176
|
-
{
|
|
177
|
-
allowLiterals: true,
|
|
178
|
-
trustedEscapingFunctions: ['escapeRegex', 'escape', 'sanitize'],
|
|
179
|
-
maxPatternLength: 100,
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
create(context, [options = {}]) {
|
|
183
|
-
const { allowLiterals = true, maxPatternLength = 100, trustedEscapingFunctions = ['escapeRegex', 'escape', 'sanitize'], } = options || {};
|
|
184
|
-
const sourceCode = context.sourceCode || context.sourceCode;
|
|
185
|
-
/**
|
|
186
|
-
* Check RegExp constructor calls
|
|
187
|
-
*/
|
|
188
|
-
function checkRegExpCall(node) {
|
|
189
|
-
// Check for RegExp constructor
|
|
190
|
-
const isRegExpCall = (node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'RegExp') ||
|
|
191
|
-
(node.type === 'NewExpression' && node.callee.type === 'Identifier' && node.callee.name === 'RegExp');
|
|
192
|
-
if (!isRegExpCall) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
const { patternNode, isUserInput: isUserInputValue, isEscaped: isEscapedValue } = extractPattern(node, sourceCode, trustedEscapingFunctions);
|
|
196
|
-
if (!patternNode) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
// Check for literal strings
|
|
200
|
-
if (patternNode.type === 'Literal' && typeof patternNode.value === 'string') {
|
|
201
|
-
// Even literals can be unsafe if they're very long - check this regardless of allowLiterals
|
|
202
|
-
const patternLength = patternNode.value.length;
|
|
203
|
-
if (patternLength > maxPatternLength) {
|
|
204
|
-
context.report({
|
|
205
|
-
node: patternNode,
|
|
206
|
-
messageId: 'unsafeRegexConstruction',
|
|
207
|
-
data: {
|
|
208
|
-
issue: 'Pattern too long',
|
|
209
|
-
details: `Pattern length (${patternLength}) exceeds maximum (${maxPatternLength})`,
|
|
210
|
-
fix: 'Split into smaller patterns or validate length',
|
|
211
|
-
},
|
|
212
|
-
suggest: [
|
|
213
|
-
{
|
|
214
|
-
messageId: 'validatePattern',
|
|
215
|
-
fix: () => null,
|
|
216
|
-
},
|
|
217
|
-
],
|
|
218
|
-
});
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (!allowLiterals) {
|
|
222
|
-
// If we reach here, allowLiterals is false, so treat as unsafe
|
|
223
|
-
context.report({
|
|
224
|
-
node: patternNode,
|
|
225
|
-
messageId: 'unsafeRegexConstruction',
|
|
226
|
-
data: {
|
|
227
|
-
issue: 'Literal regex pattern',
|
|
228
|
-
details: 'Literal regex patterns should be avoided for security. Use variables instead.',
|
|
229
|
-
fix: 'Use a variable or RegExp constructor with a string variable',
|
|
230
|
-
},
|
|
231
|
-
suggest: [
|
|
232
|
-
{
|
|
233
|
-
messageId: 'validatePattern',
|
|
234
|
-
fix: () => null,
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
});
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// Check for user input without escaping
|
|
242
|
-
if (isUserInputValue && !isEscapedValue) {
|
|
243
|
-
context.report({
|
|
244
|
-
node: patternNode,
|
|
245
|
-
messageId: 'unsafeRegexConstruction',
|
|
246
|
-
data: {
|
|
247
|
-
issue: 'User input in regex without escaping',
|
|
248
|
-
details: 'User input in regex pattern can lead to ReDoS or injection attacks',
|
|
249
|
-
fix: 'Escape special characters before using in regex',
|
|
250
|
-
},
|
|
251
|
-
suggest: [
|
|
252
|
-
{
|
|
253
|
-
messageId: 'escapeUserInput',
|
|
254
|
-
fix: () => null,
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
messageId: 'validatePattern',
|
|
258
|
-
fix: () => null,
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
messageId: 'useSafeLibrary',
|
|
262
|
-
fix: () => null,
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
// Check for dynamic flags
|
|
268
|
-
if (hasDynamicFlags(node)) {
|
|
269
|
-
context.report({
|
|
270
|
-
node,
|
|
271
|
-
messageId: 'unsafeRegexConstruction',
|
|
272
|
-
data: {
|
|
273
|
-
issue: 'Dynamic regex flags',
|
|
274
|
-
details: 'Dynamic flags can lead to unexpected behavior or security issues',
|
|
275
|
-
fix: 'Use static flags instead of dynamic flags',
|
|
276
|
-
},
|
|
277
|
-
suggest: [
|
|
278
|
-
{
|
|
279
|
-
messageId: 'avoidDynamicFlags',
|
|
280
|
-
fix: () => null,
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
CallExpression: checkRegExpCall,
|
|
288
|
-
NewExpression: checkRegExpCall,
|
|
289
|
-
};
|
|
290
|
-
},
|
|
291
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export interface Options {
|
|
2
|
-
/** Allow unsanitized HTML in test files. Default: false */
|
|
3
|
-
allowInTests?: boolean;
|
|
4
|
-
/** Trusted sanitization libraries. Default: ['dompurify', 'sanitize-html', 'xss'] */
|
|
5
|
-
trustedLibraries?: string[];
|
|
6
|
-
/** Additional safe patterns to ignore. Default: [] */
|
|
7
|
-
ignorePatterns?: string[];
|
|
8
|
-
}
|
|
9
|
-
export declare const noUnsanitizedHtml: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnsanitizedHtml = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
/**
|
|
7
|
-
* Check if a string matches any ignore pattern
|
|
8
|
-
*/
|
|
9
|
-
function matchesIgnorePattern(text, ignorePatterns) {
|
|
10
|
-
return ignorePatterns.some(pattern => {
|
|
11
|
-
try {
|
|
12
|
-
const regex = new RegExp(pattern, 'i');
|
|
13
|
-
return regex.test(text);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
// Invalid regex - treat as literal string match
|
|
17
|
-
return text.toLowerCase().includes(pattern.toLowerCase());
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
exports.noUnsanitizedHtml = (0, eslint_devkit_2.createRule)({
|
|
22
|
-
name: 'no-unsanitized-html',
|
|
23
|
-
meta: {
|
|
24
|
-
type: 'problem',
|
|
25
|
-
docs: {
|
|
26
|
-
description: 'Detects unsanitized HTML injection (dangerouslySetInnerHTML, innerHTML)',
|
|
27
|
-
},
|
|
28
|
-
hasSuggestions: true,
|
|
29
|
-
messages: {
|
|
30
|
-
unsanitizedHtml: (0, eslint_devkit_1.formatLLMMessage)({
|
|
31
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
32
|
-
issueName: 'Unsanitized HTML Injection',
|
|
33
|
-
cwe: 'CWE-79',
|
|
34
|
-
description: 'Unsanitized HTML detected: {{htmlSource}}',
|
|
35
|
-
severity: 'CRITICAL',
|
|
36
|
-
fix: '{{safeAlternative}}',
|
|
37
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/79.html',
|
|
38
|
-
}),
|
|
39
|
-
useTextContent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
40
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
41
|
-
issueName: 'Use textContent',
|
|
42
|
-
description: 'Use textContent instead of innerHTML',
|
|
43
|
-
severity: 'LOW',
|
|
44
|
-
fix: 'element.textContent = userInput;',
|
|
45
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent',
|
|
46
|
-
}),
|
|
47
|
-
useSanitizeLibrary: (0, eslint_devkit_1.formatLLMMessage)({
|
|
48
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
49
|
-
issueName: 'Use Sanitization',
|
|
50
|
-
description: 'Use sanitization library',
|
|
51
|
-
severity: 'LOW',
|
|
52
|
-
fix: 'DOMPurify.sanitize(html) or sanitize-html',
|
|
53
|
-
documentationLink: 'https://github.com/cure53/DOMPurify',
|
|
54
|
-
}),
|
|
55
|
-
useDangerouslySetInnerHTML: (0, eslint_devkit_1.formatLLMMessage)({
|
|
56
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
57
|
-
issueName: 'Sanitize First',
|
|
58
|
-
description: 'Sanitize before dangerouslySetInnerHTML',
|
|
59
|
-
severity: 'LOW',
|
|
60
|
-
fix: 'dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(html) }}',
|
|
61
|
-
documentationLink: 'https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html',
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
schema: [
|
|
65
|
-
{
|
|
66
|
-
type: 'object',
|
|
67
|
-
properties: {
|
|
68
|
-
allowInTests: {
|
|
69
|
-
type: 'boolean',
|
|
70
|
-
default: false,
|
|
71
|
-
description: 'Allow unsanitized HTML in test files',
|
|
72
|
-
},
|
|
73
|
-
trustedLibraries: {
|
|
74
|
-
type: 'array',
|
|
75
|
-
items: { type: 'string' },
|
|
76
|
-
default: ['dompurify', 'sanitize-html', 'xss'],
|
|
77
|
-
description: 'Trusted sanitization libraries',
|
|
78
|
-
},
|
|
79
|
-
ignorePatterns: {
|
|
80
|
-
type: 'array',
|
|
81
|
-
items: { type: 'string' },
|
|
82
|
-
default: [],
|
|
83
|
-
description: 'Additional safe patterns to ignore',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
additionalProperties: false,
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
defaultOptions: [
|
|
91
|
-
{
|
|
92
|
-
allowInTests: false,
|
|
93
|
-
trustedLibraries: ['dompurify', 'sanitize-html', 'xss'],
|
|
94
|
-
ignorePatterns: [],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
create(context, [options = {}]) {
|
|
98
|
-
const { allowInTests = false, trustedLibraries = ['dompurify', 'sanitize-html', 'xss'], ignorePatterns = [], } = options;
|
|
99
|
-
const filename = context.getFilename();
|
|
100
|
-
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
101
|
-
const sourceCode = context.sourceCode || context.sourceCode;
|
|
102
|
-
// Track variables that have been assigned sanitized content
|
|
103
|
-
const sanitizedVariables = new Set();
|
|
104
|
-
/**
|
|
105
|
-
* Check if a call expression is a sanitization call
|
|
106
|
-
*/
|
|
107
|
-
function isSanitizationCall(node) {
|
|
108
|
-
const callee = node.callee;
|
|
109
|
-
if (callee.type === 'Identifier') {
|
|
110
|
-
const calleeName = callee.name.toLowerCase();
|
|
111
|
-
if (['sanitize', 'sanitizehtml', 'purify', 'escape'].includes(calleeName)) {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
if (trustedLibraries.some(lib => calleeName.includes(lib.toLowerCase()))) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (callee.type === 'MemberExpression' && callee.object.type === 'Identifier') {
|
|
119
|
-
const objectName = callee.object.name.toLowerCase();
|
|
120
|
-
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
// Also check the method name
|
|
124
|
-
if (callee.property.type === 'Identifier') {
|
|
125
|
-
const methodName = callee.property.name.toLowerCase();
|
|
126
|
-
if (['sanitize', 'purify', 'escape', 'clean'].includes(methodName)) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Track variable declarations that are assigned sanitized content
|
|
135
|
-
*/
|
|
136
|
-
function trackSanitizedAssignment(node) {
|
|
137
|
-
let varName = null;
|
|
138
|
-
let init = null;
|
|
139
|
-
if (node.type === 'VariableDeclarator') {
|
|
140
|
-
if (node.id.type === 'Identifier' && node.init) {
|
|
141
|
-
varName = node.id.name;
|
|
142
|
-
init = node.init;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
if (node.left.type === 'Identifier') {
|
|
147
|
-
varName = node.left.name;
|
|
148
|
-
init = node.right;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (varName && init && init.type === 'CallExpression') {
|
|
152
|
-
if (isSanitizationCall(init)) {
|
|
153
|
-
sanitizedVariables.add(varName);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function checkAssignmentExpression(node) {
|
|
158
|
-
if (isTestFile) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
// Check if left side is a dangerous DOM property
|
|
162
|
-
if (node.left.type === 'MemberExpression' &&
|
|
163
|
-
node.left.property.type === 'Identifier') {
|
|
164
|
-
const propertyName = node.left.property.name;
|
|
165
|
-
const dangerousProps = ['innerHTML', 'outerHTML'];
|
|
166
|
-
if (!dangerousProps.includes(propertyName)) {
|
|
167
|
-
return; // Not a dangerous property
|
|
168
|
-
}
|
|
169
|
-
const memberExpr = node.left;
|
|
170
|
-
const property = memberExpr.property;
|
|
171
|
-
const text = sourceCode.getText(memberExpr);
|
|
172
|
-
// Check if the left side (variable/object) matches any ignore pattern
|
|
173
|
-
// This handles cases like testElement.innerHTML where testElement should be ignored
|
|
174
|
-
if (memberExpr.object.type === 'Identifier') {
|
|
175
|
-
const objectName = memberExpr.object.name;
|
|
176
|
-
if (matchesIgnorePattern(objectName, ignorePatterns)) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// Also check the full expression
|
|
181
|
-
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
// Check if the right side (assignment value) is a sanitization call
|
|
185
|
-
// First check if node.right itself is a sanitization call
|
|
186
|
-
if (node.right.type === 'CallExpression') {
|
|
187
|
-
const callee = node.right.callee;
|
|
188
|
-
if (callee.type === 'Identifier') {
|
|
189
|
-
const calleeName = callee.name.toLowerCase();
|
|
190
|
-
if (['sanitize', 'sanitizehtml', 'purify', 'escape'].includes(calleeName)) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (trustedLibraries.some(lib => calleeName.includes(lib.toLowerCase()))) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (callee.type === 'MemberExpression' && callee.object.type === 'Identifier') {
|
|
198
|
-
const objectName = callee.object.name.toLowerCase();
|
|
199
|
-
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
// If right side is a literal string/number, allow it
|
|
205
|
-
if (node.right.type === 'Literal') {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
// FALSE POSITIVE REDUCTION: Check if right side is a previously-sanitized variable
|
|
209
|
-
// Pattern: const clean = DOMPurify.sanitize(html); element.innerHTML = clean;
|
|
210
|
-
if (node.right.type === 'Identifier' && sanitizedVariables.has(node.right.name)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
// For innerHTML/outerHTML, we should flag ANY non-sanitized assignment
|
|
214
|
-
// This is more aggressive but safer - innerHTML should ALWAYS be sanitized
|
|
215
|
-
// unless it's a literal or explicitly sanitized
|
|
216
|
-
// Build suggestions array - conditionally include based on context
|
|
217
|
-
// For allowInTests option, don't provide suggestions (test expects none)
|
|
218
|
-
const suggestions = allowInTests && !isTestFile
|
|
219
|
-
? undefined // allowInTests is true but file is not a test file - no suggestions
|
|
220
|
-
: [
|
|
221
|
-
{
|
|
222
|
-
messageId: 'useTextContent',
|
|
223
|
-
fix: (fixer) => {
|
|
224
|
-
return fixer.replaceText(property, 'textContent');
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
messageId: 'useSanitizeLibrary',
|
|
229
|
-
fix: () => [],
|
|
230
|
-
},
|
|
231
|
-
];
|
|
232
|
-
context.report({
|
|
233
|
-
node: memberExpr,
|
|
234
|
-
messageId: 'unsanitizedHtml',
|
|
235
|
-
data: {
|
|
236
|
-
htmlSource: propertyName,
|
|
237
|
-
safeAlternative: 'Use textContent or sanitize with DOMPurify: element.textContent = userInput; or element.innerHTML = DOMPurify.sanitize(html);',
|
|
238
|
-
},
|
|
239
|
-
suggest: suggestions,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function checkJSXAttribute(node) {
|
|
244
|
-
if (isTestFile) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (node.name.type !== 'JSXIdentifier') {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const attributeName = node.name.name;
|
|
251
|
-
// Check for dangerouslySetInnerHTML
|
|
252
|
-
if (attributeName === 'dangerouslySetInnerHTML') {
|
|
253
|
-
// Check if the value is sanitized
|
|
254
|
-
if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
255
|
-
const expression = node.value.expression;
|
|
256
|
-
// Check if it's an object with __html property
|
|
257
|
-
if (expression.type === 'ObjectExpression') {
|
|
258
|
-
const htmlProperty = expression.properties.find((prop) => prop.type === 'Property' &&
|
|
259
|
-
prop.key.type === 'Identifier' &&
|
|
260
|
-
prop.key.name === '__html');
|
|
261
|
-
if (htmlProperty && htmlProperty.value) {
|
|
262
|
-
const htmlValue = htmlProperty.value;
|
|
263
|
-
// Check if the value is sanitized
|
|
264
|
-
if (htmlValue.type === 'CallExpression') {
|
|
265
|
-
const callee = htmlValue.callee;
|
|
266
|
-
if (callee.type === 'MemberExpression' && callee.object.type === 'Identifier') {
|
|
267
|
-
const objectName = callee.object.name.toLowerCase();
|
|
268
|
-
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
269
|
-
return; // It's sanitized
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (callee.type === 'Identifier') {
|
|
273
|
-
const calleeName = callee.name.toLowerCase();
|
|
274
|
-
if (['sanitize', 'sanitizehtml', 'purify', 'escape'].includes(calleeName)) {
|
|
275
|
-
return; // It's sanitized
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
// Check if the value matches user input patterns
|
|
280
|
-
const htmlValueText = sourceCode.getText(htmlValue);
|
|
281
|
-
let isUserInputValue = false;
|
|
282
|
-
if (htmlValue.type === 'Identifier') {
|
|
283
|
-
const identifierName = htmlValue.name.toLowerCase();
|
|
284
|
-
const userInputNames = ['userinput', 'userdata', 'html', 'content', 'text'];
|
|
285
|
-
isUserInputValue = userInputNames.includes(identifierName);
|
|
286
|
-
}
|
|
287
|
-
const userInputPatterns = [
|
|
288
|
-
/\b(userInput|userData|html|content|text)\b/i,
|
|
289
|
-
/\breq\.(body|query|params|headers|cookies)/,
|
|
290
|
-
/\brequest\.(body|query|params)/,
|
|
291
|
-
];
|
|
292
|
-
isUserInputValue = isUserInputValue || userInputPatterns.some(pattern => pattern.test(htmlValueText));
|
|
293
|
-
if (isUserInputValue) {
|
|
294
|
-
// It's user input, report it
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
// Check if it matches ignore patterns
|
|
298
|
-
if (matchesIgnorePattern(htmlValueText, ignorePatterns)) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
// If it's not user input and not in ignore patterns, it might be safe
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
context.report({
|
|
308
|
-
node,
|
|
309
|
-
messageId: 'unsanitizedHtml',
|
|
310
|
-
data: {
|
|
311
|
-
htmlSource: 'dangerouslySetInnerHTML',
|
|
312
|
-
safeAlternative: 'Sanitize HTML before using dangerouslySetInnerHTML: <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(html) }} />',
|
|
313
|
-
},
|
|
314
|
-
suggest: [
|
|
315
|
-
{
|
|
316
|
-
messageId: 'useDangerouslySetInnerHTML',
|
|
317
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
318
|
-
fix: (_fixer) => null,
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return {
|
|
325
|
-
VariableDeclarator: trackSanitizedAssignment,
|
|
326
|
-
AssignmentExpression: (node) => {
|
|
327
|
-
// Track sanitized assignments first
|
|
328
|
-
trackSanitizedAssignment(node);
|
|
329
|
-
// Then check for unsafe innerHTML
|
|
330
|
-
checkAssignmentExpression(node);
|
|
331
|
-
},
|
|
332
|
-
JSXAttribute: checkJSXAttribute,
|
|
333
|
-
};
|
|
334
|
-
},
|
|
335
|
-
});
|