mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-23 10:09:03 +02:00
fix: login code null submission and login code length check (#1512)
Co-authored-by: james <james@goldfish.net> Co-authored-by: Kyle Mendell <kmendell@ofkm.us>
This commit is contained in:
co-authored by
james
Kyle Mendell
parent
f673a91a67
commit
2e77d57282
@@ -508,8 +508,15 @@ func (uc *UserController) RequestOneTimeAccessEmailAsAdminHandler(c *gin.Context
|
|||||||
// @Success 200 {object} dto.UserDto
|
// @Success 200 {object} dto.UserDto
|
||||||
// @Router /api/one-time-access-token/{token} [post]
|
// @Router /api/one-time-access-token/{token} [post]
|
||||||
func (uc *UserController) exchangeOneTimeAccessTokenHandler(c *gin.Context) {
|
func (uc *UserController) exchangeOneTimeAccessTokenHandler(c *gin.Context) {
|
||||||
|
loginCode := c.Param("token")
|
||||||
|
// reject invalid length login codes
|
||||||
|
if len(loginCode) != 6 && len(loginCode) != 16 {
|
||||||
|
_ = c.Error(&common.TokenInvalidOrExpiredError{})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
deviceToken, _ := c.Cookie(cookie.DeviceTokenCookieName)
|
deviceToken, _ := c.Cookie(cookie.DeviceTokenCookieName)
|
||||||
user, token, err := uc.oneTimeAccessService.ExchangeOneTimeAccessToken(c.Request.Context(), c.Param("token"), deviceToken, c.ClientIP(), c.Request.UserAgent())
|
user, token, err := uc.oneTimeAccessService.ExchangeOneTimeAccessToken(c.Request.Context(), loginCode, deviceToken, c.ClientIP(), c.Request.UserAgent())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.Error(err)
|
_ = c.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function authenticate() {
|
async function authenticate() {
|
||||||
|
if (!code?.trim()) return;
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
try {
|
try {
|
||||||
const user = await userService.exchangeOneTimeAccessToken(code);
|
const user = await userService.exchangeOneTimeAccessToken(code);
|
||||||
|
|||||||
Reference in New Issue
Block a user