Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vulnerable-code): Correct an URL escape fixup case #8224

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
mnonnenmacher marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
}
}

private val BACKSLASH_ESCAPE_REGEX = """\\\\\\?(.)""".toRegex()
private val BACKSLASH_ESCAPE_REGEX = """\\\\?(.)""".toRegex()

internal fun String.fixupUrlEscaping(): String =
replace("""\/""", "/").replace(BACKSLASH_ESCAPE_REGEX) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.maps.shouldNotBeEmpty
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain

import java.io.File
import java.net.URI
Expand Down Expand Up @@ -141,29 +140,6 @@ class VulnerableCodeTest : WordSpec({
strutsResult.vulnerabilities should containExactlyInAnyOrder(expStrutsVulnerabilities)
}

"handle invalid URIs in references gracefully" {
server.stubPackagesRequest("response_invalid_uri.json")
val vulnerableCode = createVulnerableCode(server)
val packagesToAdvise = inputPackagesFromAnalyzerResult()

val result = vulnerableCode.retrievePackageFindings(packagesToAdvise).mapKeys { it.key.id }

val langResult = result.getValue(idLang)
val issues = langResult.summary.issues
issues shouldHaveSize 1
with(issues.first()) {
severity shouldBe Severity.HINT
source shouldBe ADVISOR_NAME
message shouldContain "oracle:siebel_engineering_-_installer_\\&_deployment:*:*:*:*:*:*:*:*"
}

val expLangVulnerability = Vulnerability(
id = "CVE-2014-8242",
references = emptyList()
)
langResult.vulnerabilities should containExactly(expLangVulnerability)
}

"extract the CVE ID from an alias" {
server.stubPackagesRequest("response_junit.json", request = generatePackagesRequest(idJUnit))
val vulnerableCode = createVulnerableCode(server)
Expand Down Expand Up @@ -296,7 +272,7 @@ class VulnerableCodeTest : WordSpec({
}

"fixup a wrongly escaped plus" {
val u = """https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:hyperion_bi\\\+:*:*:*:*:*:*:*:*"""
val u = """https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:hyperion_bi\+:*:*:*:*:*:*:*:*"""

URI.create(u.fixupUrlEscaping()) shouldBe URI(
"""https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:hyperion_bi%2B:*:*:*:*:*:*:*:*"""
Expand Down
Loading