-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1045 from aml-org/r/v6.2.3
R/v6.2.3
- Loading branch information
Showing
47 changed files
with
260 additions
and
73 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...tions/shared/src/test/scala/org/mulesoft/als/actions/definition/DefinitionFileTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
als-actions/shared/src/test/scala/org/mulesoft/als/actions/links/FindLinksTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...hared/src/test/scala/org/mulesoft/als/actions/rangeFormatting/FormattingOptionsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
als-common/shared/src/main/scala/org/mulesoft/als/common/DirectoryResolver.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ommon/shared/src/main/scala/org/mulesoft/amfintegration/platform/AlsPlatformSecrets.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.mulesoft.amfintegration.platform | ||
|
||
import amf.core.client.common.remote.Content | ||
import amf.core.client.scala.resource.ResourceLoader | ||
import amf.core.internal.remote.Platform | ||
import amf.core.internal.unsafe.PlatformBuilder | ||
import org.mulesoft.als.logger.Logger | ||
import org.mulesoft.common.io.FileSystem | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
trait AlsPlatformSecrets { | ||
private val internalPlatform: Platform = PlatformBuilder() | ||
|
||
val platform: Platform = new Platform { | ||
private def overrideLoaders(implicit executionContext: ExecutionContext): Seq[ResourceLoader] = | ||
internalPlatform.loaders().map(SecuredLoader) | ||
|
||
override def name: String = internalPlatform.name | ||
|
||
override def findCharInCharSequence(s: CharSequence)(p: Char => Boolean): Option[Char] = | ||
internalPlatform.findCharInCharSequence(s)(p) | ||
|
||
override val fs: FileSystem = internalPlatform.fs | ||
|
||
override def loaders()(implicit executionContext: ExecutionContext): Seq[ResourceLoader] = overrideLoaders | ||
|
||
override def encodeURI(url: String): String = internalPlatform.encodeURI(url) | ||
|
||
override def decodeURI(url: String): String = internalPlatform.decodeURI(url) | ||
|
||
override def encodeURIComponent(url: String): String = internalPlatform.encodeURIComponent(url) | ||
|
||
override def decodeURIComponent(url: String): String = internalPlatform.decodeURIComponent(url) | ||
|
||
override def tmpdir(): String = internalPlatform.tmpdir | ||
|
||
override def operativeSystem(): String = internalPlatform.operativeSystem | ||
|
||
// no idea where this is used, but it is overriden in JvmPlatform and I am afraid to change it | ||
override protected def customValidationLibraryHelperLocation: String = | ||
if (name == "jvm") "classpath:validations/amf_validation.js" else super.customValidationLibraryHelperLocation | ||
} | ||
|
||
private case class SecuredLoader(loader: ResourceLoader) extends ResourceLoader { | ||
override def fetch(resource: String): Future[Content] = | ||
loader.fetch(resource) | ||
|
||
override def accepts(resource: String): Boolean = | ||
!potentialLeak(resource) && loader.accepts(resource) | ||
|
||
private def potentialLeak(resource: String): Boolean = | ||
WindowsLeakRegex(resource.toLowerCase) | ||
} | ||
} | ||
|
||
protected object WindowsLeakRegex { | ||
private def checkForLiteral(literal: String, prefix: String)(implicit resource: String): Boolean = { | ||
val regex = s"$prefix/*$literal".r | ||
regex.findPrefixMatchOf(resource).nonEmpty | ||
} | ||
|
||
private def doubleCheckLiteral(literal: String)(implicit resource: String): Boolean = | ||
checkForLiteral(literal, "") || checkForLiteral(literal, filePrefix) | ||
def apply(implicit resource: String): Boolean = | ||
doubleCheckLiteral(windowsSMB) || doubleCheckLiteral(windowsSMBEncoded) || checkForLiteral( | ||
unixStyle, | ||
"" | ||
) || checkForLiteral(unixStyle, s"$filePrefix//") | ||
} |
8 changes: 8 additions & 0 deletions
8
als-common/shared/src/main/scala/org/mulesoft/amfintegration/platform/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.mulesoft.amfintegration | ||
|
||
package object platform { | ||
val filePrefix = "file:" | ||
val windowsSMB = "\\\\" // just in case because AMF sometimes tries to re-fetch a URI decoding it | ||
val windowsSMBEncoded = "%5c%5c" | ||
val unixStyle = "//" | ||
} |
4 changes: 2 additions & 2 deletions
4
als-common/shared/src/test/scala/org/mulesoft/als/common/diff/FileAssertionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
als-common/shared/src/test/scala/org/mulesoft/als/common/dtoTypes/FileUtilsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ommon/shared/src/test/scala/org/mulesoft/amfintegration/platform/WindowsSMBLeakTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.mulesoft.amfintegration.platform | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class WindowsSMBLeakTest extends AnyFunSuite { | ||
|
||
val matches: Set[String] = Set( | ||
"file:%5c%5ctest", | ||
"file:/%5c%5ctest", | ||
"file://%5c%5ctest", | ||
"file:///%5c%5ctest", | ||
"file:////%5c%5ctest", | ||
"file:\\\\test", | ||
"file:/\\\\test", | ||
"file://\\\\test", | ||
"file:///\\\\test", | ||
"\\\\test", | ||
"%5c%5ctest", | ||
"//test", | ||
"file:////test" | ||
) | ||
|
||
test("should not match URI without SMB leak") { | ||
assert(!WindowsLeakRegex("file:///test/correct")) | ||
assert(!WindowsLeakRegex("file://test/correct")) | ||
assert(!WindowsLeakRegex("file:/test/correct")) | ||
assert(!WindowsLeakRegex("file:test/correct")) | ||
assert(!WindowsLeakRegex("/test/correct")) | ||
} | ||
|
||
matches.foreach { resource => | ||
test(s"should match $resource") { | ||
assert(WindowsLeakRegex.apply(resource)) | ||
} | ||
} | ||
} |
Oops, something went wrong.