Skip to content

Instantly share code, notes, and snippets.

@nscuro
Last active August 30, 2024 07:26
Show Gist options
  • Save nscuro/cf97dfb4ae07b835ca721aafa7ac48f8 to your computer and use it in GitHub Desktop.
Save nscuro/cf97dfb4ae07b835ca721aafa7ac48f8 to your computer and use it in GitHub Desktop.
Dependency-Track GHSA Cleanup
CREATE FUNCTION "delete_ghsa_vulnerabilities"() RETURNS BOOLEAN
LANGUAGE "plpgsql"
AS
$$
DECLARE "v_vulnerability_id" BIGINT;
BEGIN
FOR "v_vulnerability_id" IN SELECT "ID" FROM "VULNERABILITY" WHERE "VULNID" LIKE 'GHSA-%'
LOOP
IF "v_vulnerability_id" IS NOT NULL THEN
DELETE FROM "AFFECTEDVERSIONATTRIBUTION"
WHERE "VULNERABILITY" = "v_vulnerability_id";
DELETE FROM "ANALYSISCOMMENT"
USING "ANALYSIS"
WHERE "ANALYSISCOMMENT"."ANALYSIS_ID" = "ANALYSIS"."ID"
AND "ANALYSIS"."VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "ANALYSIS"
WHERE "VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "COMPONENTS_VULNERABILITIES"
WHERE "VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "SERVICECOMPONENTS_VULNERABILITIES"
WHERE "VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "FINDINGATTRIBUTION"
WHERE "VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "VULNERABLESOFTWARE_VULNERABILITIES"
WHERE "VULNERABILITY_ID" = "v_vulnerability_id";
DELETE FROM "VULNERABILITY"
WHERE "ID" = "v_vulnerability_id";
END IF;
END LOOP;
RETURN TRUE;
END;
$$;
BEGIN;
SELECT "delete_ghsa_vulnerabilities"();
COMMIT;
DROP FUNCTION "delete_ghsa_vulnerabilities";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment