feat: accept trusted AI table link tails
This commit is contained in:
@@ -71,8 +71,22 @@ func ParseNotableLink(raw string) (NotableLink, error) {
|
||||
if len(raw) > 4096 {
|
||||
return NotableLink{}, errors.New("AI Table link is too long")
|
||||
}
|
||||
u, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err != nil || u.Scheme != "https" {
|
||||
input := strings.TrimSpace(raw)
|
||||
u, err := url.Parse(input)
|
||||
if err != nil {
|
||||
return NotableLink{}, errors.New("invalid AI Table link")
|
||||
}
|
||||
if u.Scheme == "" {
|
||||
if u.Host != "" || u.User != nil || strings.Contains(input, "\\") {
|
||||
return NotableLink{}, errors.New("invalid AI Table relative path")
|
||||
}
|
||||
relativePath := "/" + strings.TrimPrefix(u.Path, "/")
|
||||
if !strings.HasPrefix(relativePath, "/i/nodes/") || path.Clean(relativePath) != relativePath {
|
||||
return NotableLink{}, errors.New("invalid AI Table relative path")
|
||||
}
|
||||
u = &url.URL{Scheme: "https", Host: "alidocs.dingtalk.com", Path: relativePath, RawQuery: u.RawQuery}
|
||||
}
|
||||
if u.Scheme != "https" {
|
||||
return NotableLink{}, errors.New("invalid AI Table link")
|
||||
}
|
||||
host := strings.ToLower(u.Hostname())
|
||||
@@ -82,7 +96,7 @@ func ParseNotableLink(raw string) (NotableLink, error) {
|
||||
base := path.Base(strings.TrimRight(u.Path, "/"))
|
||||
q := u.Query()
|
||||
result := NotableLink{BaseID: base, SheetID: q.Get("sheetId"), ViewID: q.Get("viewId")}
|
||||
if result.BaseID == "" || result.BaseID == "." || result.SheetID == "" {
|
||||
if result.BaseID == "" || result.BaseID == "." || result.BaseID == ".." || result.SheetID == "" {
|
||||
return NotableLink{}, errors.New("AI Table link is missing base or sheet")
|
||||
}
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user