@hoanghainh/komagu 1.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/assess/lsa/CHANGELOG.md +6 -0
  3. package/assess/lsa/VERSION +1 -1
  4. package/assess/lsa/adapters/build_adapters.py +16 -8
  5. package/assess/lsa/adapters/codex/README.md +1 -1
  6. package/assess/lsa/adapters/generic/README.md +1 -1
  7. package/assess/lsa/knowledge/severity-and-cwe.md +1 -1
  8. package/assess/lsa/scripts/baseline.py +5 -2
  9. package/assess/lsa/scripts/findings_to_sarif.py +24 -1
  10. package/assess/lsa/tests/test_adapters.py +21 -2
  11. package/assess/lsa/tests/test_baseline.py +8 -0
  12. package/assess/lsa/tests/test_contract_groundwork.py +7 -7
  13. package/operate/cli/__init__.py +1 -1
  14. package/operate/cli/commands/scan.py +2 -7
  15. package/operate/cli/commands/test.py +1 -1
  16. package/operate/cli/env.py +4 -20
  17. package/operate/cross_user_tester/persona_matrix.py +5 -1
  18. package/operate/devsecops/pipeline.py +5 -5
  19. package/operate/exploit/generator.py +5 -1
  20. package/operate/lsa_sarif/lsa_to_sarif.py +24 -2
  21. package/operate/lsa_sarif/sarif_findings.py +96 -0
  22. package/operate/remediator/runner.py +1 -5
  23. package/operate/remediator/strategies.py +1 -1
  24. package/operate/tests/test_cli_baseline.py +1 -9
  25. package/operate/tests/test_cli_env.py +8 -29
  26. package/operate/tests/test_cross_user_pipeline.py +2 -2
  27. package/operate/tests/test_exploit_and_virtual_patch.py +3 -3
  28. package/operate/tests/test_npm_package.py +2 -16
  29. package/operate/tests/test_sarif_from_scan.py +156 -0
  30. package/package.json +2 -4
  31. package/remediate/authz/README.md +1 -1
  32. package/remediate/authz/dotnet/src/Komagu.Security.Authorization/DefaultKomaguAuthorizationService.cs +1 -1
  33. package/remediate/authz/dotnet/src/Komagu.Security.Authorization/SecurityAuditEvent.cs +2 -2
  34. package/remediate/authz/golang/authz.go +1 -1
  35. package/remediate/authz/nodejs/src/service.js +1 -1
  36. package/remediate/authz/nodejs/tests/test-authz.js +1 -1
  37. package/remediate/authz/patcher.py +3 -4
  38. package/remediate/authz/python/komagu_authz/models.py +2 -2
  39. package/remediate/authz/python/tests/test_fastapi_adapter.py +1 -1
  40. package/remediate/authz/python/tests/test_fastapi_d5_crosstest.py +1 -1
  41. package/remediate/authz/python/tests/test_python_authz.py +3 -3
  42. package/remediate/authz/spring/src/main/kotlin/io/komagu/security/authorization/DefaultKomaguSecurityManager.kt +1 -1
  43. package/remediate/authz/spring/src/main/kotlin/io/komagu/security/authorization/SecurityAuditEvent.kt +1 -2
  44. package/remediate/authz/tests/test_bola_patcher.py +1 -1
  45. package/remediate/edge/coraza/rules/coraza-crs-custom.conf +3 -4
  46. package/remediate/edge/coraza/virtual_patcher.py +4 -6
  47. package/remediate/edge/docker-compose.yml +1 -1
  48. package/remediate/ekyc/server/jpki_verifier.py +2 -8
  49. package/remediate/ekyc/server/tokenization.py +2 -8
  50. package/remediate/identity/README.md +5 -5
  51. package/remediate/identity/dotnet/src/Komagu.Security.Identity/KomaguOidcOptions.cs +2 -2
  52. package/remediate/identity/dotnet/tests/Komagu.Security.Identity.Tests/TestTokenGenerator.cs +1 -1
  53. package/remediate/identity/dotnet/tests/Komagu.Security.Identity.Tests/TokenValidationTests.cs +1 -1
  54. package/remediate/identity/python/komagu_identity/oidc_validator.py +2 -8
  55. package/remediate/identity/python/tests/test_oidc_validator.py +1 -1
  56. package/remediate/identity/spring/src/main/kotlin/io/komagu/security/identity/KomaguOidcProperties.kt +2 -2
  57. package/remediate/identity/spring/src/test/kotlin/io/komagu/security/identity/KomaguIdentityAutoConfigurationTest.kt +2 -2
  58. package/remediate/identity/spring/src/test/kotlin/io/komagu/security/identity/TestJwtFactory.kt +1 -1
  59. package/remediate/identity/spring/src/test/kotlin/io/komagu/security/identity/TokenValidationIntegrationTest.kt +1 -1
  60. package/remediate/identity/test-env/realm-komagu.json +1 -1
  61. package/remediate/legacy_shims/coldfusion/KomaguSecurityShim.cfc +5 -5
  62. package/remediate/query/README.md +1 -1
  63. package/remediate/query/dotnet/src/Komagu.Security.Query.Analyzers/DiagnosticIds.cs +1 -1
  64. package/remediate/query/dotnet/src/Komagu.Security.Query.Analyzers/Komagu.Security.Query.Analyzers.csproj +1 -1
  65. package/remediate/query/spring/src/main/kotlin/io/komagu/security/query/detekt/KomaguRuleSetProvider.kt +1 -1
  66. package/remediate/resilience/dr/dr_manager.py +2 -8
  67. package/remediate/resilience/dr/runbook.md +2 -2
  68. package/remediate/resilience/terraform/variables.tf +1 -1
  69. package/remediate/tenancy/audit/audit_trail.py +2 -8
  70. package/remediate/tenancy/crypto/byok_manager.py +2 -8
  71. package/remediate/tenancy/middleware/tenant_context.py +2 -8
  72. package/remediate/tenancy/sql/rls_isolation.sql +11 -11
  73. package/remediate/tenancy/sql/schema_per_tenant.sql +7 -7
  74. package/remediate/tenancy/test_sql_postgres.py +1 -1
  75. package/remediate/tenancy/tests/test_tenancy.py +4 -4
  76. package/bin/komainu +0 -16
  77. package/bin/komainu-legacy.js +0 -16
  78. package/remediate/ekyc/tests/test_legacy_env.py +0 -33
  79. package/remediate/identity/python/tests/test_legacy_env.py +0 -33
  80. package/remediate/identity/spring/src/main/kotlin/io/komagu/security/identity/LegacyKomainuPropertiesPostProcessor.kt +0 -60
  81. package/remediate/identity/spring/src/main/resources/META-INF/spring.factories +0 -2
  82. package/remediate/identity/spring/src/test/kotlin/io/komagu/security/identity/LegacyKomainuPropertiesPostProcessorTest.kt +0 -86
  83. package/remediate/resilience/tests/test_legacy_env.py +0 -33
  84. package/remediate/tenancy/tests/test_legacy_env.py +0 -49
@@ -1,60 +0,0 @@
1
- package io.komagu.security.identity
2
-
3
- import org.springframework.boot.SpringApplication
4
- import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor
5
- import org.springframework.boot.env.EnvironmentPostProcessor
6
- import org.springframework.boot.logging.DeferredLogFactory
7
- import org.springframework.core.Ordered
8
- import org.springframework.core.env.ConfigurableEnvironment
9
- import org.springframework.core.env.EnumerablePropertySource
10
- import org.springframework.core.env.MapPropertySource
11
-
12
- /**
13
- * Maps deprecated pre-rename `komainu.security.*` properties (and `KOMAINU_SECURITY_*` env vars)
14
- * onto `komagu.security.*` (#290). The mapped values are added last, so any `komagu.security.*`
15
- * value set explicitly still wins. Remove in the next major release.
16
- */
17
- class LegacyKomainuPropertiesPostProcessor(logFactory: DeferredLogFactory) : EnvironmentPostProcessor, Ordered {
18
-
19
- private val log = logFactory.getLog(javaClass)
20
-
21
- override fun postProcessEnvironment(environment: ConfigurableEnvironment, application: SpringApplication?) {
22
- val mapped = linkedMapOf<String, Any>()
23
- // Property sources iterate highest precedence first, so the first legacy value seen wins.
24
- environment.propertySources
25
- .filterIsInstance<EnumerablePropertySource<*>>()
26
- .filter { it.name != SOURCE_NAME }
27
- .forEach { collectLegacy(it, mapped) }
28
- if (mapped.isEmpty()) return
29
- log.warn(
30
- "komainu.security.* properties are deprecated, rename them to komagu.security.* " +
31
- "(mapped: ${mapped.keys.joinToString()})"
32
- )
33
- environment.propertySources.addLast(MapPropertySource(SOURCE_NAME, mapped))
34
- }
35
-
36
- private fun collectLegacy(source: EnumerablePropertySource<*>, mapped: MutableMap<String, Any>) {
37
- for (name in source.propertyNames) {
38
- val current = currentName(name)
39
- if (current != null && current !in mapped) {
40
- source.getProperty(name)?.let { mapped[current] = it }
41
- }
42
- }
43
- }
44
-
45
- override fun getOrder(): Int = ConfigDataEnvironmentPostProcessor.ORDER + 1
46
-
47
- companion object {
48
- const val SOURCE_NAME = "legacyKomainuProperties"
49
- private const val LEGACY_PREFIX = "komainu.security."
50
- private const val LEGACY_ENV_PREFIX = "KOMAINU_SECURITY_"
51
- private const val PREFIX = "komagu.security."
52
-
53
- fun currentName(name: String): String? = when {
54
- name.startsWith(LEGACY_PREFIX) -> PREFIX + name.removePrefix(LEGACY_PREFIX)
55
- name.startsWith(LEGACY_ENV_PREFIX) ->
56
- PREFIX + name.removePrefix(LEGACY_ENV_PREFIX).lowercase().replace('_', '.')
57
- else -> null
58
- }
59
- }
60
- }
@@ -1,2 +0,0 @@
1
- org.springframework.boot.env.EnvironmentPostProcessor=\
2
- io.komagu.security.identity.LegacyKomainuPropertiesPostProcessor
@@ -1,86 +0,0 @@
1
- package io.komagu.security.identity
2
-
3
- import org.junit.jupiter.api.Assertions.assertEquals
4
- import org.junit.jupiter.api.Assertions.assertNull
5
- import org.junit.jupiter.api.Assertions.assertTrue
6
- import org.junit.jupiter.api.Test
7
- import org.springframework.boot.context.properties.bind.Binder
8
- import org.springframework.boot.logging.DeferredLogFactory
9
- import org.springframework.core.env.MapPropertySource
10
- import org.springframework.core.env.PropertySource
11
- import org.springframework.core.env.StandardEnvironment
12
- import org.springframework.core.env.SystemEnvironmentPropertySource
13
-
14
- class LegacyKomainuPropertiesPostProcessorTest {
15
-
16
- private val processor = LegacyKomainuPropertiesPostProcessor(DeferredLogFactory { it.get() })
17
-
18
- private fun bind(env: StandardEnvironment): KomaguOidcProperties =
19
- Binder.get(env).bind("komagu.security.oidc", KomaguOidcProperties::class.java).orElseGet { KomaguOidcProperties() }
20
-
21
- private fun envWith(vararg sources: PropertySource<*>): StandardEnvironment {
22
- val env = StandardEnvironment()
23
- env.propertySources.toList().forEach { env.propertySources.remove(it.name) }
24
- sources.forEach { env.propertySources.addLast(it) }
25
- return env
26
- }
27
-
28
- @Test
29
- fun `legacy properties bind to the komagu prefix`() {
30
- val env = envWith(
31
- MapPropertySource(
32
- "app",
33
- mapOf(
34
- "komainu.security.oidc.issuer" to "https://auth.example.com",
35
- "komainu.security.oidc.jwk-set-uri" to "https://auth.example.com/certs",
36
- "komainu.security.oidc.clock-skew-seconds" to "30"
37
- )
38
- )
39
- )
40
- processor.postProcessEnvironment(env, null)
41
-
42
- val props = bind(env)
43
- assertEquals("https://auth.example.com", props.issuer)
44
- assertEquals("https://auth.example.com/certs", props.jwkSetUri)
45
- assertEquals(30L, props.clockSkewSeconds)
46
- }
47
-
48
- @Test
49
- fun `explicit komagu properties win over legacy ones`() {
50
- val env = envWith(
51
- MapPropertySource("low", mapOf("komagu.security.oidc.audience" to "new-api")),
52
- MapPropertySource("high", mapOf("komainu.security.oidc.audience" to "old-api"))
53
- )
54
- processor.postProcessEnvironment(env, null)
55
-
56
- assertEquals("new-api", bind(env).audience)
57
- }
58
-
59
- @Test
60
- fun `legacy environment variables are mapped`() {
61
- val env = envWith(
62
- SystemEnvironmentPropertySource(
63
- "systemEnvironment",
64
- mapOf<String, Any>("KOMAINU_SECURITY_OIDC_ALLOWINSECUREHTTPJWKS" to "true")
65
- )
66
- )
67
- processor.postProcessEnvironment(env, null)
68
-
69
- assertEquals(true, bind(env).allowInsecureHttpJwks)
70
- }
71
-
72
- @Test
73
- fun `nothing is added without legacy properties`() {
74
- val env = envWith(MapPropertySource("app", mapOf("komagu.security.oidc.audience" to "x")))
75
- processor.postProcessEnvironment(env, null)
76
-
77
- assertNull(env.propertySources.get(LegacyKomainuPropertiesPostProcessor.SOURCE_NAME))
78
- }
79
-
80
- @Test
81
- fun `post processor is registered in spring factories`() {
82
- val factories = javaClass.classLoader.getResource("META-INF/spring.factories")!!.readText()
83
- assertTrue("org.springframework.boot.env.EnvironmentPostProcessor" in factories)
84
- assertTrue(LegacyKomainuPropertiesPostProcessor::class.java.name in factories)
85
- }
86
- }
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env python3
2
- """KOMAGU_* environment variables with the deprecated KOMAINU_* fallback (#290)."""
3
-
4
- from __future__ import annotations
5
-
6
- import os
7
- import unittest
8
- import warnings
9
- from unittest.mock import patch
10
-
11
- from remediate.resilience.dr import dr_manager
12
-
13
- MODULES = (dr_manager,)
14
-
15
-
16
- class TestLegacyEnvFallback(unittest.TestCase):
17
- def test_new_name_wins_without_warning(self) -> None:
18
- env = {"KOMAGU_DR_METADATA_PATH": "new", "KOMAINU_DR_METADATA_PATH": "old"}
19
- for mod in MODULES:
20
- with self.subTest(module=mod.__name__), patch.dict(os.environ, env), warnings.catch_warnings(record=True) as caught:
21
- warnings.simplefilter("always")
22
- self.assertEqual(mod._env("DR_METADATA_PATH"), "new")
23
- self.assertEqual(caught, [])
24
-
25
- def test_legacy_name_is_read_with_deprecation_warning(self) -> None:
26
- for mod in MODULES:
27
- with self.subTest(module=mod.__name__), patch.dict(os.environ, {"KOMAINU_DR_METADATA_PATH": "old"}, clear=True):
28
- with self.assertWarnsRegex(DeprecationWarning, "KOMAINU_DR_METADATA_PATH is deprecated"):
29
- self.assertEqual(mod._env("DR_METADATA_PATH"), "old")
30
-
31
-
32
- if __name__ == "__main__":
33
- unittest.main()
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env python3
2
- """KOMAGU_* environment variables with the deprecated KOMAINU_* fallback (#290)."""
3
-
4
- from __future__ import annotations
5
-
6
- import os
7
- import unittest
8
- import warnings
9
- from unittest.mock import patch
10
-
11
- from remediate.tenancy.audit import audit_trail
12
- from remediate.tenancy.crypto import byok_manager
13
- from remediate.tenancy.middleware import tenant_context
14
-
15
- # Each drop-in module carries its own copy of _env; other suites test theirs.
16
- MODULES = (audit_trail, byok_manager, tenant_context)
17
-
18
-
19
- class TestLegacyEnvFallback(unittest.TestCase):
20
- def test_new_name_wins_without_warning(self) -> None:
21
- env = {"KOMAGU_AUDIT_HMAC_KEY": "new", "KOMAINU_AUDIT_HMAC_KEY": "old"}
22
- for mod in MODULES:
23
- with self.subTest(module=mod.__name__), patch.dict(os.environ, env), warnings.catch_warnings(record=True) as caught:
24
- warnings.simplefilter("always")
25
- self.assertEqual(mod._env("AUDIT_HMAC_KEY"), "new")
26
- self.assertEqual(caught, [])
27
-
28
- def test_legacy_name_is_read_with_deprecation_warning(self) -> None:
29
- for mod in MODULES:
30
- with self.subTest(module=mod.__name__), patch.dict(os.environ, {"KOMAINU_INTERNAL_SERVICE_SECRET": "old"}, clear=True):
31
- with self.assertWarnsRegex(DeprecationWarning, "KOMAINU_INTERNAL_SERVICE_SECRET is deprecated"):
32
- self.assertEqual(mod._env("INTERNAL_SERVICE_SECRET"), "old")
33
-
34
- def test_default_when_unset(self) -> None:
35
- for mod in MODULES:
36
- with self.subTest(module=mod.__name__), patch.dict(os.environ, {}, clear=True):
37
- self.assertEqual(mod._env("ENV", ""), "")
38
- self.assertIsNone(mod._env("ENV"))
39
-
40
- def test_legacy_audit_key_still_configures_audit_trail(self) -> None:
41
- key = "k" * 32
42
- with patch.dict(os.environ, {"KOMAINU_AUDIT_HMAC_KEY": key}, clear=True), warnings.catch_warnings():
43
- warnings.simplefilter("ignore", DeprecationWarning)
44
- trail = audit_trail.TenantAuditTrail()
45
- self.assertEqual(trail.hmac_key, key.encode("utf-8"))
46
-
47
-
48
- if __name__ == "__main__":
49
- unittest.main()