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

[NU-1801] Fix no validation when indexing on Lists and Maps #6826

Merged
merged 4 commits into from
Sep 10, 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
3 changes: 3 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
* toBigIntegerOrNull
* toBigDecimal
* toBigDecimalOrNull
* [#6826](https://github.com/TouK/nussknacker/pull/6826) Security fix: added validation of expression used inside
indexer for Maps and Lists (for example `{1,2,3}[#otherList.remove(1) == null ? 0 : 0]`). This allowed executing
some types of unallowed expressions.

## 1.17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ private[spel] class Typer(
case TypedClass(clazz, param :: Nil)
if clazz.isAssignableFrom(classOf[java.util.List[_]]) || clazz.isAssignableFrom(classOf[Array[Object]]) =>
// TODO: validate indexer key - the only valid key is an integer - but its more complicated with references
validNodeResult(param)
withTypedChildren(_ => valid(param))
case TypedClass(clazz, keyParam :: valueParam :: Nil) if clazz.isAssignableFrom(classOf[java.util.Map[_, _]]) =>
validNodeResult(valueParam)
withTypedChildren(_ => valid(valueParam))
case d: TypedDict => dictTyper.typeDictValue(d, e).map(toNodeResult)
case union: TypedUnion => typeUnion(e, union)
case TypedTaggedValue(underlying, _) => typeIndexer(e, underlying)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.IllegalOperation
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.MissingObjectError.{
NoPropertyError,
UnknownClassError,
UnknownMethodError
UnknownMethodError,
UnresolvedReferenceError
}
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.OperatorError._
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.UnsupportedOperationError.ArrayConstructorError
Expand Down Expand Up @@ -1281,6 +1282,14 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD
)
}

test("indexing on maps and lists should validate nodes inside indexer") {
List("#processHelper.stringOnStringMap[#invalidRef]", "{1,2,3}[#invalidRef]").map(expr =>
parse[Any](expr, ctxWithGlobal).invalidValue shouldBe NonEmptyList.one(
UnresolvedReferenceError("invalidRef")
)
)
}

test("should return correct type in array projection") {
parse[Any]("#array.![#this]", ctx).validExpression
.evaluateSync[Any](ctx) shouldBe Array("a", "b")
Expand Down
Loading