@sun-asterisk/sunlint 1.3.39 → 1.3.40
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/config/rules/rules-registry-generated.json +134 -108
- package/docs/GENERATED_FILES_QUICK_REFERENCE.md +96 -0
- package/docs/GENERATED_FILE_HANDLING_SUMMARY.md +152 -0
- package/docs/skills/CREATE_NEW_DART_RULE.md +161 -14
- package/origin-rules/dart-en.md +151 -163
- package/package.json +2 -1
- package/rules/dart/D002_dispose_resources/config.json +25 -0
- package/rules/dart/D003_prefer_widgets_over_methods/config.json +14 -0
- package/rules/dart/D004_avoid_shrinkwrap_listview/config.json +13 -0
- package/rules/dart/D005_limit_widget_nesting/config.json +13 -0
- package/rules/dart/D006_prefer_extracting_large_callbacks/config.json +25 -0
- package/rules/dart/D007_prefer_init_first_dispose_last/config.json +10 -0
- package/rules/dart/D008_avoid_long_functions/config.json +12 -0
- package/rules/dart/D009_limit_function_parameters/config.json +13 -0
- package/rules/dart/D010_limit_cyclomatic_complexity/config.json +12 -0
- package/rules/dart/D011_prefer_named_parameters/config.json +12 -0
- package/rules/dart/D012_prefer_named_boolean_parameters/config.json +9 -0
- package/rules/dart/D013_single_public_class/config.json +10 -0
- package/rules/dart/D014_unsafe_collection_access/config.json +10 -0
- package/rules/dart/D015_copywith_all_parameters/config.json +9 -0
- package/rules/dart/D016_project_should_have_tests/config.json +24 -0
- package/rules/dart/D017_pubspec_dependencies_review/config.json +23 -0
- package/rules/dart/D018_remove_commented_code/config.json +13 -0
- package/rules/dart/D019_avoid_single_child_multi_child_widget/config.json +21 -0
- package/rules/dart/D020_limit_if_else_branches/config.json +12 -0
- package/rules/dart/D021_avoid_negated_boolean_checks/config.json +14 -0
- package/rules/dart/D022_use_setstate_correctly/config.json +14 -0
- package/rules/dart/D023_avoid_unnecessary_method_overrides/config.json +13 -0
- package/rules/dart/D024_avoid_unnecessary_stateful_widget/config.json +9 -0
- package/rules/dart/D025_avoid_nested_conditional_expressions/config.json +9 -0
- package/skill-assets/sunlint-code-quality/AGENTS.md +80 -0
- package/skill-assets/sunlint-code-quality/SKILL.md +176 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C006-verb-noun-functions.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C013-no-dead-code.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C014-dependency-injection.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C017-no-constructor-logic.md +46 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C018-generic-errors.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C019-error-log-level.md +29 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C020-no-unused-imports.md +30 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C022-no-unused-variables.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C023-no-duplicate-names.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C024-centralize-constants.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C029-catch-log-root-cause.md +40 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C030-custom-error-classes.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C033-separate-data-access.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C035-error-context-logging.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C041-no-hardcoded-secrets.md +25 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C042-boolean-naming.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C052-controller-parsing.md +41 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C060-superclass-logic.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/C067-no-hardcoded-config.md +24 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S003-open-redirect.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S004-no-log-credentials.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S005-server-authorization.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S006-default-credentials.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S007-output-encoding.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S009-approved-crypto.md +37 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S010-csprng.md +32 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S011-encrypted-client-hello.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S012-secrets-management.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S013-tls-connections.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S016-no-sensitive-query-string.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S017-parameterized-queries.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S019-email-input-sanitization.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S020-eval-code-execution.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S022-context-escaping.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S023-dynamic-js-encoding.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S025-server-validation.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S026-tls-encryption.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S027-mtls-validation.md +40 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S028-upload-limits.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S029-csrf-protection.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S030-directory-browsing.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S031-secure-cookie-flag.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S032-httponly-cookie.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S033-samesite-cookie.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S034-host-prefix-cookie.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S035-app-hostnames.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S036-internal-file-paths.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S037-anti-cache-headers.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S039-tls-certificate-validation.md +41 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S041-logout-invalidation.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S042-long-lived-sessions.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S044-critical-changes-reauth.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S045-brute-force-protection.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S047-oauth-csrf-protection.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S048-oauth-redirect-validation.md +37 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S049-auth-code-expiry.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S050-token-entropy.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S051-password-length.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S052-otp-entropy.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S053-generic-error-messages.md +32 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S054-no-default-admin.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S055-content-type-validation.md +44 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S056-log-injection.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S057-synchronized-time.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/csharp/S058-ssrf-protection.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/java/C006-verb-noun-functions.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/C013-no-dead-code.md +175 -0
- package/skill-assets/sunlint-code-quality/rules/java/C014-dependency-injection.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/java/C017-no-constructor-logic.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/java/C018-generic-errors.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/java/C019-error-log-level.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/java/C020-no-unused-imports.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/java/C022-no-unused-variables.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/java/C023-no-duplicate-names.md +37 -0
- package/skill-assets/sunlint-code-quality/rules/java/C024-centralize-constants.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/C029-catch-log-root-cause.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/java/C030-custom-error-classes.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/java/C033-separate-data-access.md +46 -0
- package/skill-assets/sunlint-code-quality/rules/java/C035-error-context-logging.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/C041-no-hardcoded-secrets.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/java/C042-boolean-naming.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/java/C052-controller-parsing.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/java/C060-superclass-logic.md +32 -0
- package/skill-assets/sunlint-code-quality/rules/java/C067-no-hardcoded-config.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/java/S003-open-redirect.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/S004-no-log-credentials.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/S005-server-authorization.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/java/S006-default-credentials.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/java/S007-output-encoding.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/java/S009-approved-crypto.md +40 -0
- package/skill-assets/sunlint-code-quality/rules/java/S010-csprng.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/S011-encrypted-client-hello.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/java/S012-secrets-management.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/java/S013-tls-connections.md +40 -0
- package/skill-assets/sunlint-code-quality/rules/java/S016-no-sensitive-query-string.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/S017-parameterized-queries.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/java/S019-email-input-sanitization.md +32 -0
- package/skill-assets/sunlint-code-quality/rules/java/S020-eval-code-execution.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/java/S022-context-escaping.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/java/S023-dynamic-js-encoding.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/java/S025-server-validation.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/java/S026-tls-encryption.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/java/S027-mtls-validation.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/java/S028-upload-limits.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/java/S029-csrf-protection.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/java/S030-directory-browsing.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/S031-secure-cookie-flag.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/S032-httponly-cookie.md +31 -0
- package/skill-assets/sunlint-code-quality/rules/java/S033-samesite-cookie.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/java/S034-host-prefix-cookie.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/java/S035-app-hostnames.md +23 -0
- package/skill-assets/sunlint-code-quality/rules/java/S036-internal-file-paths.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/java/S037-anti-cache-headers.md +37 -0
- package/skill-assets/sunlint-code-quality/rules/java/S039-tls-certificate-validation.md +43 -0
- package/skill-assets/sunlint-code-quality/rules/java/S041-logout-invalidation.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/java/S042-long-lived-sessions.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/S044-critical-changes-reauth.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/java/S045-brute-force-protection.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/S047-oauth-csrf-protection.md +33 -0
- package/skill-assets/sunlint-code-quality/rules/java/S048-oauth-redirect-validation.md +25 -0
- package/skill-assets/sunlint-code-quality/rules/java/S049-auth-code-expiry.md +23 -0
- package/skill-assets/sunlint-code-quality/rules/java/S050-token-entropy.md +20 -0
- package/skill-assets/sunlint-code-quality/rules/java/S051-password-length.md +20 -0
- package/skill-assets/sunlint-code-quality/rules/java/S052-otp-entropy.md +23 -0
- package/skill-assets/sunlint-code-quality/rules/java/S053-generic-error-messages.md +21 -0
- package/skill-assets/sunlint-code-quality/rules/java/S054-no-default-admin.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/java/S055-content-type-validation.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/java/S056-log-injection.md +38 -0
- package/skill-assets/sunlint-code-quality/rules/java/S057-synchronized-time.md +35 -0
- package/skill-assets/sunlint-code-quality/rules/java/S058-ssrf-protection.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C006-verb-noun-functions.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C013-no-dead-code.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C014-dependency-injection.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C017-no-constructor-logic.md +68 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C018-generic-errors.md +46 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C019-error-log-level.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C020-no-unused-imports.md +44 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C022-no-unused-variables.md +39 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C023-no-duplicate-names.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C024-centralize-constants.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C029-catch-log-root-cause.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C030-custom-error-classes.md +72 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C033-separate-data-access.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C035-error-context-logging.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C041-no-hardcoded-secrets.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C042-boolean-naming.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C052-controller-parsing.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C060-superclass-logic.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/C067-no-hardcoded-config.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S003-open-redirect.md +66 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S004-no-log-credentials.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S005-server-authorization.md +75 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S006-default-credentials.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S007-output-encoding.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S009-approved-crypto.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S010-csprng.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S011-encrypted-client-hello.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S012-secrets-management.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S013-tls-connections.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S016-no-sensitive-query-string.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S017-parameterized-queries.md +41 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S019-email-input-sanitization.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S020-eval-code-execution.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S022-context-escaping.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S023-dynamic-js-encoding.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S025-server-validation.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S026-tls-encryption.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S027-mtls-validation.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S028-upload-limits.md +67 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S029-csrf-protection.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S030-directory-browsing.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S031-secure-cookie-flag.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S032-httponly-cookie.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S033-samesite-cookie.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S034-host-prefix-cookie.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S035-app-hostnames.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S036-internal-file-paths.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S037-anti-cache-headers.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S039-tls-certificate-validation.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S041-logout-invalidation.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S042-long-lived-sessions.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S044-critical-changes-reauth.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S045-brute-force-protection.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S047-oauth-csrf-protection.md +74 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S048-oauth-redirect-validation.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S049-auth-code-expiry.md +70 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S050-token-entropy.md +65 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S051-password-length.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S052-otp-entropy.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S053-generic-error-messages.md +66 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S054-no-default-admin.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S055-content-type-validation.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S056-log-injection.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S057-synchronized-time.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/kotlin/S058-ssrf-protection.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/php/C006-verb-noun-functions.md +46 -0
- package/skill-assets/sunlint-code-quality/rules/php/C013-no-dead-code.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/php/C014-dependency-injection.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/php/C017-no-constructor-logic.md +68 -0
- package/skill-assets/sunlint-code-quality/rules/php/C018-generic-errors.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/php/C019-error-log-level.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/C020-no-unused-imports.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/php/C022-no-unused-variables.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/php/C023-no-duplicate-names.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/php/C024-centralize-constants.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/php/C029-catch-log-root-cause.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/php/C030-custom-error-classes.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/php/C033-separate-data-access.md +79 -0
- package/skill-assets/sunlint-code-quality/rules/php/C035-error-context-logging.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/C041-no-hardcoded-secrets.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/php/C042-boolean-naming.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/php/C052-controller-parsing.md +66 -0
- package/skill-assets/sunlint-code-quality/rules/php/C060-superclass-logic.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/C067-no-hardcoded-config.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/php/S003-open-redirect.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/php/S004-no-log-credentials.md +67 -0
- package/skill-assets/sunlint-code-quality/rules/php/S005-server-authorization.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/php/S006-default-credentials.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/php/S007-output-encoding.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/php/S009-approved-crypto.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/php/S010-csprng.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/php/S011-encrypted-client-hello.md +41 -0
- package/skill-assets/sunlint-code-quality/rules/php/S012-secrets-management.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/php/S013-tls-connections.md +67 -0
- package/skill-assets/sunlint-code-quality/rules/php/S016-no-sensitive-query-string.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/php/S017-parameterized-queries.md +44 -0
- package/skill-assets/sunlint-code-quality/rules/php/S019-email-input-sanitization.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/S020-eval-code-execution.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/php/S022-context-escaping.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/php/S023-dynamic-js-encoding.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/php/S025-server-validation.md +63 -0
- package/skill-assets/sunlint-code-quality/rules/php/S026-tls-encryption.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/php/S027-mtls-validation.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/php/S028-upload-limits.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/php/S029-csrf-protection.md +65 -0
- package/skill-assets/sunlint-code-quality/rules/php/S030-directory-browsing.md +40 -0
- package/skill-assets/sunlint-code-quality/rules/php/S031-secure-cookie-flag.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/php/S032-httponly-cookie.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/S033-samesite-cookie.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/php/S034-host-prefix-cookie.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/php/S035-app-hostnames.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/php/S036-internal-file-paths.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/php/S037-anti-cache-headers.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/php/S039-tls-certificate-validation.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/S041-logout-invalidation.md +63 -0
- package/skill-assets/sunlint-code-quality/rules/php/S042-long-lived-sessions.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/php/S044-critical-changes-reauth.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/php/S045-brute-force-protection.md +67 -0
- package/skill-assets/sunlint-code-quality/rules/php/S047-oauth-csrf-protection.md +72 -0
- package/skill-assets/sunlint-code-quality/rules/php/S048-oauth-redirect-validation.md +54 -0
- package/skill-assets/sunlint-code-quality/rules/php/S049-auth-code-expiry.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/php/S050-token-entropy.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/php/S051-password-length.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/php/S052-otp-entropy.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/php/S053-generic-error-messages.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/php/S054-no-default-admin.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/php/S055-content-type-validation.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/php/S056-log-injection.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/php/S057-synchronized-time.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/php/S058-ssrf-protection.md +65 -0
- package/skill-assets/sunlint-code-quality/rules/python/C006-verb-noun-functions.md +30 -0
- package/skill-assets/sunlint-code-quality/rules/python/C013-no-dead-code.md +24 -0
- package/skill-assets/sunlint-code-quality/rules/python/C014-dependency-injection.md +68 -0
- package/skill-assets/sunlint-code-quality/rules/python/C017-no-constructor-logic.md +30 -0
- package/skill-assets/sunlint-code-quality/rules/python/C018-generic-errors.md +25 -0
- package/skill-assets/sunlint-code-quality/rules/python/C019-error-log-level.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/python/C020-no-unused-imports.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/python/C022-no-unused-variables.md +24 -0
- package/skill-assets/sunlint-code-quality/rules/python/C023-no-duplicate-names.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/python/C024-centralize-constants.md +27 -0
- package/skill-assets/sunlint-code-quality/rules/python/C029-catch-log-root-cause.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/python/C030-custom-error-classes.md +28 -0
- package/skill-assets/sunlint-code-quality/rules/python/C033-separate-data-access.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/python/C035-error-context-logging.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/python/C041-no-hardcoded-secrets.md +23 -0
- package/skill-assets/sunlint-code-quality/rules/python/C042-boolean-naming.md +24 -0
- package/skill-assets/sunlint-code-quality/rules/python/C052-controller-parsing.md +34 -0
- package/skill-assets/sunlint-code-quality/rules/python/C060-superclass-logic.md +26 -0
- package/skill-assets/sunlint-code-quality/rules/python/C067-no-hardcoded-config.md +22 -0
- package/skill-assets/sunlint-code-quality/rules/python/S003-open-redirect.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S004-no-log-credentials.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S005-server-authorization.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S006-default-credentials.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S007-output-encoding.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S009-approved-crypto.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S010-csprng.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S011-encrypted-client-hello.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S012-secrets-management.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S013-tls-connections.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S016-no-sensitive-query-string.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S017-parameterized-queries.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/python/S019-email-input-sanitization.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S020-eval-code-execution.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/python/S022-context-escaping.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S023-dynamic-js-encoding.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S025-server-validation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S026-tls-encryption.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S027-mtls-validation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S028-upload-limits.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S029-csrf-protection.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S030-directory-browsing.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S031-secure-cookie-flag.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S032-httponly-cookie.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S033-samesite-cookie.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S034-host-prefix-cookie.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S035-app-hostnames.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S036-internal-file-paths.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/python/S037-anti-cache-headers.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S039-tls-certificate-validation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S041-logout-invalidation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S042-long-lived-sessions.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S044-critical-changes-reauth.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S045-brute-force-protection.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S047-oauth-csrf-protection.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S048-oauth-redirect-validation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S049-auth-code-expiry.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S050-token-entropy.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S051-password-length.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S052-otp-entropy.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S053-generic-error-messages.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S054-no-default-admin.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S055-content-type-validation.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S056-log-injection.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S057-synchronized-time.md +16 -0
- package/skill-assets/sunlint-code-quality/rules/python/S058-ssrf-protection.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C006-verb-noun-functions.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C013-no-dead-code.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C014-dependency-injection.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C017-no-constructor-logic.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C018-generic-errors.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C019-error-log-level.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C020-no-unused-imports.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C022-no-unused-variables.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C023-no-duplicate-names.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C024-centralize-constants.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C029-catch-log-root-cause.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C030-custom-error-classes.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C033-separate-data-access.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C035-error-context-logging.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C041-no-hardcoded-secrets.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C042-boolean-naming.md +42 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C052-controller-parsing.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C060-superclass-logic.md +67 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/C067-no-hardcoded-config.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S003-open-redirect.md +76 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S004-no-log-credentials.md +71 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S005-server-authorization.md +68 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S006-default-credentials.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S007-output-encoding.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S009-approved-crypto.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S010-csprng.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S011-encrypted-client-hello.md +45 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S012-secrets-management.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S013-tls-connections.md +70 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S016-no-sensitive-query-string.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S017-parameterized-queries.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S019-email-input-sanitization.md +56 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S020-eval-code-execution.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S022-context-escaping.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S023-dynamic-js-encoding.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S025-server-validation.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S026-tls-encryption.md +47 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S027-mtls-validation.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S028-upload-limits.md +65 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S029-csrf-protection.md +62 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S030-directory-browsing.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S031-secure-cookie-flag.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S032-httponly-cookie.md +36 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S033-samesite-cookie.md +46 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S034-host-prefix-cookie.md +50 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S035-app-hostnames.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S036-internal-file-paths.md +53 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S037-anti-cache-headers.md +52 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S039-tls-certificate-validation.md +51 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S041-logout-invalidation.md +58 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S042-long-lived-sessions.md +55 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S044-critical-changes-reauth.md +69 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S045-brute-force-protection.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S047-oauth-csrf-protection.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S048-oauth-redirect-validation.md +59 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S049-auth-code-expiry.md +73 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S050-token-entropy.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S051-password-length.md +60 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S052-otp-entropy.md +49 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S053-generic-error-messages.md +61 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S054-no-default-admin.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S055-content-type-validation.md +64 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S056-log-injection.md +48 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S057-synchronized-time.md +57 -0
- package/skill-assets/sunlint-code-quality/rules/typescript/S058-ssrf-protection.md +63 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Only Approved Crypto Algorithms
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents the use of broken or weak cryptography that can be easily cracked
|
|
5
|
+
tags: cryptography, encryption, algorithms, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Only Approved Crypto Algorithms
|
|
9
|
+
|
|
10
|
+
Avoid using deprecated or weak cryptographic algorithms (like MD5, SHA1, DES, or Blowfish with small keys). These are technically broken and can be cracked in minutes by modern hardware.
|
|
11
|
+
|
|
12
|
+
**Incorrect (weak crypto):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: MD5 is broken
|
|
16
|
+
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
17
|
+
|
|
18
|
+
// VULNERABLE: DES is weak
|
|
19
|
+
Cipher c = Cipher.getInstance("DES");
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (approved crypto):**
|
|
23
|
+
|
|
24
|
+
```java
|
|
25
|
+
// SECURE: SHA-256 or SHA-512 for hashing
|
|
26
|
+
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
27
|
+
|
|
28
|
+
// SECURE: AES-256 for symmetric encryption
|
|
29
|
+
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
|
|
30
|
+
|
|
31
|
+
// SECURE: Argon2 or BCrypt for password hashing
|
|
32
|
+
String hash = BCrypt.hashpw(password, BCrypt.gensalt());
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Recommended Algorithms:**
|
|
36
|
+
- **Hashing:** SHA-256, SHA-512, SHA-3.
|
|
37
|
+
- **Encryption:** AES (128-bit or 256-bit) with GCM mode.
|
|
38
|
+
- **Passwords:** Argon2, BCrypt, SCrypt.
|
|
39
|
+
|
|
40
|
+
**Tools:** SonarQube (S1311), FindSecBugs
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use CSPRNG For Security Purposes
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents predictable random values that attackers can guess
|
|
5
|
+
tags: randomness, csprng, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use CSPRNG For Security Purposes
|
|
9
|
+
|
|
10
|
+
Standard random number generators (like `java.util.Random`) are predictable and should never be used for security-sensitive operations like generating passwords, session tokens, or initialization vectors (IVs).
|
|
11
|
+
|
|
12
|
+
**Incorrect (predictable random):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// DANGEROUS: Uses a linear congruential generator (LCG)
|
|
16
|
+
Random rand = new Random();
|
|
17
|
+
int token = rand.nextInt(1000000);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Correct (cryptographically secure random):**
|
|
21
|
+
|
|
22
|
+
```java
|
|
23
|
+
// SECURE: Uses SecureRandom (CSPRNG)
|
|
24
|
+
SecureRandom secureRand = new SecureRandom();
|
|
25
|
+
byte[] tokenBytes = new byte[32];
|
|
26
|
+
secureRand.nextBytes(tokenBytes);
|
|
27
|
+
String token = Base64.getEncoder().encodeToString(tokenBytes);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**When to use CSPRNG:**
|
|
31
|
+
- Session IDs and CSRF tokens.
|
|
32
|
+
- Password reset tokens.
|
|
33
|
+
- Cryptographic salts and IVs.
|
|
34
|
+
- Temporary passwords/OTPs.
|
|
35
|
+
|
|
36
|
+
**Tools:** SonarQube (S2245), FindSecBugs
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Enable Encrypted Client Hello (ECH)
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: protects Server Name Indication (SNI) from eavesdropping
|
|
5
|
+
tags: tls, ech, sni, privacy, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Enable Encrypted Client Hello (ECH)
|
|
9
|
+
|
|
10
|
+
ECH encrypts the Server Name Indication (SNI) in the TLS handshake, preventing network observers from seeing which specific host you are connecting to. This is primarily a privacy feature that prevents ISP/network-level tracking.
|
|
11
|
+
|
|
12
|
+
**About ECH:**
|
|
13
|
+
ECH is managed at the system/infrastructure level (JDK 22+ or via load balancers like Cloudflare/Nginx).
|
|
14
|
+
|
|
15
|
+
**Correct (ensuring Java client support):**
|
|
16
|
+
Java 22 and above have experimental support for ECH. Ensure your runtime environment and HTTP clients are configured to use the latest TLS features.
|
|
17
|
+
|
|
18
|
+
```java
|
|
19
|
+
// For Java 22+:
|
|
20
|
+
// -Djdk.tls.client.enableECH=true
|
|
21
|
+
// -Djdk.tls.server.enableECH=true
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Deployment:**
|
|
25
|
+
Enable ECH on your CDN (e.g., Cloudflare) or your entry-point Load Balancer.
|
|
26
|
+
|
|
27
|
+
**Tools:** Cloudflare, Wireshark (to verify SNI encryption), JDK 22 documentation
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Secrets Management For Backend Secrets
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents exposure of sensitive credentials in source code and version control
|
|
5
|
+
tags: secrets, management, vault, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Secrets Management For Backend Secrets
|
|
9
|
+
|
|
10
|
+
Sensitive data like API keys, database passwords, and private certificates should never be stored in plaintext in the codebase or checked into version control. Use a dedicated secrets management tool.
|
|
11
|
+
|
|
12
|
+
**Incorrect (secrets in source code):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Hardcoded API Key
|
|
16
|
+
public static final String STRIPE_SECRET = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Correct (external secrets management):**
|
|
20
|
+
|
|
21
|
+
```java
|
|
22
|
+
// 1. Environment Variables (Simple)
|
|
23
|
+
String apiKey = System.getenv("STRIPE_SECRET_KEY");
|
|
24
|
+
|
|
25
|
+
// 2. Spring Cloud Vault / Config (Recommended for Production)
|
|
26
|
+
@Value("${my.secret.key}")
|
|
27
|
+
private String secretKey;
|
|
28
|
+
|
|
29
|
+
// 3. AWS Secrets Manager / Azure Key Vault SDK
|
|
30
|
+
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId("stripe/live/key");
|
|
31
|
+
String secret = client.getSecretValue(request).getSecretString();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Tools:** HashiCorp Vault, AWS Secrets Manager, Google Cloud Secret Manager, Kubernetes Secrets
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Always Use TLS For All Connections
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: protects data in transit from eavesdropping and tampering
|
|
5
|
+
tags: tls, https, encryption, transport, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Always Use TLS For All Connections
|
|
9
|
+
|
|
10
|
+
Transmitting data over unencrypted HTTP, JDBC, or Redis connections exposes sensitive information to everyone on the network path. All connections in production must use TLS 1.2 or higher.
|
|
11
|
+
|
|
12
|
+
**Incorrect (unencrypted connections):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Using HTTP API
|
|
16
|
+
HttpClient client = HttpClient.newHttpClient();
|
|
17
|
+
HttpRequest request = HttpRequest.newBuilder()
|
|
18
|
+
.uri(URI.create("http://api.internal.com/data"))
|
|
19
|
+
.build();
|
|
20
|
+
|
|
21
|
+
// VULNERABLE: Unencrypted JDBC
|
|
22
|
+
String url = "jdbc:postgresql://db.server:5432/mydb";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (TLS/SSL everywhere):**
|
|
26
|
+
|
|
27
|
+
```java
|
|
28
|
+
// 1. HTTPS for all APIs
|
|
29
|
+
HttpRequest request = HttpRequest.newBuilder()
|
|
30
|
+
.uri(URI.create("https://api.internal.com/data"))
|
|
31
|
+
.build();
|
|
32
|
+
|
|
33
|
+
// 2. TLS for Database
|
|
34
|
+
String url = "jdbc:postgresql://db.server:5432/mydb?ssl=true&sslmode=verify-full";
|
|
35
|
+
|
|
36
|
+
// 3. Redis with TLS (Jedis/Lettuce)
|
|
37
|
+
RedisClient client = RedisClient.create("rediss://localhost:6380"); // Note: rediss://
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Tools:** SSLyze, Qualys SSL Labs, Snyk, Manual Review
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Do Not Pass Sensitive Data In Query String
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents sensitive data from leaking into browser history, server logs, and referrer headers
|
|
5
|
+
tags: query-string, sensitive-data, transport, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Do Not Pass Sensitive Data In Query String
|
|
9
|
+
|
|
10
|
+
URL parameters (the query string) are visible in browser history, bookmarks, proxy logs, and `Referer` headers. Sensitive data like passwords, tokens, or personal identifiers should never be part of a URL.
|
|
11
|
+
|
|
12
|
+
**Incorrect (sensitive query strings):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Token is in the URL
|
|
16
|
+
GET /api/user-details?auth_token=eyJhbGciOiJIUzI1NiI...
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Correct (headers or body):**
|
|
20
|
+
|
|
21
|
+
```java
|
|
22
|
+
// SECURE: Token passed in Authorization header
|
|
23
|
+
GET /api/user-details
|
|
24
|
+
Authorization: Bearer eyJhbGciOiJIUzI1NiI...
|
|
25
|
+
|
|
26
|
+
// SECURE: Data passed in POST body
|
|
27
|
+
POST /api/reset-password
|
|
28
|
+
Content-Type: application/json
|
|
29
|
+
{ "token": "...", "newPassword": "..." }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Always use:**
|
|
33
|
+
- `POST` / `PUT` for any request containing sensitive data.
|
|
34
|
+
- Standard headers like `Authorization` for tokens.
|
|
35
|
+
|
|
36
|
+
**Tools:** OWASP ZAP, Manual Audit
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Always Use Parameterized Queries
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents SQL and NoSQL injection attacks
|
|
5
|
+
tags: injection, sql, nosql, database, parameterized, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Always Use Parameterized Queries
|
|
9
|
+
|
|
10
|
+
SQL injection is one of the most critical security vulnerabilities. Directly concatenating user input into SQL strings allows attackers to manipulate queries, bypass authentication, or steal entire databases.
|
|
11
|
+
|
|
12
|
+
**Incorrect (string concatenation):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Direct concatenation
|
|
16
|
+
String userId = request.getParameter("id");
|
|
17
|
+
String query = "SELECT * FROM users WHERE id = '" + userId + "'";
|
|
18
|
+
Statement stmt = connection.createStatement();
|
|
19
|
+
ResultSet rs = stmt.executeQuery(query);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (parameterized queries):**
|
|
23
|
+
|
|
24
|
+
```java
|
|
25
|
+
// SECURE: Using PreparedStatement
|
|
26
|
+
String userId = request.getParameter("id");
|
|
27
|
+
String query = "SELECT * FROM users WHERE id = ?";
|
|
28
|
+
PreparedStatement pstmt = connection.prepareStatement(query);
|
|
29
|
+
pstmt.setString(1, userId);
|
|
30
|
+
ResultSet rs = pstmt.executeQuery();
|
|
31
|
+
|
|
32
|
+
// Using Spring Data JPA
|
|
33
|
+
@Query("SELECT u FROM User u WHERE u.id = :id")
|
|
34
|
+
User findUserById(@Param("id") String id);
|
|
35
|
+
|
|
36
|
+
// Using Hibernate Criteria
|
|
37
|
+
List<User> users = session.createSelectionQuery("from User where id = :id", User.class)
|
|
38
|
+
.setParameter("id", userId)
|
|
39
|
+
.getResultList();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Prevention Checklist:**
|
|
43
|
+
- Never use `Statement.executeQuery()` with concatenated strings.
|
|
44
|
+
- Always use `PreparedStatement` or a secure ORM (Hibernate, Spring Data).
|
|
45
|
+
- For NoSQL (e.g., MongoDB), use the driver's query builder instead of string parsing.
|
|
46
|
+
|
|
47
|
+
**Tools:** SonarQube (S2077, S3649), SpotBugs (FindSecBugs), Checkstyle, OWASP ZAP
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Sanitize Input Before Sending Emails
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: prevents email header injection and spam abuse
|
|
5
|
+
tags: email, injection, sanitization, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Sanitize Input Before Sending Emails
|
|
9
|
+
|
|
10
|
+
Email header injection occurs when user data is added to email headers (Subject, To, CC) without sanitizing newline characters. This allows attackers to add extra recipients or change the email content.
|
|
11
|
+
|
|
12
|
+
**Incorrect (vulnerable email sending):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Subject can contain \nBcc: victim@example.com
|
|
16
|
+
String subject = request.getParameter("subject");
|
|
17
|
+
SimpleMailMessage message = new SimpleMailMessage();
|
|
18
|
+
message.setSubject(subject);
|
|
19
|
+
mailSender.send(message);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (sanitization):**
|
|
23
|
+
|
|
24
|
+
```java
|
|
25
|
+
// SECURE: Remove newlines from all header fields
|
|
26
|
+
String sanitizedSubject = subject.replaceAll("[\\r\\n]", "");
|
|
27
|
+
SimpleMailMessage message = new SimpleMailMessage();
|
|
28
|
+
message.setSubject(sanitizedSubject);
|
|
29
|
+
mailSender.send(message);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Tools:** SonarQube, Manual Review
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Avoid Dynamic Code Execution
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents arbitrary code execution vulnerabilities
|
|
5
|
+
tags: injection, eval, dynamic-code, rce, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Avoid Dynamic Code Execution
|
|
9
|
+
|
|
10
|
+
Dynamic execution of code (using `ScriptEngine`, `ClassLoader.defineClass`, or unsecured reflection) allows attackers to execute arbitrary commands if they can control the input, leading to a full system compromise.
|
|
11
|
+
|
|
12
|
+
**Incorrect (dynamic script execution):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// DANGEROUS: Running JS strings from user input
|
|
16
|
+
ScriptEngineManager manager = new ScriptEngineManager();
|
|
17
|
+
ScriptEngine engine = manager.getEngineByName("JavaScript");
|
|
18
|
+
String script = request.getParameter("formula");
|
|
19
|
+
// Attacker: java.lang.Runtime.getRuntime().exec("rm -rf /")
|
|
20
|
+
engine.eval(script);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Correct (safe alternatives):**
|
|
24
|
+
|
|
25
|
+
```java
|
|
26
|
+
// 1. Use an expression language with a restricted sandbox (e.g., Spring Expression Language with validation)
|
|
27
|
+
StandardEvaluationContext context = new StandardEvaluationContext(data);
|
|
28
|
+
// STRICTLY validate or restrict what expressions are allowed
|
|
29
|
+
|
|
30
|
+
// 2. Use a safe math parser for formulas
|
|
31
|
+
Expression e = new ExpressionBuilder(request.getParameter("formula"))
|
|
32
|
+
.build();
|
|
33
|
+
double result = e.evaluate();
|
|
34
|
+
|
|
35
|
+
// 3. Prefer static logic
|
|
36
|
+
if ("add".equals(action)) {
|
|
37
|
+
result = a + b;
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Security Risks:**
|
|
42
|
+
- **Remote Code Execution (RCE):** The primary risk of using `eval()` or similar dynamic executors.
|
|
43
|
+
- **Resource Exhaustion:** Attackers might run heavy loops or consume memory.
|
|
44
|
+
|
|
45
|
+
**Tools:** SonarQube (S1523), SpotBugs (FindSecBugs), Manual Review
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Escape Data By Output Context
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: ensures correct encoding for each output context (HTML, JS, URL)
|
|
5
|
+
tags: xss, escaping, context, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Escape Data By Output Context
|
|
9
|
+
|
|
10
|
+
Different contexts require different escaping strategies. Using HTML encoding inside a JavaScript block or an HTML attribute does not fully prevent XSS.
|
|
11
|
+
|
|
12
|
+
**Incorrect (wrong encoding for context):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// WRONG: Using forHtml in a JS block
|
|
16
|
+
String name = request.getParameter("name");
|
|
17
|
+
out.println("<script>var x = '" + Encode.forHtml(name) + "';</script>");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Correct (matching encoder to context):**
|
|
21
|
+
|
|
22
|
+
```java
|
|
23
|
+
// SECURE: Use the context-specific encoder
|
|
24
|
+
out.println("<script>var x = '" + Encode.forJavaScript(name) + "';</script>");
|
|
25
|
+
out.println("<a href='/profile?u=" + Encode.forUriComponent(name) + "'>View</a>");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Tools:** OWASP Java Encoder
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Output Encoding For Dynamic JS/JSON
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents code injection in JavaScript contexts
|
|
5
|
+
tags: xss, javascript, json, encoding, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Output Encoding For Dynamic JS/JSON
|
|
9
|
+
|
|
10
|
+
When embedding user data into a JSON object that will be rendered inside a `<script>` tag, you must ensure that characters like `<` and `>` are escaped to prevent an attacker from closing the script tag and opening a new one.
|
|
11
|
+
|
|
12
|
+
**Incorrect (direct embedding):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Input </script><script>alert('xss')</script>
|
|
16
|
+
String jsonData = mapper.writeValueAsString(userData);
|
|
17
|
+
out.println("<script>var data = " + jsonData + ";</script>");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Correct (properly escaped JSON):**
|
|
21
|
+
|
|
22
|
+
```java
|
|
23
|
+
// SECURE: Use Jackson features or OWASP Encoder for JS
|
|
24
|
+
// Jackson can be configured to escape non-ascii characters
|
|
25
|
+
out.println("<script>var data = " + Encode.forJavaScript(jsonData) + ";</script>");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Tools:** Jackson `JsonGenerator.Feature.ESCAPE_NON_ASCII`, OWASP Java Encoder
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Always Validate Client Data Server-Side
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents malformed data and security bypasses
|
|
5
|
+
tags: validation, input, server-side, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Always Validate Client Data Server-Side
|
|
9
|
+
|
|
10
|
+
Client-side validation (HTML attributes, JavaScript) is for user experience only. It can be easily bypassed by using tools like Postman, `curl`, or browser developer tools. All sensitive data and business logic constraints must be re-validated on the server.
|
|
11
|
+
|
|
12
|
+
**Incorrect (trusting client input):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
@PostMapping("/api/purchase")
|
|
16
|
+
public void purchase(@RequestBody PurchaseRequest req) {
|
|
17
|
+
// VULNERABLE: Assuming price is correct from client
|
|
18
|
+
int total = req.getPrice() * req.getQuantity();
|
|
19
|
+
paymentService.charge(total);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Correct (server-side validation):**
|
|
24
|
+
|
|
25
|
+
```java
|
|
26
|
+
// 1. Use Bean Validation (JSR-380)
|
|
27
|
+
public class PurchaseRequest {
|
|
28
|
+
@NotNull
|
|
29
|
+
@Min(1)
|
|
30
|
+
private Long productId;
|
|
31
|
+
|
|
32
|
+
@Min(1)
|
|
33
|
+
@Max(100)
|
|
34
|
+
private int quantity;
|
|
35
|
+
|
|
36
|
+
// Do NOT include price in request; fetch it from DB
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@PostMapping("/api/purchase")
|
|
40
|
+
public ResponseEntity<?> purchase(@Valid @RequestBody PurchaseRequest req) {
|
|
41
|
+
// 2. Business logic validation
|
|
42
|
+
Product product = productRepo.findById(req.getProductId())
|
|
43
|
+
.orElseThrow(() -> new ProductNotFoundException());
|
|
44
|
+
|
|
45
|
+
int total = product.getPrice() * req.getQuantity();
|
|
46
|
+
paymentService.charge(total);
|
|
47
|
+
|
|
48
|
+
return ResponseEntity.ok().build();
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Validation Strategies:**
|
|
53
|
+
- **Whitelisting:** Only allow known-good input.
|
|
54
|
+
- **Strict Typing:** Use appropriate data types (e.g., `Long` for IDs, `BigDecimal` for currency).
|
|
55
|
+
- **Constraints:** Use `@NotNull`, `@Size`, `@Pattern` (Regex) in your DTOs.
|
|
56
|
+
- **Business Logic:** Validate state transitions (e.g., cannot "Cancel" an already "Shipped" order).
|
|
57
|
+
|
|
58
|
+
**Tools:** Hibernate Validator, Spring Boot Validation, OWASP ZAP, Manual Review
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TLS Encryption For All Connections
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: protects data in transit from interception and tampering
|
|
5
|
+
tags: tls, encryption, https, transport, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## TLS Encryption For All Connections
|
|
9
|
+
|
|
10
|
+
All network communications, whether between the client and server or between internal services, must be encrypted using TLS. Unencrypted connections (HTTP, raw JDBC) allow attackers to perform Man-in-the-Middle (MitM) attacks to steal sensitive data.
|
|
11
|
+
|
|
12
|
+
**Incorrect (unencrypted connections):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Using HTTP instead of HTTPS
|
|
16
|
+
HttpClient client = HttpClient.newHttpClient();
|
|
17
|
+
HttpRequest request = HttpRequest.newBuilder()
|
|
18
|
+
.uri(URI.create("http://api.production.sun-asterisk.vn/data"))
|
|
19
|
+
.build();
|
|
20
|
+
|
|
21
|
+
// VULNERABLE: Unencrypted database connection
|
|
22
|
+
String url = "jdbc:postgresql://db.sun-asterisk.vn:5432/mydb";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (TLS everywhere):**
|
|
26
|
+
|
|
27
|
+
```java
|
|
28
|
+
// 1. HTTPS for all external API calls
|
|
29
|
+
HttpRequest request = HttpRequest.newBuilder()
|
|
30
|
+
.uri(URI.create("https://api.production.sun-asterisk.vn/data"))
|
|
31
|
+
.build();
|
|
32
|
+
|
|
33
|
+
// 2. TLS for Database connections
|
|
34
|
+
String url = "jdbc:postgresql://db.sun-asterisk.vn:5432/mydb?ssl=true";
|
|
35
|
+
|
|
36
|
+
// 3. Enabling HSTS to force browsers to use HTTPS
|
|
37
|
+
// In Spring Security:
|
|
38
|
+
// http.headers(headers -> headers
|
|
39
|
+
// .httpStrictTransportSecurity(hsts -> hsts
|
|
40
|
+
// .includeSubDomains(true)
|
|
41
|
+
// .maxAgeInSeconds(31536000)
|
|
42
|
+
// )
|
|
43
|
+
// );
|
|
44
|
+
|
|
45
|
+
// 4. Redirecting HTTP to HTTPS
|
|
46
|
+
// http.requiresChannel(channel -> channel
|
|
47
|
+
// .anyRequest().requiresSecure()
|
|
48
|
+
// );
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Requirements:**
|
|
52
|
+
- All endpoints must strictly use HTTPS.
|
|
53
|
+
- Plain HTTP requests must be redirected to HTTPS.
|
|
54
|
+
- Use HSTS (`Strict-Transport-Security`) headers to prevent protocol downgrade attacks.
|
|
55
|
+
- Ensure internal service-to-service communication is also encrypted.
|
|
56
|
+
|
|
57
|
+
**Tools:** OWASP ZAP, SSLyze, Qualys SSL Labs, Manual Review
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Validate mTLS Certificates Before Auth
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: ensures that only clients with valid, trusted certificates can access the service
|
|
5
|
+
tags: tls, mtls, authentication, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Validate mTLS Certificates Before Auth
|
|
9
|
+
|
|
10
|
+
In a mutual TLS (mTLS) setup, the server must verify the client's certificate before allowing the request to proceed. This provides strong, certificate-based authentication.
|
|
11
|
+
|
|
12
|
+
**Implementation (Spring Security):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// http.x509(x509 -> x509
|
|
16
|
+
// .subjectPrincipalRegex("CN=(.*?)(?:,|$)")
|
|
17
|
+
// .userDetailsService(myUserDetailsService)
|
|
18
|
+
// );
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Key Points:**
|
|
22
|
+
- Ensure the Truststore only contains the CAs you explicitly trust.
|
|
23
|
+
- Verify expiration and revocation status of the client certificate.
|
|
24
|
+
- Link the Certificate's Common Name (CN) or Subject Alternative Name (SAN) to a specific user/service identity.
|
|
25
|
+
|
|
26
|
+
**Tools:** OpenSSL, Spring Security X.509
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Limit Upload File Size And Count
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: prevents Denial of Service (DoS) attacks via disk exhaustion or memory pressure
|
|
5
|
+
tags: uploads, dos, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Limit Upload File Size And Count
|
|
9
|
+
|
|
10
|
+
Unrestricted file uploads allow an attacker to crash the server by sending massive files or thousands of small files, filling up disk space or consuming all available memory.
|
|
11
|
+
|
|
12
|
+
**Incorrect (no limits):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: No limit on size
|
|
16
|
+
@PostMapping("/upload")
|
|
17
|
+
public void handleUpload(@RequestParam("file") MultipartFile file) {
|
|
18
|
+
file.transferTo(new File("/uploads/" + file.getOriginalFilename()));
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (configured limits):**
|
|
23
|
+
|
|
24
|
+
```java
|
|
25
|
+
// 1. Spring Boot Configuration (application.properties)
|
|
26
|
+
// spring.servlet.multipart.max-file-size=2MB
|
|
27
|
+
// spring.servlet.multipart.max-request-size=10MB
|
|
28
|
+
|
|
29
|
+
// 2. Manual check
|
|
30
|
+
if (file.getSize() > 2 * 1024 * 1024) {
|
|
31
|
+
throw new BadRequestException("File too large");
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Tools:** Spring Boot Multipart Properties, OWASP ZAP
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Apply CSRF Protection
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents Cross-Site Request Forgery attacks that could execute actions on behalf of the user
|
|
5
|
+
tags: csrf, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Apply CSRF Protection
|
|
9
|
+
|
|
10
|
+
CSRF attacks trick a logged-in user into sending a request to your application (e.g., via a hidden form on a malicious site). If the application relies only on cookies for authentication, the browser will include them, and the attack will succeed.
|
|
11
|
+
|
|
12
|
+
**Incorrect (no CSRF protection):**
|
|
13
|
+
|
|
14
|
+
```java
|
|
15
|
+
// VULNERABLE: Spring Security disabled CSRF
|
|
16
|
+
http.csrf(csrf -> csrf.disable());
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Correct (enabled and configured CSRF):**
|
|
20
|
+
|
|
21
|
+
```java
|
|
22
|
+
// 1. Spring Security (Enabled by default)
|
|
23
|
+
// For SPAs (Stateless/JWT):
|
|
24
|
+
// http.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()));
|
|
25
|
+
|
|
26
|
+
// 2. In Thymeleaf forms (automatic token insertion):
|
|
27
|
+
// <form th:action="@{/logout}" method="post">
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Defense Strategies:**
|
|
31
|
+
- **Synchronizer Token Pattern:** Include a random token in every state-changing request (POST, PUT, DELETE).
|
|
32
|
+
- **SameSite Cookie Attribute:** Set `SameSite=Lax` or `Strict`.
|
|
33
|
+
- **Custom Headers:** For AJAX requests, require a custom header (e.g., `X-Requested-With`) which cannot be added cross-site without CORS permission.
|
|
34
|
+
|
|
35
|
+
**Tools:** Spring Security, OWASP ZAP
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Disable Directory Browsing
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: prevents attackers from seeing the directory structure and identifying sensitive files
|
|
5
|
+
tags: configuration, server, directory-browsing, security, java
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Disable Directory Browsing
|
|
9
|
+
|
|
10
|
+
If directory browsing is enabled, an attacker visiting a folder without an `index.html` file can see all files in that directory. This often leads to the discovery of sensitive configuration files, source code backups, or uploaded data.
|
|
11
|
+
|
|
12
|
+
**How to Disable:**
|
|
13
|
+
|
|
14
|
+
**1. In Embedded Tomcat (Spring Boot):**
|
|
15
|
+
It is disabled by default. Do not change the `server.tomcat.basedir` to a public-facing path without index files.
|
|
16
|
+
|
|
17
|
+
**2. In Standard `web.xml` (Legacy):**
|
|
18
|
+
```xml
|
|
19
|
+
<servlet>
|
|
20
|
+
<servlet-name>default</servlet-name>
|
|
21
|
+
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
|
|
22
|
+
<init-param>
|
|
23
|
+
<param-name>listings</param-name>
|
|
24
|
+
<param-value>false</param-value> <!-- SECURE: Set to false -->
|
|
25
|
+
</init-param>
|
|
26
|
+
</servlet>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**3. Using Spring Security:**
|
|
30
|
+
```java
|
|
31
|
+
// Prevent direct access to static resource directories
|
|
32
|
+
http.authorizeHttpRequests(auth -> auth
|
|
33
|
+
.requestMatchers("/static/**").permitAll()
|
|
34
|
+
.requestMatchers("/config/**").denyAll()
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Tools:** OWASP ZAP, Manual Review
|