@@ -33,6 +33,22 @@ describe('MCP Security Validations', () => {
3333 } ) . toThrow ( "Argument '-y' is not allowed for command 'npx'" )
3434 } )
3535
36+ it ( 'should block --yes flag' , ( ) => {
37+ expect ( ( ) => {
38+ validateCommandFlags ( 'npx' , [ '--yes' , 'https://test-malicious-download.com' ] )
39+ } ) . toThrow ( "Argument '--yes' is not allowed for command 'npx'" )
40+ } )
41+
42+ it ( 'should block --node-options flag' , ( ) => {
43+ expect ( ( ) => {
44+ validateCommandFlags ( 'npx' , [ '--node-options' , '--eval malicious' ] )
45+ } ) . toThrow ( "Argument '--node-options' is not allowed for command 'npx'" )
46+
47+ expect ( ( ) => {
48+ validateCommandFlags ( 'npx' , [ '--node-options=--eval malicious' ] )
49+ } ) . toThrow ( "contains flag '--node-options'" )
50+ } )
51+
3652 it ( 'should block case variations' , ( ) => {
3753 expect ( ( ) => {
3854 validateCommandFlags ( 'npx' , [ '-C' , 'command' ] )
@@ -83,6 +99,42 @@ describe('MCP Security Validations', () => {
8399 } ) . toThrow ( "Argument '--inspect-brk' is not allowed for command 'node'" )
84100 } )
85101
102+ it ( 'should block -r/--require flags' , ( ) => {
103+ expect ( ( ) => {
104+ validateCommandFlags ( 'node' , [ '-r' , 'malicious-module' ] )
105+ } ) . toThrow ( "Argument '-r' is not allowed for command 'node'" )
106+
107+ expect ( ( ) => {
108+ validateCommandFlags ( 'node' , [ '--require' , 'malicious-module' ] )
109+ } ) . toThrow ( "Argument '--require' is not allowed for command 'node'" )
110+ } )
111+
112+ it ( 'should block --loader/--experimental-loader flags' , ( ) => {
113+ expect ( ( ) => {
114+ validateCommandFlags ( 'node' , [ '--loader' , './malicious-loader.mjs' ] )
115+ } ) . toThrow ( "Argument '--loader' is not allowed for command 'node'" )
116+
117+ expect ( ( ) => {
118+ validateCommandFlags ( 'node' , [ '--experimental-loader' , './malicious-loader.mjs' ] )
119+ } ) . toThrow ( "Argument '--experimental-loader' is not allowed for command 'node'" )
120+ } )
121+
122+ it ( 'should block --import flag' , ( ) => {
123+ expect ( ( ) => {
124+ validateCommandFlags ( 'node' , [ '--import' , './malicious.mjs' ] )
125+ } ) . toThrow ( "Argument '--import' is not allowed for command 'node'" )
126+ } )
127+
128+ it ( 'should block --env-file flag' , ( ) => {
129+ expect ( ( ) => {
130+ validateCommandFlags ( 'node' , [ '--env-file' , '.env' ] )
131+ } ) . toThrow ( "Argument '--env-file' is not allowed for command 'node'" )
132+
133+ expect ( ( ) => {
134+ validateCommandFlags ( 'node' , [ '--env-file=.env' ] )
135+ } ) . toThrow ( "contains flag '--env-file'" )
136+ } )
137+
86138 it ( 'should allow legitimate node usage' , ( ) => {
87139 expect ( ( ) => {
88140 validateCommandFlags ( 'node' , [ 'server.js' ] )
@@ -189,6 +241,56 @@ describe('MCP Security Validations', () => {
189241 } ) . toThrow ( "Argument '--ipc' is not allowed for command 'docker'" )
190242 } )
191243
244+ it ( 'should block --mount flag' , ( ) => {
245+ expect ( ( ) => {
246+ validateCommandFlags ( 'docker' , [ '--mount' , 'type=bind,source=/,target=/host' ] )
247+ } ) . toThrow ( "Argument '--mount' is not allowed for command 'docker'" )
248+
249+ expect ( ( ) => {
250+ validateCommandFlags ( 'docker' , [ '--mount=type=bind,source=/,target=/host' ] )
251+ } ) . toThrow ( "contains flag '--mount'" )
252+ } )
253+
254+ it ( 'should block --device flag' , ( ) => {
255+ expect ( ( ) => {
256+ validateCommandFlags ( 'docker' , [ '--device' , '/dev/sda' ] )
257+ } ) . toThrow ( "Argument '--device' is not allowed for command 'docker'" )
258+ } )
259+
260+ it ( 'should block --entrypoint flag' , ( ) => {
261+ expect ( ( ) => {
262+ validateCommandFlags ( 'docker' , [ '--entrypoint' , '/bin/sh' ] )
263+ } ) . toThrow ( "Argument '--entrypoint' is not allowed for command 'docker'" )
264+ } )
265+
266+ it ( 'should block compose subcommand' , ( ) => {
267+ expect ( ( ) => {
268+ validateCommandFlags ( 'docker' , [ 'compose' , 'up' ] )
269+ } ) . toThrow ( "Argument 'compose' is not allowed for command 'docker'" )
270+ } )
271+
272+ it ( 'should block --volumes-from flag' , ( ) => {
273+ expect ( ( ) => {
274+ validateCommandFlags ( 'docker' , [ '--volumes-from' , 'other-container' ] )
275+ } ) . toThrow ( "Argument '--volumes-from' is not allowed for command 'docker'" )
276+ } )
277+
278+ it ( 'should block --env-file flag' , ( ) => {
279+ expect ( ( ) => {
280+ validateCommandFlags ( 'docker' , [ '--env-file' , '/etc/secrets' ] )
281+ } ) . toThrow ( "Argument '--env-file' is not allowed for command 'docker'" )
282+
283+ expect ( ( ) => {
284+ validateCommandFlags ( 'docker' , [ '--env-file=/etc/secrets' ] )
285+ } ) . toThrow ( "contains flag '--env-file'" )
286+ } )
287+
288+ it ( 'should block build subcommand' , ( ) => {
289+ expect ( ( ) => {
290+ validateCommandFlags ( 'docker' , [ 'build' , 'https://evil.com/' ] )
291+ } ) . toThrow ( "Argument 'build' is not allowed for command 'docker'" )
292+ } )
293+
192294 it ( 'should allow safe docker usage' , ( ) => {
193295 expect ( ( ) => {
194296 validateCommandFlags ( 'docker' , [ 'ps' ] )
@@ -271,6 +373,12 @@ describe('MCP Security Validations', () => {
271373 } ) . toThrow ( 'Argument contains potential local file access' )
272374 } )
273375
376+ it ( 'should block double-slash absolute paths' , ( ) => {
377+ expect ( ( ) => {
378+ validateArgsForLocalFileAccess ( [ '//etc/passwd' ] )
379+ } ) . toThrow ( 'Argument contains potential local file access' )
380+ } )
381+
274382 it ( 'should block path traversal' , ( ) => {
275383 expect ( ( ) => {
276384 validateArgsForLocalFileAccess ( [ '../../../etc/passwd' ] )
0 commit comments