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

fix: types.RequestResponse url field UnmarshalJSON bug #5267

Merged
merged 3 commits into from
Jun 15, 2024

Conversation

LazyMaple
Copy link
Contributor

Proposed changes

In Go, when you use map[string]json.RawMessage to parse JSON data, the fields retain their original JSON-encoded format. json.RawMessage is essentially a []byte that contains the raw encoded JSON data. This means that if the JSON field is a string, it will include the quotation marks (").
Here’s a quick example to illustrate the situation:

package main

import (
    "encoding/json"
    "fmt"
)

func main() {
    data := `{"url": "testphp.vulnweb.com"}`

    var m map[string]json.RawMessage
    err := json.Unmarshal([]byte(data), &m)
    if err != nil {
        fmt.Println(err)
        return
    }

    // Printing the raw message byte array
    fmt.Printf("RawMessage in bytes: %v\n", m["url"])

    // Decode the "url" field
    var url string
    err = json.Unmarshal(m["url"], &url)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Printf("Original RawMessage: %s\n", string(m["url"]))
    fmt.Printf("Parsed URL: %s\n", url)
}

When you run this program, the output will be:

RawMessage in bytes: [34 116 101 115 116 112 104 112 46 118 117 108 110 119 101 98 46 99 111 109 34]
Original RawMessage: "testphp.vulnweb.com"
Parsed URL: testphp.vulnweb.com

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)

@GeorginaReeder
Copy link

Thanks for your contribution @LazyMaple , we appreciate it!

We also have a Discord server, which you’re more than welcome to join. It's a great place to connect with fellow contributors and stay updated with the latest developments!

pkg/input/types/http_test.go Outdated Show resolved Hide resolved
Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

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

lgtm !

@ehsandeep ehsandeep merged commit 4720d8c into projectdiscovery:dev Jun 15, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants