golang-jwt / jwt

Go implementation of JSON Web Tokens (JWT).

Home Page:https://golang-jwt.github.io/jwt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

希望可以校验token格式 I hope that the token format can be verified

cccqcccq opened this issue · comments

当遇到token乱传值时使用验证token会直接报错:invalid memory address or nil pointer dereference
例如:当token传值1.1.1时不会报错会提示校验失败,当传值111时候直接报错

When a token is randomly transferred, an error will be reported when the token is used to verify the value:invalid memory address or nil pointer dereference
For example: when the token value is 1.1.1, no error will be reported but a verification failure will be prompted. When the value 111 is passed, an error will be reported directly.

image
image

image
image

我发现了问题所在,因为这里的token返回了一个nil所以后面无法获取而报错,需要给一个空的*Token
I discovered the problem. Because the token here returns a nil, it cannot be obtained later and an error is reported. An empty *Token needs to be given.

In Go, it's best practice to check the error, and if err != nil you typically don't trust the other returned values.

I suggest checking the err in the example above.

In Go, it's best practice to check the error, and if err != nil you typically don't trust the other returned values.在 Go 中,最佳做法是检查错误, if err != nil 通常不信任其他返回的值。

I suggest checking the err in the example above.我建议在上面的例子中检查一下 err

Please check my latest reply, this file is parser.go in the framework