Proposed changes

This PR replaces the BishopFox jsluice dependency with a pure-Go implementation to eliminate CGO requirements and enable cross-platform compilation.

Problem

The BishopFox jsluice library requires CGO, which:

  • Prevents builds on Windows/386 platforms (see deleted parser_nojs.go build constraints)
  • Complicates cross-compilation and deployment
  • Adds external C dependencies to the build chain

Solution

Implemented a pure-Go JavaScript endpoint extraction engine using:

  • dop251/goja parser for JavaScript AST analysis
  • ES6 module preprocessing to handle import/export statements
  • Dual extraction strategy: combines AST-based string literal extraction with regex patterns
  • Smart deduplication via shared state across extraction methods

Key Changes

1. Pure-Go JavaScript Parsing (pkg/utils/jsluice.go)

  • Replaces CGO-dependent jsluice with native Go implementation
  • Handles ES6 modules by preprocessing to remove import/export syntax
  • Falls back to regex extraction for malformed JavaScript
  • Extracts URLs from comments and non-standard contexts that pure parsing would miss

2. Platform Support Improvements

  • Removed //go:build constraints from pkg/engine/parser/parser_generic.go
  • Deleted pkg/engine/parser/parser_nojs.go (Windows/386 fallback no longer needed)
  • JSLuice functionality now available on all platforms including Windows/386

3. Dependency Changes (go.mod)

  • ❌ Removed: github.com/BishopFox/jsluice (requires CGO)
  • ❌ Removed: github.com/ditashi/jsbeautifier-go (transitive dependency)
  • ❌ Removed: github.com/smacker/go-tree-sitter (transitive dependency)
  • ✅ Added: github.com/dop251/goja (pure-Go JavaScript engine)

Proof

Test Coverage

Added comprehensive test suite (pkg/utils/jsluice_test.go):

  • ✅ ES6 modules with import/export statements
  • ✅ Template literals (backticks)
  • ✅ Mixed valid/invalid JavaScript
  • ✅ Regex-only extraction fallback
  • ✅ URL extraction from comments
  • ✅ Duplicate prevention across extraction methods

Test Results:

$ go test ./pkg/utils/... -v
=== RUN TestExtractJsluiceEndpoints
=== RUN TestExtractJsluiceEndpoints/ES_module_with_import
=== RUN TestExtractJsluiceEndpoints/ES_module_with_export_default
=== RUN TestExtractJsluiceEndpoints/regex-only_matches_in_invalid_JS
--- PASS: TestExtractJsluiceEndpoints (0.01s)
=== RUN TestPreprocessModuleCode
--- PASS: TestPreprocessModuleCode (0.00s)
PASS
ok github.com/projectdiscovery/katana/pkg/utils 0.029s

Build Verification

$ go build ./...
# Successfully builds on all platforms (no CGO required)

Example Usage

// Handles ES6 modules that previously caused parse failures
jsCode := `import React from 'react';
const API_URL = "https://api.example.com/data";
export default function App() {
fetch(API_URL);
}`
endpoints := ExtractJsluiceEndpoints(jsCode)
// Returns: [{"https://api.example.com/data", "url"}]

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Issue/claim

Resolves #1367 /claim #1367

Claim

Total prize pool $400
Total paid $0
Status Pending
Submitted February 02, 2026
Last updated February 02, 2026

Contributors

AK

Akinniranye Samuel Tomiwa

@samuel-asleep

100%

Sponsors

PR

ProjectDiscovery

@projectdiscovery

$200
HE

Hermes1118

@dalledajay-gmail-com

$200