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

[CVE-2019-1010260] [SECURITY] Resolve dependenices over HTTPS instead of HTTP #332

Merged
merged 2 commits into from
Jan 31, 2019
Merged
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
60 changes: 40 additions & 20 deletions ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -609,28 +609,48 @@ object Main {
private fun buildDependencyResolver(): MavenDependencyResolver {
val mavenLocal = File(File(System.getProperty("user.home"), ".m2"), "repository")
mavenLocal.mkdirsOrFail()
val mavenRepositories = listOf(
RemoteRepository.Builder(
"central", "default", "https://repo1.maven.org/maven2/"
).setSnapshotPolicy(RepositoryPolicy(false, UPDATE_POLICY_NEVER,
CHECKSUM_POLICY_IGNORE)).build(),
RemoteRepository.Builder(
"bintray", "default", "https://jcenter.bintray.com"
).setSnapshotPolicy(RepositoryPolicy(false, UPDATE_POLICY_NEVER,
CHECKSUM_POLICY_IGNORE)).build(),
RemoteRepository.Builder(
"jitpack", "default", "https://jitpack.io").build()
) + repositories.map { repository ->
val colon = repository.indexOf("=").apply {
if (this == -1) { throw RuntimeException("$repository is not a valid repository entry " +
"(make sure it's provided as <id>=<url>") }
}
val id = repository.substring(0, colon)
val url = repository.substring(colon + 1)
RemoteRepository.Builder(id, "default", url).build()
}

val insecureProtocols = setOf(
"http", // Should use https
"ftp" // Should use ftps
)
mavenRepositories.forEach {
if (insecureProtocols.any { protocol -> protocol.equals(it.protocol, ignoreCase = true) }) {
/*
* Read more here:
* https://max.computer/blog/how-to-take-over-the-computer-of-any-java-or-clojure-or-scala-developer/
*/
System.err.println(
"[WARN]: Repository ${it.id} is using an insecure protocol (eg. http, ftp, ect...). " +
"This leaves you vulnerable to a Man In The Middle (MITM) attack. " +
"Attackers can use this to achieve Remote Code Execution (RCE) on your system."
)
}
}

val dependencyResolver = MavenDependencyResolver(
mavenLocal,
listOf(
RemoteRepository.Builder(
"central", "default", "http://repo1.maven.org/maven2/"
).setSnapshotPolicy(RepositoryPolicy(false, UPDATE_POLICY_NEVER,
CHECKSUM_POLICY_IGNORE)).build(),
RemoteRepository.Builder(
"bintray", "default", "http://jcenter.bintray.com"
).setSnapshotPolicy(RepositoryPolicy(false, UPDATE_POLICY_NEVER,
CHECKSUM_POLICY_IGNORE)).build(),
RemoteRepository.Builder(
"jitpack", "default", "http://jitpack.io").build()
) + repositories.map { repository ->
val colon = repository.indexOf("=").apply {
if (this == -1) { throw RuntimeException("$repository is not a valid repository entry " +
"(make sure it's provided as <id>=<url>") }
}
val id = repository.substring(0, colon)
val url = repository.substring(colon + 1)
RemoteRepository.Builder(id, "default", url).build()
},
mavenRepositories,
forceUpdate == true
)
if (debug) {
Expand Down