cc-audit 3.2.14

Security auditor for Claude Code skills, hooks, and MCP servers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
//! Input source resolution.

use crate::cli::{CheckArgs, ScanType};
use crate::client::{ClientType, DetectedClient, detect_client, detect_installed_clients};
use std::path::PathBuf;

/// The source of input for scanning.
#[derive(Debug, Clone)]
pub enum InputSource {
    /// Local file or directory paths specified by user.
    LocalPaths(Vec<PathBuf>),
    /// Remote repository URL.
    RemoteUrl {
        url: String,
        git_ref: String,
        auth_token: Option<String>,
    },
    /// List of remote repository URLs from a file.
    RemoteList {
        file: PathBuf,
        git_ref: String,
        auth_token: Option<String>,
    },
    /// All installed AI coding clients.
    AllClients,
    /// A specific AI coding client.
    SpecificClient(ClientType),
    /// Awesome Claude Code repositories.
    AwesomeClaudeCode,
}

impl InputSource {
    /// Determine the input source from CheckArgs.
    pub fn from_check_args(args: &CheckArgs) -> Self {
        if args.all_clients {
            return Self::AllClients;
        }

        if let Some(client) = args.client {
            return Self::SpecificClient(client);
        }

        if let Some(ref url) = args.remote {
            return Self::RemoteUrl {
                url: url.clone(),
                git_ref: args.git_ref.clone(),
                auth_token: args.remote_auth.clone(),
            };
        }

        if let Some(ref file) = args.remote_list {
            return Self::RemoteList {
                file: file.clone(),
                git_ref: args.git_ref.clone(),
                auth_token: args.remote_auth.clone(),
            };
        }

        if args.awesome_claude_code {
            return Self::AwesomeClaudeCode;
        }

        Self::LocalPaths(args.paths.clone())
    }

    /// Check if this is a local source.
    pub fn is_local(&self) -> bool {
        matches!(
            self,
            Self::LocalPaths(_) | Self::AllClients | Self::SpecificClient(_)
        )
    }

    /// Check if this is a remote source.
    pub fn is_remote(&self) -> bool {
        matches!(
            self,
            Self::RemoteUrl { .. } | Self::RemoteList { .. } | Self::AwesomeClaudeCode
        )
    }
}

/// Resolves input sources to concrete scan targets.
pub struct SourceResolver;

impl SourceResolver {
    /// Resolve the input source to a list of paths to scan.
    pub fn resolve(args: &CheckArgs) -> ResolvedInput {
        let source = InputSource::from_check_args(args);

        match source {
            InputSource::LocalPaths(paths) => ResolvedInput {
                paths,
                source: ResolvedSource::Local,
                clients: Vec::new(),
            },
            InputSource::AllClients => {
                let clients = detect_installed_clients();
                let paths: Vec<PathBuf> = clients.iter().flat_map(|c| c.all_configs()).collect();

                ResolvedInput {
                    paths,
                    source: ResolvedSource::Client,
                    clients,
                }
            }
            InputSource::SpecificClient(client_type) => {
                let clients: Vec<DetectedClient> = detect_client(client_type).into_iter().collect();
                let paths: Vec<PathBuf> = clients.iter().flat_map(|c| c.all_configs()).collect();

                ResolvedInput {
                    paths,
                    source: ResolvedSource::Client,
                    clients,
                }
            }
            InputSource::RemoteUrl {
                url,
                git_ref,
                auth_token,
            } => ResolvedInput {
                paths: Vec::new(),
                source: ResolvedSource::Remote {
                    urls: vec![url],
                    git_ref,
                    auth_token,
                },
                clients: Vec::new(),
            },
            InputSource::RemoteList {
                file,
                git_ref,
                auth_token,
            } => {
                // URLs will be loaded from file later
                ResolvedInput {
                    paths: Vec::new(),
                    source: ResolvedSource::Remote {
                        urls: vec![file.to_string_lossy().to_string()],
                        git_ref,
                        auth_token,
                    },
                    clients: Vec::new(),
                }
            }
            InputSource::AwesomeClaudeCode => ResolvedInput {
                paths: Vec::new(),
                source: ResolvedSource::AwesomeClaudeCode,
                clients: Vec::new(),
            },
        }
    }

    /// Get the scan type from CheckArgs.
    pub fn scan_type(args: &CheckArgs) -> ScanType {
        args.scan_type
    }
}

/// The source type after resolution.
#[derive(Debug, Clone)]
pub enum ResolvedSource {
    /// Local file system paths.
    Local,
    /// Client configuration paths.
    Client,
    /// Remote repository URLs.
    Remote {
        urls: Vec<String>,
        git_ref: String,
        auth_token: Option<String>,
    },
    /// Awesome Claude Code repositories.
    AwesomeClaudeCode,
}

/// Resolved input ready for scanning.
#[derive(Debug, Clone)]
pub struct ResolvedInput {
    /// Paths to scan (for local sources).
    pub paths: Vec<PathBuf>,
    /// The resolved source type.
    pub source: ResolvedSource,
    /// Detected clients (if source is Client).
    pub clients: Vec<DetectedClient>,
}

impl ResolvedInput {
    /// Check if there are any paths to scan.
    pub fn has_paths(&self) -> bool {
        !self.paths.is_empty()
    }

    /// Check if this is a remote source requiring clone.
    pub fn requires_clone(&self) -> bool {
        matches!(
            self.source,
            ResolvedSource::Remote { .. } | ResolvedSource::AwesomeClaudeCode
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_input_source_from_local_paths() {
        let args = CheckArgs {
            paths: vec![PathBuf::from("./test")],
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        assert!(matches!(source, InputSource::LocalPaths(_)));
        assert!(source.is_local());
        assert!(!source.is_remote());
    }

    #[test]
    fn test_input_source_all_clients() {
        let args = CheckArgs {
            all_clients: true,
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        assert!(matches!(source, InputSource::AllClients));
        assert!(source.is_local());
    }

    #[test]
    fn test_input_source_specific_client() {
        let args = CheckArgs {
            client: Some(ClientType::Claude),
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        assert!(matches!(
            source,
            InputSource::SpecificClient(ClientType::Claude)
        ));
        assert!(source.is_local());
    }

    #[test]
    fn test_input_source_remote_url() {
        let args = CheckArgs {
            remote: Some("https://github.com/user/repo".to_string()),
            git_ref: "main".to_string(),
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        assert!(matches!(source, InputSource::RemoteUrl { .. }));
        assert!(source.is_remote());
        assert!(!source.is_local());
    }

    #[test]
    fn test_input_source_awesome_claude_code() {
        let args = CheckArgs {
            awesome_claude_code: true,
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        assert!(matches!(source, InputSource::AwesomeClaudeCode));
        assert!(source.is_remote());
    }

    #[test]
    fn test_resolved_input_has_paths() {
        let input = ResolvedInput {
            paths: vec![PathBuf::from("./test")],
            source: ResolvedSource::Local,
            clients: Vec::new(),
        };
        assert!(input.has_paths());
        assert!(!input.requires_clone());

        let empty = ResolvedInput {
            paths: Vec::new(),
            source: ResolvedSource::Local,
            clients: Vec::new(),
        };
        assert!(!empty.has_paths());
    }

    #[test]
    fn test_resolved_input_requires_clone() {
        let remote = ResolvedInput {
            paths: Vec::new(),
            source: ResolvedSource::Remote {
                urls: vec!["https://github.com/user/repo".to_string()],
                git_ref: "main".to_string(),
                auth_token: None,
            },
            clients: Vec::new(),
        };
        assert!(remote.requires_clone());

        let awesome = ResolvedInput {
            paths: Vec::new(),
            source: ResolvedSource::AwesomeClaudeCode,
            clients: Vec::new(),
        };
        assert!(awesome.requires_clone());
    }

    #[test]
    fn test_input_source_remote_list() {
        let args = CheckArgs {
            remote_list: Some(PathBuf::from("repos.txt")),
            git_ref: "main".to_string(),
            remote_auth: Some("token123".to_string()),
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        match &source {
            InputSource::RemoteList {
                file,
                git_ref,
                auth_token,
            } => {
                assert_eq!(*file, PathBuf::from("repos.txt"));
                assert_eq!(*git_ref, "main");
                assert_eq!(*auth_token, Some("token123".to_string()));
            }
            _ => panic!("Expected RemoteList"),
        }
        assert!(source.is_remote());
    }

    #[test]
    fn test_input_source_remote_url_with_auth() {
        let args = CheckArgs {
            remote: Some("https://github.com/user/repo".to_string()),
            git_ref: "develop".to_string(),
            remote_auth: Some("my_token".to_string()),
            ..Default::default()
        };
        let source = InputSource::from_check_args(&args);
        match &source {
            InputSource::RemoteUrl {
                url,
                git_ref,
                auth_token,
            } => {
                assert_eq!(url, "https://github.com/user/repo");
                assert_eq!(git_ref, "develop");
                assert_eq!(*auth_token, Some("my_token".to_string()));
            }
            _ => panic!("Expected RemoteUrl"),
        }
    }

    #[test]
    fn test_source_resolver_resolve_local() {
        let args = CheckArgs {
            paths: vec![PathBuf::from("./src")],
            ..Default::default()
        };
        let resolved = SourceResolver::resolve(&args);
        assert!(matches!(resolved.source, ResolvedSource::Local));
        assert_eq!(resolved.paths, vec![PathBuf::from("./src")]);
        assert!(!resolved.requires_clone());
    }

    #[test]
    fn test_source_resolver_resolve_remote() {
        let args = CheckArgs {
            remote: Some("https://github.com/user/repo".to_string()),
            git_ref: "main".to_string(),
            ..Default::default()
        };
        let resolved = SourceResolver::resolve(&args);
        assert!(matches!(resolved.source, ResolvedSource::Remote { .. }));
        assert!(resolved.requires_clone());
    }

    #[test]
    fn test_source_resolver_resolve_remote_list() {
        let args = CheckArgs {
            remote_list: Some(PathBuf::from("repos.txt")),
            git_ref: "main".to_string(),
            ..Default::default()
        };
        let resolved = SourceResolver::resolve(&args);
        assert!(matches!(resolved.source, ResolvedSource::Remote { .. }));
    }

    #[test]
    fn test_source_resolver_resolve_awesome() {
        let args = CheckArgs {
            awesome_claude_code: true,
            ..Default::default()
        };
        let resolved = SourceResolver::resolve(&args);
        assert!(matches!(resolved.source, ResolvedSource::AwesomeClaudeCode));
        assert!(resolved.requires_clone());
    }

    #[test]
    fn test_source_resolver_scan_type() {
        let args = CheckArgs {
            scan_type: ScanType::Mcp,
            ..Default::default()
        };
        assert_eq!(SourceResolver::scan_type(&args), ScanType::Mcp);
    }

    #[test]
    fn test_resolved_source_debug() {
        let local = ResolvedSource::Local;
        let debug_str = format!("{:?}", local);
        assert!(debug_str.contains("Local"));

        let client = ResolvedSource::Client;
        let debug_str = format!("{:?}", client);
        assert!(debug_str.contains("Client"));

        let awesome = ResolvedSource::AwesomeClaudeCode;
        let debug_str = format!("{:?}", awesome);
        assert!(debug_str.contains("AwesomeClaudeCode"));
    }

    #[test]
    fn test_resolved_input_debug() {
        let input = ResolvedInput {
            paths: vec![PathBuf::from("./test")],
            source: ResolvedSource::Local,
            clients: Vec::new(),
        };
        let debug_str = format!("{:?}", input);
        assert!(debug_str.contains("ResolvedInput"));
    }

    #[test]
    fn test_input_source_debug() {
        let source = InputSource::AllClients;
        let debug_str = format!("{:?}", source);
        assert!(debug_str.contains("AllClients"));
    }

    #[test]
    fn test_resolved_input_client_not_requires_clone() {
        let client = ResolvedInput {
            paths: Vec::new(),
            source: ResolvedSource::Client,
            clients: Vec::new(),
        };
        assert!(!client.requires_clone());
    }
}