chore: safe base64 decode ipa name

pull/1831/head v3.0.0-rc.1
Noah Hsu 2022-09-18 20:17:24 +08:00
parent 24d58f278a
commit 2185839236
2 changed files with 29 additions and 14 deletions

View File

@ -3,7 +3,9 @@ package utils
import ( import (
"crypto/md5" "crypto/md5"
"crypto/sha1" "crypto/sha1"
"encoding/base64"
"encoding/hex" "encoding/hex"
"strings"
) )
func GetSHA1Encode(data string) string { func GetSHA1Encode(data string) string {
@ -17,3 +19,20 @@ func GetMD5Encode(data string) string {
h.Write([]byte(data)) h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }
var DEC = map[string]string{
"-": "+",
"_": "/",
".": "=",
}
func SafeAtob(data string) (string, error) {
for k, v := range DEC {
data = strings.ReplaceAll(data, k, v)
}
bytes, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return "", err
}
return string(bytes), err
}

View File

@ -1,13 +1,13 @@
package handles package handles
import ( import (
"encoding/base64"
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common" "github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -16,30 +16,26 @@ func Favicon(c *gin.Context) {
c.Redirect(302, setting.GetStr(conf.Favicon)) c.Redirect(302, setting.GetStr(conf.Favicon))
} }
var DEC = map[string]string{
"-": "+",
"_": "/",
".": "=",
}
func Plist(c *gin.Context) { func Plist(c *gin.Context) {
link := c.Param("link") link := c.Param("link")
for k, v := range DEC { u, err := utils.SafeAtob(link)
link = strings.ReplaceAll(link, k, v)
}
u, err := base64.StdEncoding.DecodeString(link)
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 400)
return return
} }
uUrl, err := url.Parse(string(u)) uUrl, err := url.Parse(u)
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 400)
return return
} }
fullName := c.Param("name") fullName := c.Param("name")
Url := uUrl.String() Url := uUrl.String()
fullName = strings.TrimSuffix(fullName, ".plist") fullName = strings.TrimSuffix(fullName, ".plist")
fullName, err = utils.SafeAtob(fullName)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
name := fullName name := fullName
identifier := fmt.Sprintf("ci.nn.%s", url.PathEscape(fullName)) identifier := fmt.Sprintf("ci.nn.%s", url.PathEscape(fullName))
sep := "@" sep := "@"