Analyze source map for secrets and information
(
map_url: &str,
source_map: &SourceMap,
client: &Client,
validate_tokens: bool,
)
| 711 | |
| 712 | /// Analyze source map for secrets and information |
| 713 | pub async fn analyze_source_map( |
| 714 | map_url: &str, |
| 715 | source_map: &SourceMap, |
| 716 | client: &Client, |
| 717 | validate_tokens: bool, |
| 718 | ) -> SourceMapInfo { |
| 719 | let mut info = SourceMapInfo { |
| 720 | map_url: map_url.to_string(), |
| 721 | original_files: source_map.sources.clone(), |
| 722 | secrets: Vec::new(), |
| 723 | endpoints: Vec::new(), |
| 724 | comments: Vec::new(), |
| 725 | file_paths: Vec::new(), |
| 726 | }; |
| 727 | |
| 728 | // Extract file paths - these reveal directory structure |
| 729 | for source in &source_map.sources { |
| 730 | if !source.is_empty() { |
| 731 | info.file_paths.push(source.clone()); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | // Analyze sourcesContent if available |
| 736 | if let Some(ref sources_content) = source_map.sources_content { |
| 737 | for (idx, content) in sources_content.iter().enumerate() { |
| 738 | if content.is_empty() { |
| 739 | continue; |
| 740 | } |
| 741 | |
| 742 | let source_name = source_map.sources.get(idx) |
| 743 | .map(|s| s.as_str()) |
| 744 | .unwrap_or("unknown"); |
| 745 | |
| 746 | // Scan for secrets in original source (using comprehensive scan) |
| 747 | // Pass the source map URL as the main URL for reference |
| 748 | let mut secrets = scan_for_all_hardcoded_secrets( |
| 749 | content, |
| 750 | map_url, // Keep the actual source map URL for direct access |
| 751 | client, |
| 752 | validate_tokens |
| 753 | ).await; |
| 754 | |
| 755 | // Add source file context to each secret found in this source |
| 756 | for secret in &mut secrets { |
| 757 | secret.context = format!("[Source: {}] {}", source_name, secret.context); |
| 758 | } |
| 759 | |
| 760 | info.secrets.append(&mut secrets); |
| 761 | |
| 762 | // Extract endpoints from original source |
| 763 | let mut endpoints = extract_api_endpoints( |
| 764 | content, |
| 765 | &format!("{} ({})", map_url, source_name) |
| 766 | ); |
| 767 | info.endpoints.append(&mut endpoints); |
| 768 | |
| 769 | // Extract comments (they often contain TODO, DEBUG, credentials info) |
| 770 | let comments = extract_code_comments(content); |
no test coverage detected