Skip to content

Commit

Permalink
run precommits
Browse files Browse the repository at this point in the history
run precommits and linter fixes
  • Loading branch information
DJensen94 committed Sep 27, 2024
1 parent adf58d9 commit 6bcbeef
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 72 deletions.
1 change: 0 additions & 1 deletion backend/src/api/vulnerabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class VulnerabilitySearch {
.leftJoinAndSelect('domain.organization', 'organization')
.leftJoinAndSelect('vulnerability.service', 'service');


qs.andWhere(
'domain."isFceb" = true OR (domain."isFceb" = false AND domain."fromCidr" = true)'
);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Domain extends BaseEntity {
default: false
})
isFceb: boolean;

/** SSL Certificate information */
@Column({
type: 'jsonb',
Expand Down
37 changes: 20 additions & 17 deletions backend/src/tasks/flagfloatingIps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ import { CommandOptions } from './ecs-client';
import checkIpInCidr from './helpers/checkIpInCidr';
import { Organization, connectToDatabase } from '../models';



export const handler = async (commandOptions: CommandOptions) => {
const db_connection = await connectToDatabase()
const organization_repo = db_connection.getRepository(Organization);
const organizations = await organization_repo.find({ relations: ['domains'] });
const db_connection = await connectToDatabase();
const organization_repo = db_connection.getRepository(Organization);
const organizations = await organization_repo.find({
relations: ['domains']
});

for (const organization of organizations) {
for (const domain of organization.domains) {
if (domain.ip){
const cidrSectorDict = await checkIpInCidr(domain.ip, organization.acronym);
if (cidrSectorDict['isInCidr']) {
domain.fromCidr = true;
}
if (cidrSectorDict['isExecutive']) {
domain.isFceb = true
}
domain.save()
}
for (const organization of organizations) {
for (const domain of organization.domains) {
if (domain.ip) {
const cidrSectorDict = await checkIpInCidr(
domain.ip,
organization.acronym
);
if (cidrSectorDict['isInCidr']) {
domain.fromCidr = true;
}
if (cidrSectorDict['isExecutive']) {
domain.isFceb = true;
}
domain.save();
}
}
}
};
112 changes: 59 additions & 53 deletions backend/src/tasks/helpers/checkIpInCidr.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
import { getRepository } from 'typeorm';
import { Cidr, DL_Organization,connectToDatalake2 } from '../../models';

export default async (ip: string, acronym: string): Promise<{ isInCidr: boolean; isExecutive: boolean }> => {
// await connectToDatalake2()
// const cidrRepository = getRepository(Cidr);
// const organizationRepository = getRepository(DL_Organization);

// Find the organization by acronym
const mdl_connection = await connectToDatalake2()
const mdl_organization_repo = mdl_connection.getRepository(DL_Organization);
const organization = await mdl_organization_repo.findOne({
where: { acronym },
relations: ['cidrs','sectors','parent'],
});

if (!organization) {
return {isInCidr:false, isExecutive: false}
import { Cidr, DL_Organization, connectToDatalake2 } from '../../models';

export default async (
ip: string,
acronym: string
): Promise<{ isInCidr: boolean; isExecutive: boolean }> => {
// await connectToDatalake2()
// const cidrRepository = getRepository(Cidr);
// const organizationRepository = getRepository(DL_Organization);

// Find the organization by acronym
const mdl_connection = await connectToDatalake2();
const mdl_organization_repo = mdl_connection.getRepository(DL_Organization);
const organization = await mdl_organization_repo.findOne({
where: { acronym },
relations: ['cidrs', 'sectors', 'parent']
});

if (!organization) {
return { isInCidr: false, isExecutive: false };
}

const isOrganizationExecutive = async (
org: DL_Organization
): Promise<boolean> => {
if (org.sectors.some((sector) => sector.acronym === 'EXECUTIVE')) {
return true;
}

const isOrganizationExecutive = async (org: DL_Organization): Promise<boolean> => {
if (org.sectors.some(sector => sector.acronym === 'EXECUTIVE')) {
return true;
}
if (org.parent) {
const parentOrg = await mdl_organization_repo.findOne({
where: { id: org.parent.id },
relations: ['sectors'],
});
console.log('parent')
console.log(parentOrg)
return parentOrg ? await isOrganizationExecutive(parentOrg) : false;
}
return false;
};

const isExecutive = await isOrganizationExecutive(organization);

// Get CIDRs related to the organization
const cidrs = organization.cidrs.map(cidr => cidr.network);

if (cidrs.length === 0) {
return { isInCidr: false, isExecutive }; // No CIDRs associated with the organization
if (org.parent) {
const parentOrg = await mdl_organization_repo.findOne({
where: { id: org.parent.id },
relations: ['sectors']
});
console.log('parent');
console.log(parentOrg);
return parentOrg ? await isOrganizationExecutive(parentOrg) : false;
}

// Check if the IP is in any of the CIDRs
const mdl_cidr_repo = mdl_connection.getRepository(Cidr);
const result = await mdl_cidr_repo
.createQueryBuilder('cidr')
.where('cidr.network >>= :ip', { ip })
.andWhere('cidr.id IN (:...cidrIds)', { cidrIds: organization.cidrs.map(cidr => cidr.id) })
.getCount();


return { isInCidr: result > 0, isExecutive };
}
return false;
};

const isExecutive = await isOrganizationExecutive(organization);

// Get CIDRs related to the organization
const cidrs = organization.cidrs.map((cidr) => cidr.network);

if (cidrs.length === 0) {
return { isInCidr: false, isExecutive }; // No CIDRs associated with the organization
}

// Check if the IP is in any of the CIDRs
const mdl_cidr_repo = mdl_connection.getRepository(Cidr);
const result = await mdl_cidr_repo
.createQueryBuilder('cidr')
.where('cidr.network >>= :ip', { ip })
.andWhere('cidr.id IN (:...cidrIds)', {
cidrIds: organization.cidrs.map((cidr) => cidr.id)
})
.getCount();

return { isInCidr: result > 0, isExecutive };
};

0 comments on commit 6bcbeef

Please sign in to comment.