Skip to content

Commit 3649a31

Browse files
authored
Merge pull request CactuseSecurity#3046 from Y4nnikH/fix/rsb-all-tab-duplicates
fix(ui rsb): ui crash likely caused by duplicates in query result
2 parents 1d8064a + a32322a commit 3649a31

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

roles/lib/files/FWO.Api.Client/APIcalls/allObjects/getAllObjectDetails.graphql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ query getAllObjectDetails (
22
$management_id: [Int!]
33
$type: [String!]
44
$uid: [String!]
5-
$time: String
5+
$import_id: bigint
66
$obj_name: [String!]
77
$limit: Int
88
$offset: Int
@@ -25,7 +25,8 @@ query getAllObjectDetails (
2525
offset: $offset
2626
where: {
2727
stm_obj_typ: { obj_typ_name: { _in: $type } }
28-
active: { _eq: true }
28+
obj_last_seen: { _gte: $import_id }
29+
obj_create: { _lte: $import_id }
2930
obj_name: { _in: $obj_name }
3031
obj_uid: { _in: $uid }
3132
}
@@ -38,7 +39,8 @@ query getAllObjectDetails (
3839
offset: $offset
3940
where: {
4041
stm_svc_typ: { svc_typ_name: { _in: $type } }
41-
active: { _eq: true }
42+
svc_last_seen: { _gte: $import_id }
43+
svc_create: { _lte: $import_id }
4244
svc_name: { _in: $obj_name }
4345
svc_uid: { _in: $uid }
4446
}
@@ -51,7 +53,8 @@ query getAllObjectDetails (
5153
offset: $offset
5254
where: {
5355
stm_usr_typ: { usr_typ_name: { _in: $type } }
54-
active: { _eq: true }
56+
user_last_seen: { _gte: $import_id }
57+
user_create: { _lte: $import_id }
5558
user_name: { _in: $obj_name }
5659
user_uid: { _in: $uid }
5760
}

roles/lib/files/FWO.Api.Client/APIcalls/networkObject/getNetworkObjectDetails.graphql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ query getNetworkObjectDetails(
22
$management_id: [Int!]
33
$nwObjTyp: [String!]
44
$nwObjUid: [String!]
5-
$time: String
5+
$import_id: bigint
66
$obj_name: [String!]
77
$obj_ip: [cidr!]
88
$limit: Int
@@ -16,12 +16,13 @@ query getNetworkObjectDetails(
1616
offset: $offset
1717
where: {
1818
stm_obj_typ: { obj_typ_name: { _in: $nwObjTyp } }
19-
active: { _eq: true }
19+
obj_last_seen: { _gte: $import_id }
20+
obj_create: { _lte: $import_id }
2021
obj_name: { _in: $obj_name }
2122
obj_ip: { _in: $obj_ip }
2223
obj_uid: { _in: $nwObjUid }
2324
}
24-
order_by: { obj_name: asc }
25+
order_by: [{ obj_name: asc }, { obj_id: asc }]
2526
) {
2627
...networkObjectDetails
2728
}

roles/lib/files/FWO.Api.Client/APIcalls/networkService/getNetworkServiceDetails.graphql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
query getNetworkServiceDetails(
22
$management_id: [Int!]
3-
$time: String
3+
$import_id: bigint
44
$svc_name: [String!]
55
$svc_port: [Int!]
66
$limit: Int
@@ -13,11 +13,12 @@ query getNetworkServiceDetails(
1313
limit: $limit
1414
offset: $offset
1515
where: {
16-
active: { _eq: true }
16+
svc_last_seen: { _gte: $import_id }
17+
svc_create: { _lte: $import_id }
1718
svc_name: { _in: $svc_name }
1819
svc_port: { _in: $svc_port }
1920
}
20-
order_by: { svc_name: asc }
21+
order_by: [{ svc_name: asc }, { svc_id: asc }]
2122
) {
2223
...networkServiceDetails
2324
}

roles/lib/files/FWO.Api.Client/APIcalls/user/getUserDetails.graphql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
query listUsers(
1+
query getUserDetails(
22
$management_id: [Int!]
3-
$time: String
3+
$import_id: bigint
44
$user_name: [String!]
55
$limit: Int
66
$offset: Int
@@ -11,8 +11,12 @@ query listUsers(
1111
userObjects: usrs(
1212
limit: $limit
1313
offset: $offset
14-
where: { active: { _eq: true }, user_name: { _in: $user_name } }
15-
order_by: { user_name: asc }
14+
where: {
15+
user_last_seen: { _gte: $import_id }
16+
user_create: { _lte: $import_id }
17+
user_name: { _in: $user_name }
18+
}
19+
order_by: [{ user_name: asc }, { user_id: asc }]
1620
) {
1721
...userDetails
1822
}

roles/ui/files/FWO.UI/Shared/RightSidebar.razor

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using System
1+
@using System
22
@using FWO.Report
33
@using FWO.Report.Filter
44
@using FWO.Ui.Data
@@ -147,6 +147,17 @@
147147
});
148148
}
149149

150+
private async Task<long> GetImportId(int mgmId)
151+
{
152+
Dictionary<string, object> ImpIdQueryVariables = new()
153+
{
154+
["time"] = DateTime.Now.ToString(DynGraphqlQuery.fullTimeFormat), // TODO: if set, use time from lsb
155+
["mgmIds"] = mgmId
156+
};
157+
List<ManagementReport> result = await apiConnection.SendQueryAsync<List<ManagementReport>>(ReportQueries.getRelevantImportIdsAtTime, ImpIdQueryVariables);
158+
return result.First().Import.ImportAggregate.ImportAggregateMax.RelevantImportId ?? 0;
159+
}
160+
150161
public async Task FetchContent(RsbTab rsbTab, ObjCategory objType, Func<ReportData, Task> callback, long id = 0, bool nat = false)
151162
{
152163
Log.WriteDebug("Fetching Content..", $"nat: {nat}");
@@ -165,6 +176,8 @@
165176
{
166177
case RsbTab.all:
167178
queryVars.Add("management_id", (int)id);
179+
queryVars.Add("import_id", await GetImportId((int)id));
180+
168181
switch (objType)
169182
{
170183
case ObjCategory.all:
@@ -198,6 +211,7 @@
198211
if (objType == ObjCategory.all)
199212
{
200213
queryVars.Add("rule_id", id);
214+
queryVars.Remove("limit"); // No pagination for rule details
201215
query = nat ? RuleQueries.getNatRuleDetails : RuleQueries.getRuleDetails;
202216
await FetchObjects(query, queryVars, callback);
203217
}
@@ -218,6 +232,7 @@
218232
ReportData reportData = new();
219233
bool newObjects = true;
220234
int fetchCount = 0;
235+
int elementsPerFetch = userConfig.ElementsPerFetch;
221236

222237
while (newObjects && (++fetchCount <= userConfig.MaxInitialFetchesRightSidebar || userConfig.AutoFillRightSidebar))
223238
{
@@ -232,11 +247,11 @@
232247
}
233248

234249
if (queryVars.ContainsKey("offset"))
235-
queryVars["offset"] = (int)queryVars["offset"] + userConfig.ElementsPerFetch;
250+
queryVars["offset"] = (int)queryVars["offset"] + elementsPerFetch;
236251
await callback(reportData);
237252
}
238253

239-
Log.WriteDebug("Lazy Fetch", $"Fetched sidebar objects in {fetchCount - 1} cycle(s) ({userConfig.ElementsPerFetch} at a time)");
254+
Log.WriteDebug("Lazy Fetch", $"Fetched sidebar objects in {fetchCount - 1} cycle(s) ({elementsPerFetch} at a time)");
240255

241256
if (fetchCount > userConfig.MaxInitialFetchesRightSidebar && !userConfig.AutoFillRightSidebar)
242257
DisplayMessageInUi(null, userConfig.GetText("object_fetch_warning"), userConfig.GetText("E0021"), true);

0 commit comments

Comments
 (0)