Skip to content

Commit

Permalink
#1631 Prevent multiple alert imports
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent 7fad72e commit b4973af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
54 changes: 28 additions & 26 deletions thehive/app/org/thp/thehive/services/AlertSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,33 +236,35 @@ class AlertSrv @Inject() (
def createCase(alert: RichAlert, user: Option[User with Entity], organisation: Organisation with Entity)(implicit
graph: Graph,
authContext: AuthContext
): Try[RichCase] = // FIXME check if alert is already imported
for {
caseTemplate <-
alert
.caseTemplate
.map(ct => caseTemplateSrv.get(EntityIdOrName(ct)).richCaseTemplate.getOrFail("CaseTemplate"))
.flip
customField = alert.customFields.map(f => InputCustomFieldValue(f.name, f.value, f.order))
case0 = Case(
number = 0,
title = caseTemplate.flatMap(_.titlePrefix).getOrElse("") + alert.title,
description = alert.description,
severity = alert.severity,
startDate = new Date,
endDate = None,
flag = false,
tlp = alert.tlp,
pap = alert.pap,
status = CaseStatus.Open,
summary = None
)
): Try[RichCase] =
get(alert.alert).`case`.richCase.headOption.getOrElse {
for {
caseTemplate <-
alert
.caseTemplate
.map(ct => caseTemplateSrv.get(EntityIdOrName(ct)).richCaseTemplate.getOrFail("CaseTemplate"))
.flip
customField = alert.customFields.map(f => InputCustomFieldValue(f.name, f.value, f.order))
case0 = Case(
number = 0,
title = caseTemplate.flatMap(_.titlePrefix).getOrElse("") + alert.title,
description = alert.description,
severity = alert.severity,
startDate = new Date,
endDate = None,
flag = false,
tlp = alert.tlp,
pap = alert.pap,
status = CaseStatus.Open,
summary = None
)

createdCase <- caseSrv.create(case0, user, organisation, alert.tags.toSet, customField, caseTemplate, Nil)
_ <- importObservables(alert.alert, createdCase.`case`)
_ <- alertCaseSrv.create(AlertCase(), alert.alert, createdCase.`case`)
_ <- markAsRead(alert._id)
} yield createdCase
createdCase <- caseSrv.create(case0, user, organisation, alert.tags.toSet, customField, caseTemplate, Nil)
_ <- importObservables(alert.alert, createdCase.`case`)
_ <- alertCaseSrv.create(AlertCase(), alert.alert, createdCase.`case`)
_ <- markAsRead(alert._id)
} yield createdCase
}

def mergeInCase(alertId: EntityIdOrName, caseId: EntityIdOrName)(implicit graph: Graph, authContext: AuthContext): Try[Case with Entity] =
for {
Expand Down
2 changes: 2 additions & 0 deletions thehive/conf/play/reference-overrides.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ play.http.session.cookieName = THEHIVE-SESSION

play.server.provider = org.thp.thehive.CustomAkkaHttpServerProvider

play.server.http.idleTimeout = 10 minutes

akka.actor {
serializers {
stream = "org.thp.thehive.services.StreamSerializer"
Expand Down

0 comments on commit b4973af

Please sign in to comment.