Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enrich the details of dsl evaluate errors #1469

Closed
wants to merge 3 commits into from

Conversation

akkuman
Copy link
Contributor

@akkuman akkuman commented Jan 11, 2022

Proposed changes

enrich the details of dsl evaluate errors

see #580

I think it is necessary to expose these errors

the error message can be see in https://github.com/Knetic/govaluate/blob/master/parameters.go#L27

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)

@ehsandeep ehsandeep changed the base branch from master to dev January 11, 2022 07:44
Copy link
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akkuman few fixes and improvements about errors are added in #1372 in the dev branch also please resolve conflict errors and some examples run or example templates?

@akkuman
Copy link
Contributor Author

akkuman commented Jan 11, 2022

@forgedhallpass
Copy link
Contributor

If a target is given, the code will already show the correct DSL method signature (see #1295):

image

This being said, we should probably handle the case when no input is given with -u
image

@Mzack9999
Copy link
Member

I think we should eventually expose the error with gologger and keep a tolerant logic with continue as follows:

compiled, err := govaluate.NewEvaluableExpressionWithFunctions(expr, dsl.HelperFunctions())
if err != nil {
	gologger.Warning().Msgf("%s\n", err)
	continue
}
result, err := compiled.Evaluate(base)
if err != nil {
	gologger.Warning().Msgf("%s\n", err)
	continue
}

The risk with an early return is being not able to use a valid template where the body contains strings matching any helper function and shouldn't be evaluated but sent literally, which is happening now via continue-on-error, for instance with the following template:

id: dsl-test

info:
  name: dsl literal in body
  author: test
  severity: info

requests:
  - raw:
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded

        {{test}} # literal 1
        {{to_lower("a", "b", "c", "d")}} # literal 2

    skip-variables-check: true

@akkuman
Copy link
Contributor Author

akkuman commented Jan 12, 2022

@forgedhallpass there isn't error when the dsl function is in raw request

@akkuman
Copy link
Contributor Author

akkuman commented Jan 12, 2022

@Mzack9999 I think it's good idea. But user cannot catch the error if they want to use nuclei from go code, like https://github.com/projectdiscovery/nuclei/blob/master/DESIGN.md#using-nuclei-from-go-code

hopefully we can find a better way

@forgedhallpass
Copy link
Contributor

@akkuman good point. Will have to extend the tests to cover this scenario as well.

A possible solution could also be to collect and return a slice of errors, and let the client code decide what to do with it.

The logging part will be covered under #1166.

Since we'll soon introduce the REST API, using nuclei as a library will probably not be a priority.

image

when a string identical to the function name appears
@akkuman
Copy link
Contributor Author

akkuman commented Jan 13, 2022

I think we should eventually expose the error with gologger and keep a tolerant logic with continue as follows:

compiled, err := govaluate.NewEvaluableExpressionWithFunctions(expr, dsl.HelperFunctions())
if err != nil {
	gologger.Warning().Msgf("%s\n", err)
	continue
}
result, err := compiled.Evaluate(base)
if err != nil {
	gologger.Warning().Msgf("%s\n", err)
	continue
}

The risk with an early return is being not able to use a valid template where the body contains strings matching any helper function and shouldn't be evaluated but sent literally, which is happening now via continue-on-error, for instance with the following template:

id: dsl-test

info:
  name: dsl literal in body
  author: test
  severity: info

requests:
  - raw:
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded

        {{test}} # literal 1
        {{to_lower("a", "b", "c", "d")}} # literal 2

    skip-variables-check: true

The situation you mentioned can be avoided. I added a test case

@Mzack9999 @forgedhallpass

@akkuman
Copy link
Contributor Author

akkuman commented Jan 13, 2022

@forgedhallpass My solution does look ugly

A possible solution could also be to collect and return a slice of errors, and let the client code decide what to do with it.

if implement it, there will be a lot of code changes involved, I'm not sure it's worth it.

@akkuman
Copy link
Contributor Author

akkuman commented Jan 13, 2022

But my solution doesn't cover every wrong situation

@Mzack9999 Mzack9999 added the Status: On Hold Similar to blocked, but is assigned to someone label Jan 20, 2022
@Mzack9999
Copy link
Member

On hold - Expression lexer is being reworked in #1516

@Mzack9999 Mzack9999 added the Type: Maintenance Updating phrasing or wording to make things clearer or removing ambiguity. label Jan 20, 2022
@Mzack9999
Copy link
Member

Closing - The PR seems not actual with actual core changes (lexer + dsl)

@Mzack9999 Mzack9999 closed this Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: On Hold Similar to blocked, but is assigned to someone Type: Maintenance Updating phrasing or wording to make things clearer or removing ambiguity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants