feat: support mailing-list and monthly mail capture paths
This commit is contained in:
1 parent
543814cbd6
commit
1a451023f0
7 files changed
+165
-5
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"html"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -40,6 +41,14 @@ func TaskCaptureWikiPath(prefix, title, request string) string {
|
||||
return strings.TrimRight(prefix, "/") + "/mail-" + request
|
||||
}
|
||||
|
||||
var mailListSuffix = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,99}/(0|[1-9][0-9]{0,19})$`)
|
||||
var mailMonthSuffix = regexp.MustCompile(`^[0-9]{4}/(0[1-9]|1[0-2])/([0-9a-f]{64}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`)
|
||||
|
||||
// Only the two mail layouts are accepted; no arbitrary relative path traversal.
|
||||
func ValidTaskMailSuffix(s string) bool {
|
||||
return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/"))
|
||||
}
|
||||
|
||||
func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error {
|
||||
if target == "" || !ValidTaskWikiPrefix(path.Dir(target)) || path.Clean(target) != target || item.PageUUID != "" || len(body) > 256<<10 || !utf8.ValidString(body) || strings.IndexByte(body, 0) >= 0 {
|
||||
return ErrTaskInvalid
|
||||
|
||||
Reference in new issue
Block a user