nuclei icon indicating copy to clipboard operation
nuclei copied to clipboard

[BUG] Configuring a custom template path in the sdk

Open Legion-101 opened this issue 8 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Current Behavior

When I install my own directory on the local location of the nuclei templates in sdk

	ne, err := nuclei.NewNucleiEngineCtx(
		ctx,
		nuclei.WithTemplateFilters(nuclei.TemplateFilters{
			Tags:     params.Filter.Tags,
			Severity: params.Filter.Severity,
			IDs:      params.Filter.TemplateIDs,
		}),
		nuclei.WithCatalog(disk.NewCatalog(absPath)),
		nuclei.DisableUpdateCheck(),
	)
	if err != nil {
		return fmt.Errorf("failed to create nuclei engine: %w", err)
	}

loader.New loads the included and excluded templates slice by slice, which are nil by default, so loader.New loads templates only from the default directory.

	store := &Store{
		id:        cfg.StoreId,
		config:    cfg,
		tagFilter: tagFilter,
		pathFilter: filter.NewPathFilter(&filter.PathFilterConfig{
			IncludedTemplates: cfg.IncludeTemplates,
			ExcludedTemplates: cfg.ExcludeTemplates,
		}, cfg.Catalog),
		finalTemplates: cfg.Templates,
		finalWorkflows: cfg.Workflows,
	}

Expected Behavior

It was expected to download templates from the catalog installed for the nuclei engine using the command:

nuclei.WithCatalog(disk.NewCatalog(absPath)),

Steps To Reproduce

absPath, err := filepath.Abs(n.pathToTemplates)
	if err != nil {
		return fmt.Errorf("get absolute path: %w", err)
	}

	n.logger.Debug("abs path to templates", slog.String("path", absPath))

	ne, err := nuclei.NewNucleiEngineCtx(
		ctx,
		nuclei.WithTemplateFilters(nuclei.TemplateFilters{
			Tags:     params.Filter.Tags,
			Severity: params.Filter.Severity,
			IDs:      params.Filter.TemplateIDs,
		}),
		nuclei.WithCatalog(disk.NewCatalog(absPath)),
		nuclei.DisableUpdateCheck(),
	)
	if err != nil {
		return fmt.Errorf("failed to create nuclei engine: %w", err)
	}

	if err := ne.LoadAllTemplates(); err != nil {
		return fmt.Errorf("failed load templates: %w", err)
	}

Relevant log output


Environment

- OS: Debian 12 (WSL)
- Nuclei: 3.4.0
- Go: go1.24.2

Anything else?

No response

Legion-101 avatar Apr 28 '25 23:04 Legion-101

For the time being you need to set the custom directory in the default config:

config.DefaultConfig.TemplatesDirectory = "/path/to/templates"

This is going to be reworked in https://github.com/projectdiscovery/nuclei/issues/5239 - keep an eye on the issue. Thanks!

Mzack9999 avatar May 01 '25 21:05 Mzack9999

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Aug 03 '25 00:08 github-actions[bot]

This issue has been automatically closed due to inactivity. If you think this is a mistake or would like to continue the discussion, please comment or feel free to reopen it.

github-actions[bot] avatar Aug 10 '25 00:08 github-actions[bot]