JS-X-Ray is a sophisticated JavaScript AST (Abstract Syntax Tree) analysis tool designed for security research and code vulnerability detection. This document provides AI agents with the essential information to effectively work with and contribute to this project.
- Main Package:
@nodesecure/js-x-ray- Primary analysis engine - Supporting Workspaces:
@nodesecure/js-x-ray-ai- AI-powered analysis capabilities
AstAnalyser.ts- Main analysis class for JavaScript security scanningEntryFilesAnalyser.ts- Multi-file project analysisProbeRunner.ts- Security probe execution engineSourceFile.ts- Source code file representationwarnings.ts- Security warning type definitions
Critical:
obfuscated-code- Code obfuscation detectionsuspicious-file- Excessive encoded literals
Warning Level:
unsafe-import- Untraceable require/import statementsunsafe-regex- ReDoS attack patternsunsafe-stmt- Dangerous statements (eval, Function constructor)weak-crypto- Weak cryptographic algorithms (MD5, SHA1)shady-link- Suspicious URLs/linksdata-exfiltration- Potential data theft patterns
Information Level:
parsing-error- AST parsing failuresencoded-literal- Hex/base64/Unicode encoded contentsynchronous-io- Sync I/O operations
# Build all workspaces
npm run build
# Run tests with coverage
npm run test
# Lint code across all workspaces
npm run lint
# Development mode (watch + test)
npm run dev- Uses Node.js native test runner
- Coverage with c8
- 100+ test files with real-world malware examples
- Test fixtures in
test/fixtures/directory
- Source Parsing: JavaScript/TypeScript → AST using Meriyah parser
- Probe Execution: Security probes analyze AST nodes
- Pattern Matching: Detect obfuscation, encoded literals, unsafe patterns
- Dependency Tracking: Trace require/import statements
- Warning Generation: Produce structured security warnings
- Report Generation: Comprehensive security analysis results
- Language: TypeScript (ESM modules)
- AST Parser: Meriyah (JavaScript/TypeScript parser)
- Build System: TypeScript compiler with project references
- Testing: Node.js native test runner with c8 coverage
- Linting: ESLint with TypeScript support
- Package Management: npm workspaces with changesets for versioning
workspaces/js-x-ray/
├── src/ # Main source code
│ ├── analysis/ # Analysis engine components
│ ├── probes/ # Security probe implementations
│ └── warnings/ # Warning type definitions
├── test/ # Test suite
│ ├── fixtures/ # Real-world malware examples
│ └── unit/ # Unit tests
├── docs/ # API documentation
└── examples/ # Usage examples
This project is specifically designed for:
- Malicious JavaScript detection
- Supply chain security analysis
- Code obfuscation identification
- Vulnerability pattern recognition
- Security research and education
- Probe System: Custom security probes can be added to
src/probes/ - Pipeline Architecture: Modular analysis pipeline allows for custom processing stages
- Warning Types: New warning categories can be defined in
src/warnings/
- The project contains real malicious code samples for testing
- Always handle test fixtures with appropriate security precautions
- Use the provided test environment for safe code analysis
- TypeScript with strict type checking
- ESM module structure
- Comprehensive test coverage required
- Security-focused code review process
import { AstAnalyser } from "@nodesecure/js-x-ray";
const analyser = new AstAnalyser();
const results = await analyser.analyse(sourceCode);import { EntryFilesAnalyser } from "@nodesecure/js-x-ray";
const analyser = new EntryFilesAnalyser();
const results = await analyser.analyse(filePaths);- Create probe class in
src/probes/ - Implement required probe interface
- Add tests in
test/unit/probes/ - Update documentation
- Define warning type in
src/warnings/ - Add detection logic
- Create test cases
- Update warning documentation
- API Documentation:
docs/api/ - Warning Documentation: Root
docs/directory - Real-world Examples:
examples/directory - Test Fixtures:
test/fixtures/(malicious code samples)
- This tool analyzes potentially malicious code
- Always use in isolated environments
- Follow security research best practices
- Report vulnerabilities responsibly
- Uses changesets for versioning
- Automated publishing workflow
- Semantic versioning across workspaces
- Backward compatibility maintained