Skip to content

Commit

Permalink
Merge pull request #2053 from vdebergue/fix/2050
Browse files Browse the repository at this point in the history
Fix #2050: add max-attributes to misp filters
  • Loading branch information
To-om authored Jun 3, 2021
2 parents a4c64d7 + 39b5374 commit 6a7a20d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MispClient(
val baseUrl: String,
auth: Authentication,
ws: WSClient,
maxAttributes: Option[Int],
maxAge: Option[Duration],
excludedOrganisations: Seq[String],
whitelistOrganisations: Seq[String],
Expand Down Expand Up @@ -55,6 +56,7 @@ class MispClient(
| url: $baseUrl
| proxy: ${configuredProxy.getOrElse("<not set>")}
| filters:
| max attributes: ${maxAttributes.getOrElse("<not set>")}
| max age: ${maxAge.fold("<not set>")(_.toCoarsest.toString)}
| excluded orgs: ${excludedOrganisations.mkString}
| excluded tags: ${excludedTags.mkString}
Expand Down Expand Up @@ -183,6 +185,7 @@ class MispClient(
val maybeEvent = Try(Json.parse(data.toArray[Byte]).as[Event])
maybeEvent.fold(error => { logger.warn(s"Event has invalid format: ${data.decodeString("UTF-8")}", error); Nil }, List(_))
}
.filter(event => maxAttributes.fold(true)(max => event.attributes.length < max))
.mapMaterializedValue(_ => NotUsed)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ case class TheHiveMispClientConfig(
url: String,
auth: Authentication,
wsConfig: ProxyWSConfig = ProxyWSConfig(AhcWSClientConfig(), None),
maxAttributes: Option[Int],
maxAge: Option[Duration],
excludedOrganisations: Seq[String] = Nil,
whitelistOrganisations: Seq[String] = Nil,
Expand All @@ -37,12 +38,14 @@ case class TheHiveMispClientConfig(

object TheHiveMispClientConfig {
implicit val purposeFormat: Format[MispPurpose.Value] = Json.formatEnum(MispPurpose)

val reads: Reads[TheHiveMispClientConfig] = {
for {
name <- (JsPath \ "name").read[String]
url <- (JsPath \ "url").read[String]
auth <- (JsPath \ "auth").read[Authentication]
wsConfig <- (JsPath \ "wsConfig").readWithDefault[ProxyWSConfig](ProxyWSConfig(AhcWSClientConfig(), None))
maxAttributes <- (JsPath \ "max-attributes").readNullable[Int]
maxAge <- (JsPath \ "maxAge").readNullable[Duration]
excludedOrganisations <- (JsPath \ "exclusion" \ "organisations").readWithDefault[Seq[String]](Nil)
whitelistOrganisations <- (JsPath \ "whitelist" \ "organisations").readWithDefault[Seq[String]](Nil)
Expand All @@ -60,6 +63,7 @@ object TheHiveMispClientConfig {
url,
auth,
wsConfig,
maxAttributes,
maxAge,
excludedOrganisations,
whitelistOrganisations,
Expand All @@ -80,6 +84,7 @@ object TheHiveMispClientConfig {
"url" -> cfg.url,
"auth" -> cfg.auth,
"wsConfig" -> cfg.wsConfig,
"maxAttributes" -> cfg.maxAttributes,
"maxAge" -> cfg.maxAge,
"exclusion" -> Json.obj("organisations" -> cfg.excludedOrganisations, "tags" -> cfg.excludedTags),
"whitelistTags" -> Json.obj("whitelist" -> cfg.whitelistTags),
Expand All @@ -99,6 +104,7 @@ class TheHiveMispClient(
baseUrl: String,
auth: Authentication,
ws: WSClient,
maxAttributes: Option[Int],
maxAge: Option[Duration],
excludedOrganisations: Seq[String],
whitelistOrganisations: Seq[String],
Expand All @@ -116,6 +122,7 @@ class TheHiveMispClient(
baseUrl,
auth,
ws,
maxAttributes,
maxAge,
excludedOrganisations,
whitelistOrganisations,
Expand All @@ -129,6 +136,7 @@ class TheHiveMispClient(
config.url,
config.auth,
new ProxyWS(config.wsConfig, mat),
config.maxAttributes,
config.maxAge,
config.excludedOrganisations,
config.whitelistOrganisations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TestMispClientProvider @Inject() (Action: DefaultActionBuilder, implicit v
baseUrl = baseUrl,
auth = NoAuthentication,
ws = ws,
maxAttributes = None,
maxAge = None,
excludedOrganisations = Nil,
whitelistOrganisations = Nil,
Expand Down

0 comments on commit 6a7a20d

Please sign in to comment.