I've no idea why the VerifyIDToken on Go SDK got panicked. I've used VerifyIDToken on the handler of gin as follows:
r.GET("/idToken/:id", func(c *gin.Context) {
// idToken := c.Param("id")
opt := option.WithCredentialsFile("xxx-secret.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
fmt.Println(fmt.Errorf("error initializing app: %v", err))
}
client, err := app.Auth(context.Background())
if err != nil {
fmt.Println("error getting Auth client: %v\n", err)
fmt.Println(client)
}
idToken := c.Param("id")
fmt.Println("idTaken = ", idToken)
token, err := client.VerifyIDToken(context.Background(), idToken)
if err != nil {
fmt.Println("error verifying ID token: %v\n", err)
}
fmt.Println("Verified ID token: %v\n", token)
})
I've called above API as follows:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
user.getIdToken(/* forceRefresh */ true).then(function(idToken) {
// Send token to your backend via HTTPS
// ...
axios
.get('https://xx.xxx.com/idToken/' + idToken)
.then(response => {
this.response = response;
console.log(response);
if (response.data.update == "ok") {
this.acceptOKresponse = true;
}
})
}).catch(function(error) {
// Handle error
});
Then, Followings appeared on the server console:
idTaken = eyJhbGciOiJSUzI1NiIsImtpZCI6IjBlYTNmN2EwMjQ4YmU0ZTBkZjAyYWVlZWIyMGIxZDJlMmI3ZjI0NzQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5LiK55Sw5YGl5LmLIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL21hZ2ljbGFiZWwtYjQ0NjkiLCJhdWQiOiJtYWdpY2xhYmVsLWI0NDY5IiwiYXV0aF90aW1lIjoxNTgzMTE2MjQwLCJ1c2VyX2lkIjoiS0V5b3dYZnd4NFNqbEMwakdsTnVzcDU0c0xQMiIsInN1YiI6IktFeW93WGZ3eDRTamxDMGpHbE51c3A1NHNMUDIiLCJpYXQiOjE1ODMxMjM3NTcsImV4cCI6MTU4MzEyNzM1NywiZW1haWwiOiJnZGUwMDEwN0BuaWZ0eS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJnZGUwMDEwN0BuaWZ0eS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.ABnMA6iOITghzo_WzgdDwssODiLsswVSlKod6w5CHcnkJOQVKqQIynZufTQvcF8nQO77MYXikZD8TQE_uGq3EpHWQibun67mvN74GnPaguzgvpjQ-PqIOzuhnn2n2SpHSacdREtFkwtj1S66bhigbuTJbqr8jQtIEIB6gfmnObwcmpNRsc-GGR45xjWAO6UY4Ygw4xDcHsHGXwL6SA-HbDuSZGeQfXtdPt94taJfrQQB9nr_7gRjttQLz4ongh-g-fMSpWx3z8lmQgPwgg4GyChYPZ6_hdEV3AWFJTHptE2X8RCV6HfpZB6EGwvLQr6ZrC01uodGTg87BvtPrersjA
2020/03/02 13:35:58 [Recovery] 2020/03/02 - 13:35:58 panic recovered:
GET /idToken/eyJhbGciOiJSUzI1NiIsImtpZCI6IjBlYTNmN2EwMjQ4YmU0ZTBkZjAyYWVlZWIyMGIxZDJlMmI3ZjI0NzQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5LiK55Sw5YGl5LmLIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL21hZ2ljbGFiZWwtYjQ0NjkiLCJhdWQiOiJtYWdpY2xhYmVsLWI0NDY5IiwiYXV0aF90aW1lIjoxNTgzMTE2MjQwLCJ1c2VyX2lkIjoiS0V5b3dYZnd4NFNqbEMwakdsTnVzcDU0c0xQMiIsInN1YiI6IktFeW93WGZ3eDRTamxDMGpHbE51c3A1NHNMUDIiLCJpYXQiOjE1ODMxMjM3NTcsImV4cCI6MTU4MzEyNzM1NywiZW1haWwiOiJnZGUwMDEwN0BuaWZ0eS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJnZGUwMDEwN0BuaWZ0eS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.ABnMA6iOITghzo_WzgdDwssODiLsswVSlKod6w5CHcnkJOQVKqQIynZufTQvcF8nQO77MYXikZD8TQE_uGq3EpHWQibun67mvN74GnPaguzgvpjQ-PqIOzuhnn2n2SpHSacdREtFkwtj1S66bhigbuTJbqr8jQtIEIB6gfmnObwcmpNRsc-GGR45xjWAO6UY4Ygw4xDcHsHGXwL6SA-HbDuSZGeQfXtdPt94taJfrQQB9nr_7gRjttQLz4ongh-g-fMSpWx3z8lmQgPwgg4GyChYPZ6_hdEV3AWFJTHptE2X8RCV6HfpZB6EGwvLQr6ZrC01uodGTg87BvtPrersjA HTTP/1.1
Host: ml.uedasoft.com
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: ja,en;q=0.9,fr;q=0.8,en-US;q=0.7
Connection: Keep-Alive
Origin: http://localhost:8080
Referer: http://localhost:8080/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36
X-Forwarded-For: 125.172.88.148
X-Forwarded-Host: ml.uedasoft.com
X-Forwarded-Server: ml.uedasoft.com
runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:199 (0x5595f)
panicmem: panic(memoryError)
/usr/local/go/src/runtime/signal_unix.go:394 (0x55838)
sigpanic: panicmem()
/usr/local/go/src/runtime/internal/atomic/atomic_arm.go:103 (0x126db)
goXadd64: *(*int)(nil) = 0 // crash on unaligned uint64
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:483 (0x50b937)
(*defaultIDGenerator).NewSpanID: id = atomic.AddUint64(&gen.nextSpanID, gen.spanIDInc)
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:196 (0x50a26f)
startSpanInternal: span.spanContext.SpanID = cfg.IDGenerator.NewSpanID()
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:162 (0x50a117)
StartSpan: span := startSpanInternal(name, parent != SpanContext{}, parent, false, opts)
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/trace.go:58 (0x51713b)
(*traceTransport).RoundTrip: ctx, span := trace.StartSpan(req.Context(), name,
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/client_stats.go:54 (0x516b1b)
statsTransport.RoundTrip: resp, err := t.base.RoundTrip(req)
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/client.go:89 (0x5165c7)
(*Transport).RoundTrip: return rt.RoundTrip(req)
/usr/local/go/src/net/http/client.go:250 (0x25ec27)
send: resp, err = rt.RoundTrip(req)
/usr/local/go/src/net/http/client.go:174 (0x25e6ef)
(*Client).send: resp, didTimeout, err = send(req, c.transport(), deadline)
/usr/local/go/src/net/http/client.go:641 (0x25fb17)
(*Client).do: if resp, didTimeout, err = c.send(req, deadline); err != nil {
/usr/local/go/src/net/http/client.go:509 (0x4f9def)
(*Client).Do: return c.do(req)
/home/ueda/.go/src/golang.org/x/net/context/ctxhttp/ctxhttp.go:30 (0x4f9d60)
Do: resp, err := client.Do(req.WithContext(ctx))
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:92 (0x59750b)
(*httpKeySource).refreshKeys: resp, err := ctxhttp.Do(ctx, k.HTTPClient, req)
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:72 (0x59733b)
(*httpKeySource).Keys: err := k.refreshKeys(ctx)
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:129 (0x5979e3)
verifyToken: keys, err := ks.Keys(ctx)
/home/ueda/.go/src/firebase.google.com/go/auth/auth.go:223 (0x59529f)
(*Client).VerifyIDToken: if err := verifyToken(ctx, idToken, c.keySource); err != nil {
/home/ueda/ml/main.go:97 (0x5fdc33)
main.func5: token, err := client.VerifyIDToken(context.Background(), idToken)
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/recovery.go:83 (0x497efb)
RecoveryWithWriter.func1: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/logger.go:241 (0x497347)
LoggerWithConfig.func1: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/gin.go:412 (0x48f8bf)
(*Engine).handleHTTPRequest: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/gin.go:370 (0x48f19f)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2802 (0x2a2c7f)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1890 (0x29f12f)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_arm.s:868 (0x6c86f)
goexit: MOVW R0, R0 // NOP
[GIN] 2020/03/02 - 13:35:58 | 500 | 13.345389ms | 125.172.88.148 | GET /idToken/eyJhbGciOiJSUzI1NiIsImtpZCI6IjBlYTNmN2EwMjQ4YmU0ZTBkZjAyYWVlZWIyMGIxZDJlMmI3ZjI0NzQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5LiK55Sw5YGl5LmLIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL21hZ2ljbGFiZWwtYjQ0NjkiLCJhdWQiOiJtYWdpY2xhYmVsLWI0NDY5IiwiYXV0aF90aW1lIjoxNTgzMTE2MjQwLCJ1c2VyX2lkIjoiS0V5b3dYZnd4NFNqbEMwakdsTnVzcDU0c0xQMiIsInN1YiI6IktFeW93WGZ3eDRTamxDMGpHbE51c3A1NHNMUDIiLCJpYXQiOjE1ODMxMjM3NTcsImV4cCI6MTU4MzEyNzM1NywiZW1haWwiOiJnZGUwMDEwN0BuaWZ0eS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJnZGUwMDEwN0BuaWZ0eS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.ABnMA6iOITghzo_WzgdDwssODiLsswVSlKod6w5CHcnkJOQVKqQIynZufTQvcF8nQO77MYXikZD8TQE_uGq3EpHWQibun67mvN74GnPaguzgvpjQ-PqIOzuhnn2n2SpHSacdREtFkwtj1S66bhigbuTJbqr8jQtIEIB6gfmnObwcmpNRsc-GGR45xjWAO6UY4Ygw4xDcHsHGXwL6SA-HbDuSZGeQfXtdPt94taJfrQQB9nr_7gRjttQLz4ongh-g-fMSpWx3z8lmQgPwgg4GyChYPZ6_hdEV3AWFJTHptE2X8RCV6HfpZB6EGwvLQr6ZrC01uodGTg87BvtPrersjA
I've completely no idea of the cause of this panic. Any suggestions are so welcome! Thank you for your suggestions.
As commented by mkopriva, root cause was a reported issue. It's fixed by updating dependencies as follows:
go get -u all
Thank you, mkopriva!
Related
I'm starting to work with fasthttp in Golang and I can't figure out how to send key:value format. In default net/http I did it via url.values. I would appreciate it if you could help me with some sample code!
Image from Burp Suite (How it must look like)
var client *fasthttp.Client
var headerContentTypeJson = []byte("application/json")
type loginData struct {
login string
pass string
}
func main() {
readTimeout, _ := time.ParseDuration("500ms")
writeTimeout, _ := time.ParseDuration("500ms")
maxIdleConnDuration, _ := time.ParseDuration("1h")
client = &fasthttp.Client{
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
MaxIdleConnDuration: maxIdleConnDuration,
NoDefaultUserAgentHeader: true, //
DisableHeaderNamesNormalizing: true, //
DisablePathNormalizing: true,
Dial: (&fasthttp.TCPDialer{
Concurrency: 4096,
DNSCacheDuration: time.Hour,
}).Dial,
}
reqTimeout := time.Duration(100) * time.Millisecond
reqData := &loginData{
login: "login",
pass: "password",
}
reqDataByte, _ := json.Marshal(reqData)
req := fasthttp.AcquireRequest()
req.SetRequestURI("https://oskelly.ru/api/v2/account/rawauth")
req.Header.SetMethod(fasthttp.MethodPost)
req.Header.SetContentTypeBytes(headerContentTypeJson)
req.SetBodyRaw(reqDataByte)
resp := fasthttp.AcquireResponse()
err := client.DoTimeout(req, resp, reqTimeout)
fasthttp.ReleaseRequest(req)
if err == nil {
statusCode := resp.StatusCode()
respBody := resp.Body()
fmt.Printf("DEEBUG Response: %s\n", respBody)
if statusCode == http.StatusOK {
respData := &loginData{}
err := json.Unmarshal(respBody, respData)
if err == io.EOF || err == nil {
fmt.Printf("DEBUG Parsed data Response %v\n")
} else {
fmt.Printf("ERR invalid HTTP response code: %d\n", statusCode)
}
}
fasthttp.ReleaseResponse(resp)
}}
enter image description here
Tried to figure out how to integrate url.values into fasthttp
For request Body parameters:
req.Header.SetContentType("application/x-www-form-urlencoded; charset=UTF-8")
Form the request body in key=val string and not json. Can do a simple Stringer impl or req.PostArgs().Add(key, val)
req.PostArgs().Add("login", reqData.Login)
req.PostArgs().Add("pass", reqData.Pass)
Output request
POST / HTTP/1.1
Host: ....
Content-Length: 25
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
login=login&pass=password
I am trying to write a simple Unix domain socket based http server in golang. Here is the code:
package main
import (
"fmt"
"log"
"net/http"
"net"
"os"
"encoding/json"
"os/signal"
"syscall"
)
type UnixListener struct {
ServerMux *http.ServeMux
SocketPath string
UID int
GID int
SocketFileMode os.FileMode
}
//////////////////////////////////////////////////////////////////////
// Start the HTTP server with UNIX socket.
//////////////////////////////////////////////////////////////////////
func (l *UnixListener) Start() error {
listener, err := net.Listen("unix", l.SocketPath)
if err != nil {
return err
}
if err := os.Chown(l.SocketPath, l.UID, l.GID); err != nil {
return err
}
if err := os.Chmod(l.SocketPath, l.SocketFileMode); err != nil {
return err
}
go func(){
shutdown(listener)
}()
svr := http.Server{
Handler: l.ServerMux,
}
if err := svr.Serve(listener); err != nil {
return err
} else {
return nil
}
}
//////////////////////////////////////////////////////////////////////
// Shutdown the HTTP server.
//////////////////////////////////////////////////////////////////////
func shutdown(listener net.Listener) {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
s := <-c
listener.Close()
log.Fatalf("[FATAL] Caught a signal. sinal=%s", s)
}
func hello(w http.ResponseWriter, r *http.Request) {
log.Println("Received request %s", r.RequestURI)
fmt.Fprintf(w, "Hello World!\n")
w.Header().Set("ContentType", "application/json")
w.WriteHeader(http.StatusOK)
data := map[string]string { "name" : "satish"}
resp, _ := json.Marshal(data)
if _, err := w.Write(resp); err != nil {
fmt.Printf("Error writing response")
}
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/hello", hello)
unixListener := UnixListener{
ServerMux: mux,
SocketPath: "/temp/test.sock",
UID: 501,
GID: 20,
SocketFileMode: 0644,
}
if err := unixListener.Start(); err != nil {
log.Fatalf("[FATAL] HTTP server error: %s", err)
}
}
But when I send the request to this UDS based server like below, the handler does not seem to be invoked, giving 404 not found error. What is the right way to implement UDS based http server and how to send the http request to it?
curl -vvv --unix-socket /temp/test.sock http:/hello
* Trying /Users/sburnwal/Projects/ACI/temp/test.sock:0...
* Connected to hello (/temp/test.sock) port 80 (#0)
> GET / HTTP/1.1
> Host: hello
> User-Agent: curl/7.84.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Mon, 14 Nov 2022 02:38:11 GMT
< Content-Length: 19
<
404 page not found
* Connection #0 to host hello left intact
It appears it's interpreting http:/hello in your command line as the host name and using that for the header. And then requesting / as the path
Try replacing http:/hello in your command line with http://hello/hello. I'm not sure if the single slash vs double-slash is significant. It just looks suspicious.
curl -vvv --unix-socket /temp/test.sock http://hello/hello
Or change your Go code to have a response handler for "/" instead of just for "/hello"
mux.HandleFunc("/hello", hello)
mux.HandleFunc("/", hello)
I'm trying to send a request using a Hello Chrome fingerprint by using the uTLS library, but after looking through the docs I'm struggling to figure out how to utilise the uTLS connection when sending a request.
I've got both parts of the code below, but not sure how to put them together, or if I'm even doing it the correct way.
package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/cookiejar"
tls "github.com/refraction-networking/utls"
)
func main() {
tcpConn, err := net.Dial("tcp", "151.101.65.69:443")
if err != nil {
fmt.Printf("net.Dial() failed: %+v\n", err)
return
}
config := tls.Config{ServerName: "www.stackoverflow.com"}
tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_Auto)
defer tlsConn.Close()
err = tlsConn.Handshake()
if err != nil {
fmt.Printf("uTlsConn.Handshake() error: %+v", err)
} else {
fmt.Println("Handshake met")
}
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{
Jar: cookieJar,
Transport: &http.Transport{},
}
req, err := http.NewRequest("GET", "https://ja3er.com/json", nil)
req.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(resp.StatusCode)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
}
Simply move your code into Transport.DialTLSContext:
DialTLSContext specifies an optional dial function for creating
TLS connections for non-proxied HTTPS requests.
[...]
The returned net.Conn is assumed to already be
past the TLS handshake.
client := &http.Client{
Jar: cookieJar,
Transport: &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
// Note that hardcoding the address is not necessary here. Only
// do that if you want to ignore the DNS lookup that already
// happened behind the scenes.
tcpConn, err := (&net.Dialer{}).DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
config := tls.Config{ServerName: "www.stackoverflow.com"}
tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_Auto)
err = tlsConn.Handshake()
if err != nil {
return nil, fmt.Errorf("uTlsConn.Handshake() error: %w", err)
}
return tlsConn, nil
},
},
}
When I use http://localhost:8080/login?id=ddfd#vcv.com&pwd=dccccf in postman or use it in android app I am getting 404. On curl I get
{"name":"Miss Moneypenny","email":"ddfd#vcv.com","password":"dccccf","mobile":27,"address":"dscsdacc"}
I am not able to understand what can I do to achieve json output in postman and on other platforms like Apps in ios as well as android when I use this api and also on the browser window.
My Main.go code
func getSession() *mgo.Session {
s, err := mgo.Dial("mongodb://localhost")
if err != nil {
panic(err)
}
return s
}
func main() {
r := httprouter.New()
uc := controllers.NewUserController(getSession())
r.GET("/login", uc.LoginUser)
http.ListenAndServe(":8080", r)
}
code in controller/user.go
type UserController struct {
session *mgo.Session
}
func NewUserController(s *mgo.Session) *UserController {
return &UserController{s}
}
func (uc UserController) LoginUser(w http.ResponseWriter, request *http.Request, params httprouter.Params) {
dump,err :=httputil.DumpRequest(request, true)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
return
}
fmt.Println("Request Dump:\n", string(dump))
encodedValue := request.URL.Query().Get("id")
pwd := request.URL.Query().Get("pwd")
emailId, err := url.QueryUnescape(encodedValue)
if err != nil {
log.Fatal(err)
return
}
u := models.User{}
if err := uc.session.DB("go-web-dev-db").C("users").FindId(emailId + pwd).One(&u); err != nil {
w.WriteHeader(404)
return
}
uj, err := json.Marshal(u)
if err != nil {
fmt.Println(err)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) // 200
fmt.Fprintf(w, "%s\n", uj)
}
code in model/user.go
type User struct {
Name string `json:"name" bson:"name"`
Email string `json:"email" bson:"_id"`
Password string `json:"password" bson:"password"`
Mobile int `json:"mobile" bson:"mobile"`
Address string `json:"address" bson:"address"`
}
After using dump when I am using i am using curl 'http://localhost:8080/login?id=ddfd#vcv.com&pwd=dccccf' I get :-
Request Dump:
GET /login?id=ddfd#vcv.com&pwd=dccccf HTTP/1.1
Host: localhost:8080
Accept: */*
User-Agent: curl/7.69.1
After using dump when I am using i am using http://localhost:8080/login?id=ddfd#vcv.com&pwd=dccccf in postman I get :-
Request Dump:
GET /login?id=ddfd#vcv.com&pwd=dccccf HTTP/1.1
Host: localhost:8080
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Postman-Token: 8e925738-b8db-4656-9f53-813f4cd53a80
User-Agent: PostmanRuntime/7.24.1
I try to parse a page with this code :
client := &http.Client{}
profile := getEpiURL(login)
log.Print("Fetch " + profile)
req, err := http.NewRequest("GET", profile, nil)
if err != nil {
log.Fatal(err)
}
req.AddCookie(cookieSessionIntra)
body, _ := httputil.DumpRequestOut(req, true)
With this as getEpiURL function :
func getEpiURL(login string) (url string) {
url = "https://********/user/" + login + "/?format=json"
return
}
And when i look at the output the profile variable is good, but in the Request it seems obviously wrong...
2016/11/24 12:53:53 Fetch https://********/user/le****in-vi**rd#e*******/?format=json
Then the debug for the request prints me :
GET /user/%00l%*****0o%*00.%00c***0-%00v%00i%0*a%00r%00d%00#%00e%00i%00t%00e%00c%0***0.%0***00/?format=json
HTTP/1.1 Host: ****** User-Agent: Go-http-client/1.1 Cookie:
PHPSESSID=********* Accept-Encoding: gzip
I think your original string somehow contains NUL characters. Try this out in the playground:
func main() {
req, err := http.NewRequest("GET", "https://some/normal/path", nil)
if err != nil {
log.Fatal(err)
}
body, _ := httputil.DumpRequestOut(req, true)
fmt.Printf("Hello, playground, %q", body)
}
You'll get:
"GET /normal/path HTTP/1.1\r\nHost: some...
Now try it with a string in which you inserted NUL characters:
req, err := http.NewRequest("GET", "https://some/\000n\000o\000rmal/path", nil)
...
"GET /%00n%00o%00rmal/path HTTP/1.1\r\nHost: some...
Not quite sure how your string ended up containing those. Read more about percent encoding.