Skip to content

Commit fca6f7d

Browse files
authored
chore(abg): remove custom billion laughs attack protection (#1739)
kaml added proper support for configuring enablement of anchors and aliases. It's possible to remove the workaround of directly using snakeyaml-engine-kmp, and while here, depend on a sane default of 100 max aliases.
1 parent 22f5693 commit fca6f7d

3 files changed

Lines changed: 6 additions & 15 deletions

File tree

action-binding-generator/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ version = rootProject.version
1313

1414
dependencies {
1515
implementation("com.squareup:kotlinpoet:2.0.0")
16-
implementation("it.krzeminski:snakeyaml-engine-kmp:3.0.3")
1716
implementation("com.charleskorn.kaml:kaml:0.66.0")
1817
implementation("io.github.oshai:kotlin-logging:7.0.3")
1918
implementation(projects.sharedInternal)

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingAc
1313
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
1414
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.fetchUri
1515
import io.github.typesafegithub.workflows.actionbindinggenerator.utils.toPascalCase
16-
import it.krzeminski.snakeyaml.engine.kmp.api.Load
1716
import kotlinx.serialization.Serializable
1817
import kotlinx.serialization.decodeFromString
1918
import java.io.IOException
@@ -83,7 +82,7 @@ private fun ActionCoords.fetchTypingsForOlderVersionFromCatalog(fetchUri: (URI)
8382
} catch (e: IOException) {
8483
return null
8584
}
86-
val metadata = yaml.protectedDecodeFromString<CatalogMetadata>(metadataYml)
85+
val metadata = yaml.decodeFromString<CatalogMetadata>(metadataYml)
8786
val requestedVersionAsInt = this.version.versionToIntOrNull() ?: return null
8887
val fallbackVersion =
8988
metadata.versionsWithTypings
@@ -151,18 +150,11 @@ private inline fun <reified T> Yaml.decodeFromStringOrDefaultIfEmpty(
151150
default: T,
152151
): T =
153152
if (text.isNotBlank()) {
154-
protectedDecodeFromString(text)
153+
decodeFromString(text)
155154
} else {
156155
default
157156
}
158157

159-
private inline fun <reified T> Yaml.protectedDecodeFromString(text: String): T {
160-
// protect against billion laughs attack until
161-
// https://github.com/charleskorn/kaml/pull/620 is available
162-
Load().loadOne(text)
163-
return decodeFromString(text)
164-
}
165-
166158
private fun String.versionToInt() = this.versionToIntOrNull() ?: error("Version '$this' cannot be treated as numeric!")
167159

168160
private fun String.versionToIntOrNull() = lowercase().removePrefix("v").toIntOrNull()
@@ -172,7 +164,7 @@ private val yaml =
172164
configuration =
173165
Yaml.default.configuration.copy(
174166
strictMode = false,
175-
anchorsAndAliases = AnchorsAndAliases.Permitted(10u),
167+
anchorsAndAliases = AnchorsAndAliases.Permitted(),
176168
),
177169
)
178170

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator.typing
22

3+
import com.charleskorn.kaml.ForbiddenAnchorOrAliasException
34
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
45
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.CommitHash
56
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
67
import io.kotest.assertions.throwables.shouldThrow
78
import io.kotest.core.spec.style.FunSpec
89
import io.kotest.matchers.shouldBe
9-
import it.krzeminski.snakeyaml.engine.kmp.exceptions.YamlEngineException
1010
import java.io.IOException
1111
import java.net.URI
1212

@@ -535,10 +535,10 @@ class TypesProvidingTest :
535535

536536
// Expect
537537
val exception =
538-
shouldThrow<YamlEngineException> {
538+
shouldThrow<ForbiddenAnchorOrAliasException> {
539539
actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
540540
}
541-
exception.message shouldBe "Number of aliases for non-scalar nodes exceeds the specified max=50"
541+
exception.message shouldBe "Maximum number of aliases has been reached."
542542
}
543543
}
544544

0 commit comments

Comments
 (0)