diff --git a/.changes/0b4c83e2-93d6-47f1-bcf3-83233e4438b2.json b/.changes/0b4c83e2-93d6-47f1-bcf3-83233e4438b2.json new file mode 100644 index 00000000000..861cf9c92de --- /dev/null +++ b/.changes/0b4c83e2-93d6-47f1-bcf3-83233e4438b2.json @@ -0,0 +1,6 @@ +{ + "id": "0b4c83e2-93d6-47f1-bcf3-83233e4438b2", + "type": "bugfix", + "description": "Reject carriage return and line feed characters in ECS container authorization tokens", + "module": "aws-config" +} diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProvider.kt index 116e553330f..9e598fe8bac 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProvider.kt @@ -116,7 +116,7 @@ public class EcsCredentialsProvider( ?: AwsSdkSetting.AwsContainerAuthorizationToken.resolve(platformProvider) ?: return null - if (token.contains("\r\n")) { + if (token.contains('\r') || token.contains('\n')) { throw CredentialsProviderException("Token contains illegal line break sequence.") } diff --git a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProviderTest.kt b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProviderTest.kt index 6d1ba64f044..52a5f28353c 100644 --- a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProviderTest.kt +++ b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProviderTest.kt @@ -386,7 +386,7 @@ class EcsCredentialsProviderTest { @Test fun testAuthTokenIllegal() = runTest { - val token = "auth\r\ntoken" + listOf("auth\rtoken", "auth\ntoken", "auth\r\ntoken").forEach { token -> val engine = TestConnection() val testPlatform = TestPlatformProvider.of( @@ -400,12 +400,13 @@ class EcsCredentialsProviderTest { assertFailsWith { provider.resolve() }.message.shouldContain("Token contains illegal line break sequence.") + } } @Test fun testAuthTokenFileIllegal() = runTest { + listOf("auth\rtoken", "auth\ntoken", "auth\r\ntoken").forEach { token -> val tokenFile = "/path/to/token" - val token = "auth\r\ntoken" val engine = TestConnection() val testPlatform = TestPlatformProvider.of( @@ -422,6 +423,7 @@ class EcsCredentialsProviderTest { assertFailsWith { provider.resolve() }.message.shouldContain("Token contains illegal line break sequence.") + } } @Test