1
0

path.go 575 B

12345678910111213141516171819
  1. package tool
  2. import (
  3. "path/filepath"
  4. "strings"
  5. )
  6. // IsSameSiteURLPath returns true if the URL path belongs to the same site, false otherwise.
  7. // False: //url, http://url, /\url
  8. // True: /url
  9. func IsSameSiteURLPath(url string) bool {
  10. return len(url) >= 2 && url[0] == '/' && url[1] != '/' && url[1] != '\\'
  11. }
  12. // IsMaliciousPath returns true if given path is an absolute path or contains malicious content
  13. // which has potential to traverse upper level directories.
  14. func IsMaliciousPath(path string) bool {
  15. return filepath.IsAbs(path) || strings.Contains(path, "..")
  16. }