Skip to content

fix(alert detected type): don't default to leaked secret #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
001139a
rename timestamp coloumn to time
kantord Jan 23, 2025
4c2c604
make 'time' the first column
kantord Jan 23, 2025
474f9a2
use relative date time format in alerts table
kantord Jan 23, 2025
e68e4c2
rename trigger type column to type
kantord Jan 23, 2025
70ceabb
clamp trigger markdown to a single lineoverflowoverflow
kantord Jan 23, 2025
fa48c6e
remove code and file columns from alerts table
kantord Jan 23, 2025
a956b9e
rename trigger token column to event
kantord Jan 23, 2025
bc6542f
.
kantord Jan 23, 2025
04860b3
implement event column content correctly
kantord Jan 23, 2025
5e92cbe
implement type column values
kantord Jan 23, 2025
f7c9c73
add note about ongoing discussion on message type
kantord Jan 24, 2025
3a778b2
fix mapping alerts type
kantord Jan 24, 2025
2a742d8
Merge branch 'main' into alerts-table-refactor
kantord Jan 24, 2025
c07eeac
display detected problem properly
kantord Jan 24, 2025
7d55f72
Merge branch 'main' into alerts-table-refactor
kantord Jan 24, 2025
b75fc79
configure alerts table width
kantord Jan 24, 2025
d013d4e
fix(getIssueDetectedType): don't default to `leaked_secret`
alex-mcgovern Jan 27, 2025
360af2c
fix(`AlertsTable`): failing test
alex-mcgovern Jan 27, 2025
4c5cbac
chore: tidy up
alex-mcgovern Jan 27, 2025
60bda23
fix table column sizing using <ResizableTableContainer />
kantord Jan 27, 2025
5063b18
Merge branch 'alerts-table-refactor' into fix/issue-detected-type/don…
alex-mcgovern Jan 27, 2025
d402361
Merge branch 'main' into fix/issue-detected-type/don't-default-to-lea…
kantord Jan 27, 2025
879df3d
chore: more sane mock for alert secrets
alex-mcgovern Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/AlertsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function IssueDetectedCellContent({ alert }: { alert: AlertConversation }) {
return (
<>
<PackageX className="size-4 text-blue-700" />

Blocked malicious package
</>
);
Expand Down
12 changes: 12 additions & 0 deletions src/features/alerts/lib/__tests__/is-alert-malicious.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from "vitest";
import { isAlertMalicious } from "../is-malicious";
import { ALERT_MALICIOUS } from "../../mocks/alert-malicious.mock";
import { ALERT_SECRET } from "../../mocks/alert-secret.mock";

test("matches malicious alert", () => {
expect(isAlertMalicious(ALERT_MALICIOUS)).toBe(true);
});

test("doesn't match secret", () => {
expect(isAlertMalicious(ALERT_SECRET)).toBe(false);
});
12 changes: 12 additions & 0 deletions src/features/alerts/lib/__tests__/is-alert-secret.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from "vitest";
import { ALERT_MALICIOUS } from "../../mocks/alert-malicious.mock";
import { ALERT_SECRET } from "../../mocks/alert-secret.mock";
import { isAlertSecret } from "../is-alert-secret";

test("matches secret alert", () => {
expect(isAlertSecret(ALERT_SECRET)).toBe(true);
});

test("doesn't match malicious", () => {
expect(isAlertSecret(ALERT_MALICIOUS)).toBe(false);
});
8 changes: 8 additions & 0 deletions src/features/alerts/lib/is-alert-secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AlertConversation } from "@/api/generated";

export function isAlertSecret({
trigger_type,
trigger_category,
}: AlertConversation) {
return trigger_category === "critical" && trigger_type === "codegate-secrets";
}
14 changes: 14 additions & 0 deletions src/features/alerts/lib/is-malicious.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AlertConversation } from "@/api/generated";

export function isAlertMalicious({
trigger_string,
trigger_category,
}: AlertConversation) {
return (
trigger_category === "critical" &&
trigger_string !== null &&
typeof trigger_string === "object" &&
"status" in trigger_string &&
trigger_string.status === "malicious"
);
}
37 changes: 37 additions & 0 deletions src/features/alerts/mocks/alert-malicious.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AlertConversation, QuestionType } from "@/api/generated";

export const ALERT_MALICIOUS = {
conversation: {
question_answers: [
{
question: {
message:
"Context: invokehttp is a Python package available on PyPI ecosystem. However, this package is found to be malicious and must not be used. For additional information refer to https://www.insight.stacklok.com/report/pypi/invokehttp - Package offers this functionality: Python HTTP for Humans.\n \n\n Query: Is invokehttp a malicious package?",
timestamp: "2025-01-14T16:29:49.602403Z",
message_id: "bf92bf3c-fcec-4064-ad02-c792026c3555",
},
answer: {
message:
"**Warning:** CodeGate detected one or more malicious, deprecated or archived packages.\n- Pkg 1: [https://www.insight.stacklok.com/report/pypi/invokehttp](https://www.insight.stacklok.com/report/pypi/invokehttp)",
timestamp: "2025-01-14T16:29:50.213490Z",
message_id: "7e260699-906e-43dc-a43e-8f288389bd9d",
},
},
],
provider: "copilot",
type: QuestionType.CHAT,
chat_id: "bf92bf3c-fcec-4064-ad02-c792026c3555",
conversation_timestamp: "2025-01-14T16:29:49.602403Z",
},
alert_id: "bf92bf3c-fcec-4064-ad02-c792026c3555",
code_snippet: null,
trigger_string: {
name: "invokehttp",
type: "pypi",
status: "malicious",
description: "Python HTTP for Humans.",
},
trigger_type: "codegate-context-retriever",
trigger_category: "critical",
timestamp: "2025-01-14T16:29:49.602403Z",
} satisfies AlertConversation;
31 changes: 31 additions & 0 deletions src/features/alerts/mocks/alert-secret.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AlertConversation, QuestionType } from "@/api/generated";

export const ALERT_SECRET = {
conversation: {
question_answers: [
{
question: {
message: "Analyse this file please",
timestamp: "2025-01-13T17:15:06.942856Z",
message_id: "11ab8b11-0338-4fdb-b329-2184d3e71a14",
},
answer: {
message: "foo-bar",
timestamp: "2025-01-13T17:15:08.537530Z",
message_id: "f1a6201f-0d7f-4c93-bb84-525f2a2d0d3b",
},
},
],
provider: "copilot",
type: QuestionType.CHAT,
chat_id: "11ab8b11-0338-4fdb-b329-2184d3e71a14",
conversation_timestamp: "2025-01-13T17:15:06.942856Z",
},
alert_id: "11ab8b11-0338-4fdb-b329-2184d3e71a14",
code_snippet: null,
trigger_string:
"Amazon - Secret Access Key:\n steps:\n - name: Checkout Repository\n uses: REDACTED<$foo-bar> # v4\n\n - name: Setup\n uses: ./.github/actions/setup",
trigger_type: "codegate-secrets",
trigger_category: "critical",
timestamp: "2025-01-13T17:15:06.942856Z",
} satisfies AlertConversation;
13 changes: 6 additions & 7 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AlertConversation, Conversation } from "@/api/generated/types.gen";
import { isAlertSecret } from "@/features/alerts/lib/is-alert-secret";
import { isAlertMalicious } from "@/features/alerts/lib/is-malicious";
import { MaliciousPkgType, TriggerType } from "@/types";
import { format, isToday, isYesterday } from "date-fns";

Expand Down Expand Up @@ -178,12 +180,9 @@ export function getMaliciousPackage(

export function getIssueDetectedType(
alert: AlertConversation,
): "malicious_package" | "leaked_secret" {
const maliciousPackage = getMaliciousPackage(alert.trigger_string);
): "malicious_package" | "leaked_secret" | null {
if (isAlertMalicious(alert)) return "malicious_package";
if (isAlertSecret(alert)) return "leaked_secret";

if (maliciousPackage !== null && typeof maliciousPackage === "object") {
return "malicious_package";
}

return "leaked_secret";
return null;
}
Loading