Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
s/whitelist/allowlist
  • Loading branch information
code-asher committed Aug 18, 2023
commit 64cf76d3ade9f5faa2e7abc10e625e4bac9a47ea
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
}

// Check that both the domain and the redirected domain are
// whitelisted. If not, check with the user whether to proceed.
// allowlisted. If not, check with the user whether to proceed.
verifyDownloadLink(parameters, deploymentURL.toURL())

// TODO: Ask for the project path if missing and validate the path.
Expand Down Expand Up @@ -159,7 +159,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
}

/**
* Check that the link is whitelisted. If not, confirm with the user.
* Check that the link is allowlisted. If not, confirm with the user.
*/
private fun verifyDownloadLink(parameters: Map<String, String>, deploymentURL: URL) {
val link = parameters[IDE_DOWNLOAD_LINK]
Expand All @@ -173,25 +173,25 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
throw IllegalArgumentException("$link is not a valid URL")
}

val (whitelisted, https, linkWithRedirect) = try {
CoderRemoteConnectionHandle.isWhitelisted(url, deploymentURL)
val (allowlisted, https, linkWithRedirect) = try {
CoderRemoteConnectionHandle.isAllowlisted(url, deploymentURL)
} catch (e: Exception) {
throw IllegalArgumentException("Unable to verify $url: $e")
}
if (whitelisted && https) {
if (allowlisted && https) {
return
}

val comment = if (whitelisted) "The download link is from a non-whitelisted URL"
val comment = if (allowlisted) "The download link is from a non-allowlisted URL"
else if (https) "The download link is not using HTTPS"
else "The download link is from a non-whitelisted URL and is not using HTTPS"
else "The download link is from a non-allowlisted URL and is not using HTTPS"

if (!CoderRemoteConnectionHandle.confirm(
"Confirm download URL",
"$comment. Would you like to proceed?",
linkWithRedirect,
)) {
throw IllegalArgumentException("$linkWithRedirect is not whitelisted")
throw IllegalArgumentException("$linkWithRedirect is not allowlisted")
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ class CoderRemoteConnectionHandle {
}

/**
* Return if the URL is whitelisted, https, and the URL and its final
* Return if the URL is allowlisted, https, and the URL and its final
* destination, if it is a different host.
*/
@JvmStatic
fun isWhitelisted(url: URL, deploymentURL: URL): Triple<Boolean, Boolean, String> {
// TODO: Setting for the whitelist, and remember previously allowed
fun isAllowlisted(url: URL, deploymentURL: URL): Triple<Boolean, Boolean, String> {
// TODO: Setting for the allowlist, and remember previously allowed
// domains.
val domainWhitelist = listOf("intellij.net", "jetbrains.com", deploymentURL.host)
val domainAllowlist = listOf("intellij.net", "jetbrains.com", deploymentURL.host)

// Resolve any redirects.
val finalUrl = try {
Expand All @@ -269,10 +269,10 @@ class CoderRemoteConnectionHandle {
linkWithRedirect = "$linkWithRedirect (redirects to to $finalUrl)"
}

val whitelisted = domainWhitelist.any { url.host == it || url.host.endsWith(".$it") }
&& domainWhitelist.any { finalUrl.host == it || finalUrl.host.endsWith(".$it") }
val allowlisted = domainAllowlist.any { url.host == it || url.host.endsWith(".$it") }
&& domainAllowlist.any { finalUrl.host == it || finalUrl.host.endsWith(".$it") }
val https = url.protocol == "https" && finalUrl.protocol == "https"
return Triple(whitelisted, https, linkWithRedirect)
return Triple(allowlisted, https, linkWithRedirect)
}

/**
Expand Down