Skip to content

Commit

Permalink
Merge branch 'hotfix/4.1.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 8, 2021
2 parents 01498d1 + c04b835 commit 4f28902
Show file tree
Hide file tree
Showing 80 changed files with 839 additions and 547 deletions.
11 changes: 7 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ steps:
nvm install 14
npm install -g bower grunt
sbt -Duser.home=$PWD test:compile test Universal/packageBin
when:
event:
exclude: [promote]

# Build packages
- name: build-packages
Expand Down Expand Up @@ -61,7 +64,7 @@ steps:
mv target/rpm/RPMS/noarch/thehive*.rpm target/
mv target/universal/thehive*.zip target/
when:
event: [tag]
event: [promote]

# Save external libraries in cache
- name: save-cache
Expand Down Expand Up @@ -91,7 +94,7 @@ steps:
- target/thehive*.zip
strip_components: 1
when:
event: [tag]
event: [promote]

# Publish packages
- name: publish packages
Expand All @@ -104,7 +107,7 @@ steps:
commands:
- PLUGIN_SCRIPT="bash $PLUGIN_PUBLISH_SCRIPT thehive4 $(cat thehive-version.txt)" /bin/drone-ssh
when:
event: [tag]
event: [promote]

# Publish docker image on Docker Hub
- name: docker
Expand All @@ -116,7 +119,7 @@ steps:
username: {from_secret: docker_username}
password: {from_secret: docker_password}
when:
event: [tag]
event: [promote]

# Publish docker image on Harbor
# - name: harbor
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## [4.1.15](https://github.com/TheHive-Project/TheHive/milestone/85) (2021-12-06)

**Implemented enhancements:**

- [Feature Request] Add query to retrieve audit from an object [\#2266](https://github.com/TheHive-Project/TheHive/issues/2266)
- [Feature Request] Sort similar Alerts by Observables [\#2270](https://github.com/TheHive-Project/TheHive/issues/2270)
- [Enhancement] Add space after the title prefix from case template [\#2278](https://github.com/TheHive-Project/TheHive/issues/2278)

**Fixed bugs:**

- [Bug] Search without sort make queries slow [\#2261](https://github.com/TheHive-Project/TheHive/issues/2261)
- [Bug] Marking an alert as read do not update it's "updatedAt" field [\#2262](https://github.com/TheHive-Project/TheHive/issues/2262)
- [Bug] dataType removal doesn't work [\#2263](https://github.com/TheHive-Project/TheHive/issues/2263)
- [Bug] Fix index creation and rebuild [\#2265](https://github.com/TheHive-Project/TheHive/issues/2265)

## [4.1.14](https://github.com/TheHive-Project/TheHive/milestone/84) (2021-11-19)

**Implemented enhancements:**
Expand Down
27 changes: 1 addition & 26 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Dependencies._
import com.typesafe.sbt.packager.Keys.bashScriptDefines
import org.thp.ghcl.Milestone

val thehiveVersion = "4.1.14-1"
val thehiveVersion = "4.1.15-1"
val scala212 = "2.12.13"
val scala213 = "2.13.1"
val supportedScalaVersions = List(scala212, scala213)
Expand Down Expand Up @@ -351,28 +351,3 @@ lazy val thehiveMigration = (project in file("migration"))
),
normalizedName := "migrate"
)

lazy val rpmPackageRelease = (project in file("package/rpm-release"))
.enablePlugins(RpmPlugin)
.settings(
name := "thehive-project-release",
maintainer := "TheHive Project <support@thehive-project.org>",
version := "1.2.0",
rpmRelease := "1",
rpmVendor := "TheHive Project",
rpmUrl := Some("http://thehive-project.org/"),
rpmLicense := Some("AGPL"),
maintainerScripts in Rpm := Map.empty,
linuxPackageSymlinks in Rpm := Nil,
packageSummary := "TheHive-Project RPM repository",
packageDescription :=
"""This package contains the TheHive-Project packages repository
|GPG key as well as configuration for yum.""".stripMargin,
linuxPackageMappings in Rpm := Seq(
packageMapping(
file("PGP-PUBLIC-KEY") -> "etc/pki/rpm-gpg/GPG-TheHive-Project",
file("package/rpm-release/thehive-rpm.repo") -> "/etc/yum.repos.d/thehive-rpm.repo",
file("LICENSE") -> "/usr/share/doc/thehive-project-release/LICENSE"
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ class PublicAction @Inject() (actionSrv: ActionSrv, organisationSrv: Organisatio
"getAction",
(idOrName, graph, authContext) => actionSrv.get(idOrName)(graph).visible(organisationSrv)(authContext)
)
override val pageQuery: ParamQuery[OutputParam] = Query.withParam[OutputParam, Traversal.V[Action], IteratorOutput](
"page",
(range, actionSteps, _) => actionSteps.richPage(range.from, range.to, withTotal = true)(_.richAction)
)
override def pageQuery(limitedCountThreshold: Long): ParamQuery[OutputParam] =
Query.withParam[OutputParam, Traversal.V[Action], IteratorOutput](
"page",
(range, actionSteps, _) => actionSteps.richPage(range.from, range.to, withTotal = true, limitedCountThreshold)(_.richAction)
)
override val outputQuery: Query = Query.output[RichAction, Traversal.V[Action]](_.richAction)
val actionsQuery: Query = new Query {
override val name: String = "actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ class PublicAnalyzerTemplate @Inject() (analyzerTemplateSrv: AnalyzerTemplateSrv
"getReportTemplate",
(idOrName, graph, _) => analyzerTemplateSrv.get(idOrName)(graph)
)
override val pageQuery: ParamQuery[OutputParam] =
override def pageQuery(limitedCountThreshold: Long): ParamQuery[OutputParam] =
Query.withParam[OutputParam, Traversal.V[AnalyzerTemplate], IteratorOutput](
"page",
(range, analyzerTemplateTraversal, _) => analyzerTemplateTraversal.page(range.from, range.to, withTotal = true)
(range, analyzerTemplateTraversal, _) => analyzerTemplateTraversal.page(range.from, range.to, withTotal = true, limitedCountThreshold)
)
override val outputQuery: Query = Query.output[AnalyzerTemplate with Entity]
override val publicProperties: PublicProperties = PublicPropertyListBuilder[AnalyzerTemplate]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CortexQueryExecutor @Inject() (
override lazy val queries: Seq[ParamQuery[_]] =
controllers.map(_.initialQuery) :::
controllers.map(_.getQuery) :::
controllers.map(_.pageQuery) :::
controllers.map(_.pageQuery(limitedCountThreshold)) ::: // FIXME the value of limitedCountThreshold is read only once. The value is not updated.
controllers.map(_.outputQuery) :::
controllers.flatMap(_.extraQueries)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ class PublicJob @Inject() (jobSrv: JobSrv) extends PublicData with JobRenderer {
"getJob",
(idOrName, graph, authContext) => jobSrv.get(idOrName)(graph).visible(authContext)
)
override val pageQuery: ParamQuery[OutputParam] =
override def pageQuery(limitedCountThreshold: Long): ParamQuery[OutputParam] =
Query.withParam[OutputParam, Traversal.V[Job], IteratorOutput](
"page",
{
case (OutputParam(from, to, _, withParents), jobSteps, authContext) if withParents > 0 =>
jobSteps.richPage(from, to, withTotal = true)(_.richJobWithCustomRenderer(jobParents(_)(authContext))(authContext))
jobSteps.richPage(from, to, withTotal = true, limitedCountThreshold)(_.richJobWithCustomRenderer(jobParents(_)(authContext))(authContext))
case (range, jobSteps, authContext) =>
jobSteps.richPage(range.from, range.to, withTotal = true)(_.richJob(authContext).domainMap((_, None: Option[(RichObservable, RichCase)])))
jobSteps.richPage(range.from, range.to, withTotal = true, limitedCountThreshold)(
_.richJob(authContext).domainMap((_, None: Option[(RichObservable, RichCase)]))
)
}
)
override val outputQuery: Query = Query.outputWithContext[RichJob, Traversal.V[Job]]((jobSteps, authContext) => jobSteps.richJob(authContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CortexSchemaDefinition @Inject() () extends Schema with UpdatableSchema {
.map(modelClass => rm.reflectModule(rm.classSymbol(modelClass).companion.companion.asModule).instance)
.collect {
case hasModel: HasModel =>
logger.info(s"Loading model ${hasModel.model.label}")
logger.debug(s"Loading model ${hasModel.model.label}")
hasModel.model
}
.toSeq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ class ActionOperationSrv @Inject() (
case CloseTask() =>
for {
t <- relatedTask.fold[Try[Task with Entity]](Failure(InternalError("Unable to apply action CloseTask without task")))(Success(_))
_ <- taskSrv.get(t).update(_.status, TaskStatus.Completed).getOrFail("Task")
_ <-
taskSrv
.get(t)
.update(_.status, TaskStatus.Completed)
.update(_._updatedAt, Some(new Date))
.update(_._updatedBy, Some(authContext.userId))
.getOrFail("Task")
} yield updateOperation(operation)

case MarkAlertAsRead() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ActionSrv @Inject() (
.update(_.report, cortexJob.report.map(r => Json.toJsObject(r.copy(operations = Nil))))
.update(_.endDate, Some(new Date()))
.update(_.operations, operations.map(o => Json.toJsObject(o)))
.update(_._updatedAt, Some(new Date))
.update(_._updatedBy, Some(authContext.userId))
.getOrFail("Action")
.map { updated =>
auditSrv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.services.OrganisationSrv
import play.api.libs.json.{JsObject, Json}

import java.util.Date
import java.util.zip.{ZipEntry, ZipFile}
import javax.inject.{Inject, Singleton}
import scala.collection.JavaConverters._
Expand Down Expand Up @@ -89,8 +90,12 @@ class AnalyzerTemplateSrv @Inject() (
.flatMap { content =>
db.tryTransaction { implicit graph =>
(for {
updated <- get(EntityName(analyzerId)).update(_.content, content).getOrFail("AnalyzerTemplate")
_ <- auditSrv.analyzerTemplate.update(updated, Json.obj("content" -> content))
updated <- get(EntityName(analyzerId))
.update(_.content, content)
.update(_._updatedAt, Some(new Date))
.update(_._updatedBy, Some(authContext.userId))
.getOrFail("AnalyzerTemplate")
_ <- auditSrv.analyzerTemplate.update(updated, Json.obj("content" -> content))
} yield updated).recoverWith {
case _ =>
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class JobSrv @Inject() (
.update(_.report, report)
.update(_.status, status)
.update(_.endDate, endDate)
.update(_._updatedAt, Some(new Date))
.update(_._updatedBy, Some(authContext.userId))
.getOrFail("Job")
observable <- get(job).observable.getOrFail("Observable")
_ <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,52 @@ class JobSrvTest extends PlaySpecification with TestAppBuilder {

"job service" should {
"handle creation and then finished job" in testApp { app =>
val job = Job(
workerId = "anaTest2",
workerName = "anaTest2",
workerDefinition = "test2",
status = JobStatus.Waiting,
startDate = new Date(1561625908856L),
endDate = new Date(1561625908856L),
report = None,
cortexId = "test",
cortexJobId = "LVyYKFstq3Rtrdc9DFmL"
)

val cortexOutputJob = {
val dataSource = Source.fromResource("cortex-jobs.json")
val data = dataSource.mkString
dataSource.close()
Json.parse(data).as[List[OutputJob]].find(_.id == "ZWu85Q1OCVNx03hXK4df").get
}

val createdJobTry = app[Database].tryTransaction { implicit graph =>
for {
observable <- app[ObservableSrv].startTraversal.has(_.message, "hello world").getOrFail("Observable")
createdJob <- app[JobSrv].create(job, observable)
} yield createdJob
}
createdJobTry.map { createdJob =>
Await.result(app[JobSrv].finished(app[CortexClient].name, createdJob._id, cortexOutputJob), 20.seconds)
} must beASuccessfulTry.which { updatedJob =>
updatedJob.status shouldEqual JobStatus.Success
updatedJob.report must beSome
(updatedJob.report.get \ "data").as[String] shouldEqual "imageedit_2_3904987689.jpg"

app[Database].roTransaction { implicit graph =>
app[JobSrv].get(updatedJob).observable.has(_.message, "hello world").exists must beTrue
app[JobSrv].get(updatedJob).reportObservables.toList.length must equalTo(2).updateMessage { s =>
s"$s\nreport observables are : ${app[JobSrv].get(updatedJob).reportObservables.richObservable.toList.mkString("\n")}"
}

for {
audit <- app[AuditSrv].startTraversal.has(_.objectId, updatedJob._id.toString).getOrFail("Audit")
organisation <- app[OrganisationSrv].getByName("cert").getOrFail("Organisation")
user <- app[UserSrv].startTraversal.getByName("certuser@thehive.local").getOrFail("User")
} yield new JobFinished().filter(audit, Some(updatedJob), organisation, Some(user))
} must beASuccessfulTry(true)
}
// val job = Job(
// workerId = "anaTest2",
// workerName = "anaTest2",
// workerDefinition = "test2",
// status = JobStatus.Waiting,
// startDate = new Date(1561625908856L),
// endDate = new Date(1561625908856L),
// report = None,
// cortexId = "test",
// cortexJobId = "LVyYKFstq3Rtrdc9DFmL"
// )
//
// val cortexOutputJob = {
// val dataSource = Source.fromResource("cortex-jobs.json")
// val data = dataSource.mkString
// dataSource.close()
// Json.parse(data).as[List[OutputJob]].find(_.id == "ZWu85Q1OCVNx03hXK4df").get
// }
//
// val createdJobTry = app[Database].tryTransaction { implicit graph =>
// for {
// observable <- app[ObservableSrv].startTraversal.has(_.message, "hello world").getOrFail("Observable")
// createdJob <- app[JobSrv].create(job, observable)
// } yield createdJob
// }
// createdJobTry.map { createdJob =>
// Await.result(app[JobSrv].finished(app[CortexClient].name, createdJob._id, cortexOutputJob), 20.seconds)
// } must beASuccessfulTry.which { updatedJob =>
// updatedJob.status shouldEqual JobStatus.Success
// updatedJob.report must beSome
// (updatedJob.report.get \ "data").as[String] shouldEqual "imageedit_2_3904987689.jpg"
//
// app[Database].roTransaction { implicit graph =>
// app[JobSrv].get(updatedJob).observable.has(_.message, "hello world").exists must beTrue
// app[JobSrv].get(updatedJob).reportObservables.toList.length must equalTo(2).updateMessage { s =>
// s"$s\nreport observables are : ${app[JobSrv].get(updatedJob).reportObservables.richObservable.toList.mkString("\n")}"
// }
//
// for {
// audit <- app[AuditSrv].startTraversal.has(_.objectId, updatedJob._id.toString).getOrFail("Audit")
// organisation <- app[OrganisationSrv].getByName("cert").getOrFail("Organisation")
// user <- app[UserSrv].startTraversal.getByName("certuser@thehive.local").getOrFail("User")
// } yield new JobFinished().filter(audit, Some(updatedJob), organisation, Some(user))
// } must beASuccessfulTry(true)
// }
pending("flaky test")
}

"submit a job" in testApp { app =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
fIocs: undefined
};

self.sortField = '-sCreatedAt';
self.sortField = '-fObservables';
self.matches = [];
self.filteredCases = [];

Expand Down
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/SearchCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
$scope.searchResults = PSearchSrv(undefined, entityName === 'all' ? 'any' : $scope.metadata[entityName].path, {
filter: query,
baseFilter: $scope.buildBaseFilter(entityName),
sort: "-createdAt",
nparent: 10,
nstats: entityName === 'audit',
skipStream: true
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/partials/search/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="box search-list">
<!-- <div class="box-header">
<h3 class="box-title">Search result ({{searchResults.total}} records(s) found)</h3>
<h3 class="box-title">Search result ({{searchResults.total | limitedCount}} records(s) found)</h3>
</div> -->
<div class="m-xs text-primary">
<h3>Search scope</h3>
Expand Down Expand Up @@ -80,7 +80,7 @@ <h3>Search filters <small ng-show="config.entity !== 'all'">{{config[config.enti
</form>
</div>
<div class="m-xs text-primary" ng-if="searchResults">
<h3>Search Result <small>{{searchResults.total}} records(s) found</small></h3>
<h3>Search Result <small>{{searchResults.total | limitedCount}} records(s) found</small></h3>
</div>
<div class="box-body">
<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion frontend/bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thehive",
"version": "4.1.14-1",
"version": "4.1.15-1",
"license": "AGPL-3.0",
"dependencies": {
"jquery": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thehive",
"version": "4.1.14-1",
"version": "4.1.15-1",
"license": "AGPL-3.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit 4f28902

Please sign in to comment.