golang-jwt / jwt

Go implementation of JSON Web Tokens (JWT).
https://golang-jwt.github.io/jwt/
MIT License
6.98k stars 335 forks source link

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

Closed cccqcccq closed 4 months ago

cccqcccq commented 4 months ago

当遇到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

cccqcccq commented 4 months ago

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.

mfridman commented 4 months ago

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.

cccqcccq commented 4 months ago

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