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

Fix #2050: add max-attributes to misp filters #2053

Merged
merged 1 commit into from
Jun 3, 2021
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
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