From fac8a0b9bc41d87a15e22a33e444ddec71150413 Mon Sep 17 00:00:00 2001 From: Stefan Petrushevski Date: Fri, 26 Apr 2024 21:38:59 +0200 Subject: [PATCH] addressing note CodeQL alerts --- dist/github/Utils.js | 15 --------------- dist/index.js | 1 - dist/main.js | 1 - src/evaluators/OrgPolicyEvaluator.ts | 1 - .../organization/OrgCustomRolesChecks.ts | 1 - src/evaluators/organization/OrgGHASChecks.ts | 1 - src/evaluators/repository/ActionsChecks.ts | 2 -- src/evaluators/repository/WebHooksChecks.ts | 2 -- src/github/Actions.ts | 1 - src/github/Issues.ts | 1 - src/github/Repositories.ts | 5 ++--- src/github/Utils.ts | 1 - src/main.ts | 5 +---- src/reporting/Report.ts | 3 +-- 14 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 dist/github/Utils.js diff --git a/dist/github/Utils.js b/dist/github/Utils.js deleted file mode 100644 index b5defcd..0000000 --- a/dist/github/Utils.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getRepoFile = void 0; -const GitArmorKit_1 = require("./GitArmorKit"); -//Given a certain path in a repository, get the contents of the file -const getRepoFile = async (owner, repo, path) => { - const octokit = new GitArmorKit_1.GitArmorKit(); - const response = await octokit.rest.repos.getContent({ - owner: owner, - repo: repo, - path: path, - }); - return response.data; -}; -exports.getRepoFile = getRepoFile; diff --git a/dist/index.js b/dist/index.js index 27f6992..eb09e66 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49519,7 +49519,6 @@ const run = async () => { let report = new Report_1.Report(); report.addInput(inputs); report.addPolicy(policies); - const policyEvaluator = null; // depending on which input.level is provided, run the appropriate checks if (inputs.level === "organization") { Logger_1.logger.info("Running org level checks"); diff --git a/dist/main.js b/dist/main.js index fe4ad09..ffae7ad 100644 --- a/dist/main.js +++ b/dist/main.js @@ -46,7 +46,6 @@ const run = async () => { let report = new Report_1.Report(); report.addInput(inputs); report.addPolicy(policies); - const policyEvaluator = null; // depending on which input.level is provided, run the appropriate checks if (inputs.level === "organization") { Logger_1.logger.info("Running org level checks"); diff --git a/src/evaluators/OrgPolicyEvaluator.ts b/src/evaluators/OrgPolicyEvaluator.ts index 546a50f..d8c50ec 100644 --- a/src/evaluators/OrgPolicyEvaluator.ts +++ b/src/evaluators/OrgPolicyEvaluator.ts @@ -4,7 +4,6 @@ import { OrgGHASChecks } from "./organization/OrgGHASChecks"; import { OrgAuthenticationChecks } from "./organization/OrgAuthenticationChecks"; import { OrgCustomRolesChecks } from "./organization/OrgCustomRolesChecks"; import { getOrganization } from "../github/Organization"; -import { FilesExistChecks } from "./multipurpose/FilesExistChecks"; import { PrivilegesChecks } from "./organization/PrivilegesChecks"; export class OrgPolicyEvaluator { diff --git a/src/evaluators/organization/OrgCustomRolesChecks.ts b/src/evaluators/organization/OrgCustomRolesChecks.ts index 81aa3cc..9220d7a 100644 --- a/src/evaluators/organization/OrgCustomRolesChecks.ts +++ b/src/evaluators/organization/OrgCustomRolesChecks.ts @@ -1,6 +1,5 @@ import { Organization, CheckResult } from "../../types/common/main"; import { getCustomRolesForOrg } from "../../github/Organization"; -import { logger } from "../../utils/Logger"; export class OrgCustomRolesChecks { private policy: any; diff --git a/src/evaluators/organization/OrgGHASChecks.ts b/src/evaluators/organization/OrgGHASChecks.ts index c7fa79d..89e269d 100644 --- a/src/evaluators/organization/OrgGHASChecks.ts +++ b/src/evaluators/organization/OrgGHASChecks.ts @@ -1,6 +1,5 @@ import { Organization, CheckResult } from "../../types/common/main"; import { getSecurityTeamsForOrg } from "../../github/Organization"; -import { logger } from "../../utils/Logger"; export class OrgGHASChecks { private policy: any; diff --git a/src/evaluators/repository/ActionsChecks.ts b/src/evaluators/repository/ActionsChecks.ts index 92f996a..78b5d44 100644 --- a/src/evaluators/repository/ActionsChecks.ts +++ b/src/evaluators/repository/ActionsChecks.ts @@ -2,8 +2,6 @@ import { CheckResult, Repository } from "../../types/common/main"; import { getRepoActionsPermissions, getRepoSelectedActions, - getRepoWorkflows, - getRepoWorkflowActions, } from "../../github/Actions"; import { logger } from "../../utils/Logger"; diff --git a/src/evaluators/repository/WebHooksChecks.ts b/src/evaluators/repository/WebHooksChecks.ts index 9727c07..6b84053 100644 --- a/src/evaluators/repository/WebHooksChecks.ts +++ b/src/evaluators/repository/WebHooksChecks.ts @@ -1,6 +1,5 @@ import { CheckResult, Repository } from "../../types/common/main"; import { getWebHooks, getWebHookConfig } from "../../github/WebHooks"; -import { logger } from "../../utils/Logger"; export class WebHooksChecks { private policy: any; @@ -18,7 +17,6 @@ export class WebHooksChecks { this.repository.name, ); - // for each webhook in webhooks extract the domain and check if it is in the allowed list in the policy, if not return false const allowedDomains = this.policy.webhooks.allowed_domains; diff --git a/src/github/Actions.ts b/src/github/Actions.ts index d4add4c..c7be3c0 100644 --- a/src/github/Actions.ts +++ b/src/github/Actions.ts @@ -1,7 +1,6 @@ import { Endpoints } from "@octokit/types"; import { GitArmorKit } from "./GitArmorKit"; import { logger } from "../utils/Logger"; -import { getRepoFile } from "./Utils"; //Get GitHub Actions permissions for a repository export const getRepoActionsPermissions = async ( diff --git a/src/github/Issues.ts b/src/github/Issues.ts index c0d948d..b948a69 100644 --- a/src/github/Issues.ts +++ b/src/github/Issues.ts @@ -1,4 +1,3 @@ -import { Issue } from "../types/common/main"; import { GitArmorKit } from "./GitArmorKit"; // export class to Issues class diff --git a/src/github/Repositories.ts b/src/github/Repositories.ts index 8c8a6f4..af7194b 100644 --- a/src/github/Repositories.ts +++ b/src/github/Repositories.ts @@ -28,15 +28,14 @@ export const getRepository = async ( repo: string, ): Promise => { const octokit = new GitArmorKit(); - + const response: Endpoints["GET /repos/{owner}/{repo}"]["response"] = await octokit.rest.repos.get({ owner: owner, repo: repo, }); - - return response.data; + return response.data; }; export const getRepoPullRequests = async ( diff --git a/src/github/Utils.ts b/src/github/Utils.ts index e87e0be..3519a0f 100644 --- a/src/github/Utils.ts +++ b/src/github/Utils.ts @@ -1,6 +1,5 @@ import { Endpoints } from "@octokit/types"; import { GitArmorKit } from "./GitArmorKit"; -import { logger } from "../utils/Logger"; //Given a certain path in a repository, get the contents of the file export const getRepoFile = async ( diff --git a/src/main.ts b/src/main.ts index 22ae6f4..d33fd61 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,10 +7,8 @@ import { Report } from "./reporting/Report"; import { RepoPolicy, OrgPolicy, Repository } from "./types/common/main"; import { loadPolicy } from "./utils/policies"; import * as core from "@actions/core"; -import { summary } from "@actions/core/lib/summary"; const run = async (): Promise => { - console.log(` GitArmor @@ -27,7 +25,6 @@ const run = async (): Promise => { let report = new Report(); report.addInput(inputs); report.addPolicy(policies); - const policyEvaluator = null; // depending on which input.level is provided, run the appropriate checks if (inputs.level === "organization") { logger.info("Running org level checks"); @@ -72,7 +69,7 @@ const run = async (): Promise => { repository, policies.repo as RepoPolicy, ); - + await policyEvaluator.evaluatePolicy(); policyEvaluator.printCheckResults(); report.addOneRepoEvaluator(policyEvaluator); diff --git a/src/reporting/Report.ts b/src/reporting/Report.ts index 19f34ff..a1c1408 100644 --- a/src/reporting/Report.ts +++ b/src/reporting/Report.ts @@ -1,9 +1,8 @@ -import { CheckResult, Policy, Inputs } from "../types/common/main"; +import { Policy, Inputs } from "../types/common/main"; import { OrgPolicyEvaluator } from "../evaluators/OrgPolicyEvaluator"; import { RepoPolicyEvaluator } from "../evaluators/RepoPolicyEvaluator"; import { logger } from "./../utils/Logger"; import fs from "fs"; -import { json } from "stream/consumers"; export class Report { private orgEvaluators: Map;