From 273518c3bf9df84bf69fb59c07c54722128cc753 Mon Sep 17 00:00:00 2001 From: Stephanie Lamb Date: Mon, 7 Oct 2024 15:58:22 -0500 Subject: [PATCH 1/5] initial refactor --- cmd/api/src/api/filters.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cmd/api/src/api/filters.go diff --git a/cmd/api/src/api/filters.go b/cmd/api/src/api/filters.go new file mode 100644 index 000000000..f08f74074 --- /dev/null +++ b/cmd/api/src/api/filters.go @@ -0,0 +1,31 @@ +package api + +import ( + "fmt" + + "github.com/specterops/bloodhound/src/model" +) + +type Filterable interface { + ValidFilters() map[string][]model.FilterOperator +} + +func GetFilterableColumns(f Filterable) []string { + var columns = make([]string, 0) + for column := range f.ValidFilters() { + columns = append(columns, column) + } + return columns +} + +func GetValidFilterPredicatesAsStrings(f Filterable, column string) ([]string, error) { + if predicates, validColumn := f.ValidFilters()[column]; !validColumn { + return []string{}, fmt.Errorf("the specified column cannot be filtered") + } else { + var stringPredicates = make([]string, 0) + for _, predicate := range predicates { + stringPredicates = append(stringPredicates, string(predicate)) + } + return stringPredicates, nil + } +} From ca502f38dd19ca4ddbef2d27b88c6ce4904dc4c4 Mon Sep 17 00:00:00 2001 From: Stephanie Lamb Date: Tue, 8 Oct 2024 09:32:38 -0500 Subject: [PATCH 2/5] added filters file --- cmd/api/src/api/filters.go | 16 ++++++++++++++++ cmd/api/src/model/appcfg/parameter.go | 1 + 2 files changed, 17 insertions(+) diff --git a/cmd/api/src/api/filters.go b/cmd/api/src/api/filters.go index f08f74074..3853ce133 100644 --- a/cmd/api/src/api/filters.go +++ b/cmd/api/src/api/filters.go @@ -1,3 +1,19 @@ +// Copyright 2024 Specter Ops, Inc. +// +// Licensed under the Apache License, Version 2.0 +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + package api import ( diff --git a/cmd/api/src/model/appcfg/parameter.go b/cmd/api/src/model/appcfg/parameter.go index 7595e2c62..1754ef448 100644 --- a/cmd/api/src/model/appcfg/parameter.go +++ b/cmd/api/src/model/appcfg/parameter.go @@ -162,6 +162,7 @@ func (s *PasswordExpiration) UnmarshalJSON(data []byte) error { return nil } + } func GetPasswordExpiration(ctx context.Context, service ParameterService) time.Duration { From 537f62c2ece325828705a0b6d0e48765328bc5d5 Mon Sep 17 00:00:00 2001 From: Stephanie Lamb Date: Wed, 16 Oct 2024 15:04:08 -0500 Subject: [PATCH 3/5] openapi changes --- packages/go/openapi/doc/openapi.json | 248 +++++++++++++++++- .../attack-paths.domains.id.details.yaml | 185 ++++++++++++- .../src/schemas/model.list-finding.yaml | 20 ++ .../schemas/model.relationship-finding.yaml | 20 ++ 4 files changed, 457 insertions(+), 16 deletions(-) diff --git a/packages/go/openapi/doc/openapi.json b/packages/go/openapi/doc/openapi.json index c06b84f53..3eabaf1b5 100644 --- a/packages/go/openapi/doc/openapi.json +++ b/packages/go/openapi/doc/openapi.json @@ -12166,7 +12166,7 @@ "get": { "operationId": "ListDomainAttackPathsDetails", "summary": "List domain attack paths details", - "description": "Lists detailed data about attack paths for a domain.", + "description": "Lists detailed data about attack paths for a domain. \n\n__Note:__ __Note:__ `ImpactCount`, `ImpactPercentage`, `ExposureCount`, and `ExposurePercentage` will have a value other than zero when butterfly analysis is enabled.\n", "tags": [ "Attack Paths", "Enterprise" @@ -12174,7 +12174,6 @@ "parameters": [ { "name": "finding", - "x-go-name": "FindingDeprecated", "in": "query", "schema": { "$ref": "#/components/schemas/api.params.predicate.filter.string" @@ -12182,7 +12181,7 @@ }, { "name": "sort_by", - "description": "Sortable columns are `domain_sid`, `index`, `AcceptedUntil`, `id`, `created_at`, `updated_at`, `deleted_at`. Relationship risks can be sorted on `FromPrincipal` and `ToPrincipal` in addition to the sortable columns for List Risks.", + "description": "Sortable columns are `domain_sid`, `index`, `AcceptedUntil`, `id`, `created_at`, `updated_at`, `deleted_at`, `exposure_percent`, `impact_percent`. Relationship risks can be sorted on `FromPrincipal` and `ToPrincipal` in addition to the sortable columns for List Risks.", "in": "query", "schema": { "$ref": "#/components/schemas/api.params.query.sort-by" @@ -12191,7 +12190,6 @@ { "name": "FromPrincipal", "deprecated": true, - "x-go-name": "FromPrincipalDeprecated", "in": "query", "schema": { "$ref": "#/components/schemas/api.params.predicate.filter.string" @@ -12200,7 +12198,6 @@ { "name": "ToPrincipal", "deprecated": true, - "x-go-name": "ToPrincipalDeprecated", "in": "query", "schema": { "$ref": "#/components/schemas/api.params.predicate.filter.string" @@ -12237,7 +12234,6 @@ { "name": "AcceptedUntil", "deprecated": true, - "x-go-name": "AcceptedUntilDeprecated", "in": "query", "schema": { "$ref": "#/components/schemas/api.params.predicate.filter.time" @@ -12259,6 +12255,7 @@ }, { "name": "Finding", + "deprecated": true, "in": "query", "schema": { "$ref": "#/components/schemas/api.params.predicate.filter.string" @@ -12362,6 +12359,186 @@ ] } ] + }, + "examples": { + "Butterfly Relationship Finding": { + "summary": "Butterfly Relationship Finding", + "description": "When the butterfly analysis feature flag is on, impact count/percentage and exposure count/percentage will have a value other than zero.", + "value": { + "count": 0, + "skip": 0, + "limit": 0, + "data": [ + { + "id": 0, + "created_at": "2024-08-28T21:21:40.845Z", + "updated_at": "2024-08-28T21:21:40.845Z", + "deleted_at": { + "time": "2024-08-28T21:21:40.845Z", + "valid": true + }, + "FromPrincipal": "string", + "ToPrincipal": "string", + "FromPrincipalProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "FromPrincipalKind": "string", + "ToPrincipalProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "ToPrincipalKind": "string", + "RelProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "ComboGraphRelationID": { + "int64": 0, + "valid": true + }, + "Finding": "string", + "DomainSID": "string", + "PrincipalHash": "string", + "AcceptedUntil": "2024-08-28T21:21:40.845Z", + "ImpactPercentage": 12, + "ImpactCount": 2, + "ExposurePercentage": 24, + "ExposureCount": 4, + "Severity": "high", + "Accepted": true + } + ] + } + }, + "Metatree Relationship Finding": { + "summary": "Metatree Relationship Finding", + "description": "When the butterfly analysis feature flag is off and metatree is running, impact count/percentage and exposure count/percentage will have a value of zero.", + "value": { + "count": 0, + "skip": 0, + "limit": 0, + "data": [ + { + "id": 0, + "created_at": "2024-08-28T21:21:40.845Z", + "updated_at": "2024-08-28T21:21:40.845Z", + "deleted_at": { + "time": "2024-08-28T21:21:40.845Z", + "valid": true + }, + "FromPrincipal": "string", + "ToPrincipal": "string", + "FromPrincipalProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "FromPrincipalKind": "string", + "ToPrincipalProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "ToPrincipalKind": "string", + "RelProps": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "ComboGraphRelationID": { + "int64": 0, + "valid": true + }, + "Finding": "string", + "DomainSID": "string", + "PrincipalHash": "string", + "AcceptedUntil": "2024-08-28T21:21:40.845Z", + "ImpactPercentage": 0, + "ImpactCount": 0, + "ExposurePercentage": 0, + "ExposureCount": 0, + "Severity": "", + "Accepted": true + } + ] + } + }, + "Butterfly List Finding": { + "summary": "Butterfly List Finding", + "description": "When the butterfly analysis feature flag is on, impact count/percentage and exposure count/percentage will have a value other than zero.", + "value": { + "count": "0,", + "skip": "0,", + "limit": "0,", + "data": [ + { + "id": 0, + "created_at": "2024-08-28T21:42:18.844Z", + "updated_at": "2024-08-28T21:42:18.844Z", + "deleted_at": { + "time": "2024-08-28T21:42:18.844Z", + "valid": true + }, + "Principal": "string", + "PrincipalKind": "string", + "Finding": "string", + "DomainSID": "string", + "Props": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "accepted_until": "2024-08-28T21:42:18.844Z", + "ImpactPercentage": 12, + "ImpactCount": 2, + "ExposurePercentage": 24, + "ExposureCount": 4, + "Severity": "high", + "Accepted": true + } + ] + } + }, + "Metatree List Finding": { + "summary": "Metatree List Finding", + "description": "When the butterfly analysis feature flag is off and metatree is running, impact count/percentage and exposure count/percentage will have a value of zero.", + "value": { + "count": "0,", + "skip": "0,", + "limit": "0,", + "data": [ + { + "id": 0, + "created_at": "2024-08-28T21:42:18.844Z", + "updated_at": "2024-08-28T21:42:18.844Z", + "deleted_at": { + "time": "2024-08-28T21:42:18.844Z", + "valid": true + }, + "Principal": "string", + "PrincipalKind": "string", + "Finding": "string", + "DomainSID": "string", + "Props": { + "additionalProp1": {}, + "additionalProp2": {}, + "additionalProp3": {} + }, + "accepted_until": "2024-08-28T21:42:18.844Z", + "ImpactPercentage": 0, + "ImpactCount": 0, + "ExposurePercentage": 0, + "ExposureCount": 0, + "Severity": "", + "Accepted": true + } + ] + } + } } } } @@ -12881,15 +13058,14 @@ }, "query.entity.type": { "name": "type", - "description": "The type of return data requested. If no type is provided, query will default to `list`.\nThe only supported type is `list`, but unsupported `graph` and `count` can be used.\nAn invalid type will result in a `count` query. Some entity query endpoints do not\nsupport the `graph` type.\n", + "description": "The type of return data requested. If no type is provided, query will default to `list`.\nThe only supported type is `list`, but the unsupported `graph` type can be used.\nSome entity query endpoints do not support the `graph` type. For those interested in\nusing the undocumented graph type parameter, the response type is described in the schema\n`model.bh-graph.graph`.\n", "in": "query", "schema": { "type": "string", "default": "list", "enum": [ "list", - "graph", - "count" + "graph" ] } }, @@ -15400,6 +15576,32 @@ "AcceptedUntil": { "type": "string", "format": "date-time" + }, + "ImpactPercentage": { + "type": "number", + "format": "double" + }, + "ImpactCount": { + "type": "integer", + "format": "int64" + }, + "ExposurePercentage": { + "type": "number", + "format": "double" + }, + "ExposureCount": { + "type": "integer", + "format": "int64" + }, + "Severity": { + "type": "string", + "enum": [ + "critical", + "high", + "moderate", + "low", + "" + ] } } } @@ -15437,6 +15639,32 @@ "accepted_until": { "type": "string", "format": "date-time" + }, + "ImpactPercentage": { + "type": "number", + "format": "double" + }, + "ImpactCount": { + "type": "integer", + "format": "int64" + }, + "ExposurePercentage": { + "type": "number", + "format": "double" + }, + "ExposureCount": { + "type": "integer", + "format": "int64" + }, + "Severity": { + "type": "string", + "enum": [ + "critical", + "high", + "moderate", + "low", + "" + ] } } } @@ -15709,7 +15937,7 @@ } }, "related-entity-query-results": { - "description": "**OK**\n\nThis endpoint returns a response, dependent upon which return type is requested by the `type` parameter.\nThe only supported `type` parameter is `list`.\nWhile `list` is the only supported `type` parameter, the `count` or `graph` parameters can be used\nand will result in a different response structure then documented here.\nFor those interested in using the undocumented graph type parameter, the response type is described in the schema\nmodel.bh-graph.graph.\n", + "description": "**OK**\n\nThis endpoint returns a response, dependent upon which return type is requested by the `type` parameter.\nThe only supported `type` parameter is `list`.\nWhile `list` is the only supported `type` parameter, the `graph` parameter can be used\nand will result in a different response structure then documented here.\nFor those interested in using the undocumented graph type parameter, the response type is described in the schema\n`model.bh-graph.graph`.\n", "content": { "application/json": { "schema": { diff --git a/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml b/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml index 8cfb405bb..3d0ac051e 100644 --- a/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml +++ b/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml @@ -25,19 +25,22 @@ parameters: get: operationId: ListDomainAttackPathsDetails summary: List domain attack paths details - description: Lists detailed data about attack paths for a domain. + # !!!!!!!! New Description !!!!!!! + description: | + Lists detailed data about attack paths for a domain. + + __Note:__ __Note:__ `ImpactCount`, `ImpactPercentage`, `ExposureCount`, and `ExposurePercentage` will have a value other than zero when butterfly analysis is enabled. tags: - Attack Paths - Enterprise parameters: - name: finding - x-go-name: "FindingDeprecated" in: query schema: $ref: './../schemas/api.params.predicate.filter.string.yaml' - name: sort_by description: Sortable columns are `domain_sid`, `index`, `AcceptedUntil`, - `id`, `created_at`, `updated_at`, `deleted_at`. Relationship risks can be sorted on + `id`, `created_at`, `updated_at`, `deleted_at`, `exposure_percent`, `impact_percent`. Relationship risks can be sorted on `FromPrincipal` and `ToPrincipal` in addition to the sortable columns for List Risks. in: query @@ -45,13 +48,11 @@ get: $ref: './../schemas/api.params.query.sort-by.yaml' - name: FromPrincipal deprecated: true - x-go-name: "FromPrincipalDeprecated" in: query schema: $ref: './../schemas/api.params.predicate.filter.string.yaml' - name: ToPrincipal deprecated: true - x-go-name: "ToPrincipalDeprecated" in: query schema: $ref: './../schemas/api.params.predicate.filter.string.yaml' @@ -73,7 +74,6 @@ get: $ref: './../schemas/api.params.predicate.filter.string.yaml' - name: AcceptedUntil deprecated: true - x-go-name: "AcceptedUntilDeprecated" in: query schema: $ref: './../schemas/api.params.predicate.filter.time.yaml' @@ -86,6 +86,7 @@ get: schema: $ref: './../schemas/api.params.predicate.filter.string.yaml' - name: Finding + deprecated: true in: query schema: $ref: './../schemas/api.params.predicate.filter.string.yaml' @@ -135,6 +136,178 @@ get: properties: Accepted: type: boolean + # !!!!! New examples !!!!! + examples: + Butterfly Relationship Finding: + summary: "Butterfly Relationship Finding" + description: "When the butterfly analysis feature flag is on, impact count/percentage and exposure count/percentage will have a value other than zero." + value: + count: 0 + skip: 0 + limit: 0 + data: [ + { + id: 0, + created_at: "2024-08-28T21:21:40.845Z", + updated_at: "2024-08-28T21:21:40.845Z", + deleted_at: { + time: "2024-08-28T21:21:40.845Z", + valid: true + }, + FromPrincipal: string, + ToPrincipal: string, + FromPrincipalProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + FromPrincipalKind: string, + ToPrincipalProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + ToPrincipalKind: string, + RelProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + ComboGraphRelationID: { + int64: 0, + valid: true + }, + Finding: string, + DomainSID: string, + PrincipalHash: string, + AcceptedUntil: "2024-08-28T21:21:40.845Z", + ImpactPercentage: 12, + ImpactCount: 2, + ExposurePercentage: 24, + ExposureCount: 4, + Severity: 'high', + Accepted: true, + } + ] + Metatree Relationship Finding: + summary: "Metatree Relationship Finding" + description: "When the butterfly analysis feature flag is off and metatree is running, impact count/percentage and exposure count/percentage will have a value of zero." + value: + count: 0 + skip: 0 + limit: 0 + data: [ + { + id: 0, + created_at: "2024-08-28T21:21:40.845Z", + updated_at: "2024-08-28T21:21:40.845Z", + deleted_at: { + time: "2024-08-28T21:21:40.845Z", + valid: true + }, + FromPrincipal: string, + ToPrincipal: string, + FromPrincipalProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + FromPrincipalKind: string, + ToPrincipalProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + ToPrincipalKind: string, + RelProps: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + ComboGraphRelationID: { + int64: 0, + valid: true + }, + Finding: string, + DomainSID: string, + PrincipalHash: string, + AcceptedUntil: "2024-08-28T21:21:40.845Z", + ImpactPercentage: 0, + ImpactCount: 0, + ExposurePercentage: 0, + ExposureCount: 0, + Severity: '', + Accepted: true + } + ] + Butterfly List Finding: + summary: "Butterfly List Finding" + description: "When the butterfly analysis feature flag is on, impact count/percentage and exposure count/percentage will have a value other than zero." + value: + count: 0, + skip: 0, + limit: 0, + data: [ + { + id: 0, + created_at: "2024-08-28T21:42:18.844Z", + updated_at: "2024-08-28T21:42:18.844Z", + deleted_at: { + time: "2024-08-28T21:42:18.844Z", + valid: true + }, + Principal: string, + PrincipalKind: string, + Finding: string, + DomainSID: string, + Props: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + accepted_until: "2024-08-28T21:42:18.844Z", + ImpactPercentage: 12, + ImpactCount: 2, + ExposurePercentage: 24, + ExposureCount: 4, + Severity: 'high', + Accepted: true + } + ] + Metatree List Finding: + summary: "Metatree List Finding" + description: "When the butterfly analysis feature flag is off and metatree is running, impact count/percentage and exposure count/percentage will have a value of zero." + value: + count: 0, + skip: 0, + limit: 0, + data: [ + { + id: 0, + created_at: "2024-08-28T21:42:18.844Z", + updated_at: "2024-08-28T21:42:18.844Z", + deleted_at: { + time: "2024-08-28T21:42:18.844Z", + valid: true + }, + Principal: string, + PrincipalKind: string, + Finding: string, + DomainSID: string, + Props: { + additionalProp1: {}, + additionalProp2: {}, + additionalProp3: {} + }, + accepted_until: "2024-08-28T21:42:18.844Z", + ImpactPercentage: 0, + ImpactCount: 0, + ExposurePercentage: 0, + ExposureCount: 0, + Severity: '', + Accepted: true + } + ] 400: $ref: './../responses/bad-request.yaml' 401: diff --git a/packages/go/openapi/src/schemas/model.list-finding.yaml b/packages/go/openapi/src/schemas/model.list-finding.yaml index b00ff5405..f28376889 100644 --- a/packages/go/openapi/src/schemas/model.list-finding.yaml +++ b/packages/go/openapi/src/schemas/model.list-finding.yaml @@ -34,3 +34,23 @@ allOf: accepted_until: type: string format: date-time + ImpactPercentage: + type: number + format: double + ImpactCount: + type: integer + format: int64 + ExposurePercentage: + type: number + format: double + ExposureCount: + type: integer + format: int64 + Severity: + type: string + enum: + - critical + - high + - moderate + - low + - "" \ No newline at end of file diff --git a/packages/go/openapi/src/schemas/model.relationship-finding.yaml b/packages/go/openapi/src/schemas/model.relationship-finding.yaml index 65cef89a5..15b306262 100644 --- a/packages/go/openapi/src/schemas/model.relationship-finding.yaml +++ b/packages/go/openapi/src/schemas/model.relationship-finding.yaml @@ -50,3 +50,23 @@ allOf: AcceptedUntil: type: string format: date-time + ImpactPercentage: + type: number + format: double + ImpactCount: + type: integer + format: int64 + ExposurePercentage: + type: number + format: double + ExposureCount: + type: integer + format: int64 + Severity: + type: string + enum: + - critical + - high + - moderate + - low + - "" \ No newline at end of file From 750df0e6b1245b22333432a3a4f146f8f60c0448 Mon Sep 17 00:00:00 2001 From: Stephanie Lamb Date: Wed, 16 Oct 2024 15:58:03 -0500 Subject: [PATCH 4/5] ran prepare for codereview --- cmd/api/src/api/tools/analysis_schedule.go | 21 +++++++++++++++-- .../src/api/tools/analysis_schedule_test.go | 23 ++++++++++++++++--- cmd/api/src/api/v2/analysisrequest.go | 3 ++- cmd/api/src/go.mod | 3 ++- cmd/api/src/go.sum | 10 ++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/cmd/api/src/api/tools/analysis_schedule.go b/cmd/api/src/api/tools/analysis_schedule.go index b19b234c6..df2afe505 100644 --- a/cmd/api/src/api/tools/analysis_schedule.go +++ b/cmd/api/src/api/tools/analysis_schedule.go @@ -1,14 +1,31 @@ +// Copyright 2024 Specter Ops, Inc. +// +// Licensed under the Apache License, Version 2.0 +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + package tools import ( "fmt" + "net/http" + "strings" + "github.com/specterops/bloodhound/src/api" v2 "github.com/specterops/bloodhound/src/api/v2" "github.com/specterops/bloodhound/src/database/types" "github.com/specterops/bloodhound/src/model/appcfg" "github.com/teambition/rrule-go" - "net/http" - "strings" ) type ScheduledAnalysisConfiguration struct { diff --git a/cmd/api/src/api/tools/analysis_schedule_test.go b/cmd/api/src/api/tools/analysis_schedule_test.go index 51c272e9a..330e6d421 100644 --- a/cmd/api/src/api/tools/analysis_schedule_test.go +++ b/cmd/api/src/api/tools/analysis_schedule_test.go @@ -1,9 +1,29 @@ +// Copyright 2024 Specter Ops, Inc. +// +// Licensed under the Apache License, Version 2.0 +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + package tools_test import ( "bytes" "context" "encoding/json" + "net/http" + "net/http/httptest" + "testing" + "github.com/golang/mock/gomock" "github.com/gorilla/mux" "github.com/specterops/bloodhound/headers" @@ -11,9 +31,6 @@ import ( "github.com/specterops/bloodhound/src/api/tools" "github.com/specterops/bloodhound/src/ctx" "github.com/stretchr/testify/require" - "net/http" - "net/http/httptest" - "testing" ) func TestToolContainer_GetScheduledAnalysisConfiguration_Errors(t *testing.T) { diff --git a/cmd/api/src/api/v2/analysisrequest.go b/cmd/api/src/api/v2/analysisrequest.go index c12b5324b..2d6c06c6e 100644 --- a/cmd/api/src/api/v2/analysisrequest.go +++ b/cmd/api/src/api/v2/analysisrequest.go @@ -18,9 +18,10 @@ package v2 import ( "database/sql" - "github.com/specterops/bloodhound/src/model/appcfg" "net/http" + "github.com/specterops/bloodhound/src/model/appcfg" + "github.com/specterops/bloodhound/errors" "github.com/specterops/bloodhound/log" "github.com/specterops/bloodhound/src/api" diff --git a/cmd/api/src/go.mod b/cmd/api/src/go.mod index 52ab28f14..aaf6e2323 100644 --- a/cmd/api/src/go.mod +++ b/cmd/api/src/go.mod @@ -28,6 +28,7 @@ require ( github.com/gobeam/stringy v0.0.6 github.com/gofrs/uuid v4.4.0+incompatible github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/golang/mock v1.6.0 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/gorilla/schema v1.4.1 @@ -40,13 +41,13 @@ require ( github.com/prometheus/client_golang v1.16.0 github.com/russellhaering/goxmldsig v1.4.0 github.com/stretchr/testify v1.9.0 + github.com/teambition/rrule-go v1.8.2 github.com/unrolled/secure v1.13.0 github.com/zenazn/goji v1.0.1 go.uber.org/mock v0.2.0 golang.org/x/crypto v0.24.0 gorm.io/driver/postgres v1.3.8 gorm.io/gorm v1.23.8 - github.com/teambition/rrule-go v1.8.2 ) require ( diff --git a/cmd/api/src/go.sum b/cmd/api/src/go.sum index edf408c38..6e95fee82 100644 --- a/cmd/api/src/go.sum +++ b/cmd/api/src/go.sum @@ -49,6 +49,7 @@ github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1 github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= @@ -210,8 +211,10 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/teambition/rrule-go v1.8.2 h1:lIjpjvWTj9fFUZCmuoVDrKVOtdiyzbzc93qTmRVe/J8= github.com/unrolled/secure v1.13.0 h1:sdr3Phw2+f8Px8HE5sd1EHdj1aV3yUwed/uZXChLFsk= github.com/unrolled/secure v1.13.0/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= github.com/zenazn/goji v1.0.1 h1:4lbD8Mx2h7IvloP7r2C0D6ltZP6Ufip8Hn0wmSK5LR8= github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= @@ -243,13 +246,16 @@ golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5D golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -262,6 +268,8 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= @@ -285,7 +293,9 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 6715f623656d252c54dfe0a20b94155f87d7cd70 Mon Sep 17 00:00:00 2001 From: Stephanie Lamb Date: Wed, 23 Oct 2024 10:09:27 -0700 Subject: [PATCH 5/5] removed comment. added generic errors --- cmd/api/src/api/filters.go | 10 ++++++++++ .../src/paths/attack-paths.domains.id.details.yaml | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/api/src/api/filters.go b/cmd/api/src/api/filters.go index 3853ce133..94a50b873 100644 --- a/cmd/api/src/api/filters.go +++ b/cmd/api/src/api/filters.go @@ -17,11 +17,21 @@ package api import ( + "errors" "fmt" "github.com/specterops/bloodhound/src/model" ) +var ( + ErrColumnUnfilterable = errors.New("the specified column cannot be filtered") + ErrFilterPredicateNotSupported = errors.New("the specified filter predicate is not supported for this column") + ErrNoFindingType = errors.New("no finding type specified") + ErrColumnFormatNotSupported = errors.New("column format does not support sorting") + ErrInvalidFindingType = errors.New("invalid finding type specified") + ErrInvalidAcceptedFilter = errors.New("invalid finding type specified") +) + type Filterable interface { ValidFilters() map[string][]model.FilterOperator } diff --git a/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml b/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml index 3d0ac051e..46657a116 100644 --- a/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml +++ b/packages/go/openapi/src/paths/attack-paths.domains.id.details.yaml @@ -25,7 +25,6 @@ parameters: get: operationId: ListDomainAttackPathsDetails summary: List domain attack paths details - # !!!!!!!! New Description !!!!!!! description: | Lists detailed data about attack paths for a domain.