feat: add browser upload queue and trusted sessions with bounded projections
This commit is contained in:
1 parent
84d52390f9
commit
b90aef79d0
79 files changed
+1962
-196
No files matched your search
@@ -20,11 +20,11 @@ import (
|
||||
"golang.org/x/net/html/atom"
|
||||
)
|
||||
|
||||
const htmlProjectionVersion = "controlled-v2"
|
||||
const htmlProjectionVersion = "controlled-v3"
|
||||
const maxProjectionInput = 1 << 20
|
||||
const maxProjectionOutput = 4 << 20
|
||||
|
||||
var projectionMacroRE = regexp.MustCompile(`\{\{(?:children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`)
|
||||
var projectionMacroRE = regexp.MustCompile(`\{\{(?:csv:[^}]*|children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`)
|
||||
var languageClassRE = regexp.MustCompile(`^language-[a-zA-Z0-9_+-]{1,40}$`)
|
||||
|
||||
func projectionPolicy(generated bool) *bluemonday.Policy {
|
||||
@@ -199,6 +199,8 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
}
|
||||
var output strings.Builder
|
||||
macros, count := 0, 0
|
||||
csvCount := 0
|
||||
csvResults := map[string]string{}
|
||||
var emit func(*html.Node, int, bool) bool
|
||||
emit = func(n *html.Node, depth int, literal bool) bool {
|
||||
count++
|
||||
@@ -226,6 +228,14 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
// be reparsed as a nested children request on its raw text.
|
||||
if isAnonymousProjection(r) {
|
||||
expanded = s.expandPublicMacro(r, macro, path)
|
||||
} else if strings.HasPrefix(macro, "{{csv:") {
|
||||
if cached, ok := csvResults[macro]; ok {
|
||||
expanded = cached
|
||||
} else if csvCount < 4 {
|
||||
csvCount++
|
||||
expanded = s.expandCSVMacro(r, macro)
|
||||
csvResults[macro] = expanded
|
||||
}
|
||||
} else if strings.HasPrefix(macro, "{{children") {
|
||||
expanded = s.expandChildrenMacros(macro, path)
|
||||
} else {
|
||||
@@ -236,6 +246,9 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
// promote decoded entities into trusted generated elements.
|
||||
output.WriteString(stdhtml.EscapeString(macro))
|
||||
} else {
|
||||
if output.Len()+len(expanded) > maxProjectionOutput {
|
||||
return false
|
||||
}
|
||||
output.WriteString(expanded)
|
||||
}
|
||||
at = loc[1]
|
||||
|
||||
Reference in new issue
Block a user