ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
fix(hookvm): charge range iterations against the memory budget
Coff0xc0c557746136b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5af6fb6..3075bb2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b### Fixed+- **Hook `range` counts against the memory budget**: ranging over a body, slice, string, or map charges the iteration before the loop. A body larger than the hook budget now stops with the memory limit instead of allocating one element at a time with no check.- **Docker Compose database passwords with URL-special characters**: `docker-compose.yml` no longer pastes `POSTGRES_PASSWORD` into `ARTEX_PG_DSN`. The server builds the URL from `ARTEX_PG_HOST`, `ARTEX_PG_PORT`, `ARTEX_PG_USER`, `ARTEX_PG_PASSWORD`, `ARTEX_PG_DBNAME` and `ARTEX_PG_SSLMODE`, percent-encoding the user and password, so `/`, `?`, `%`, `@`, `:` and spaces connect. An explicit `ARTEX_PG_DSN` still wins and is not rewritten. `ARTEX_PG_PASSWORD` is removed from the environment with the other startup secrets (#450).## [0.7.0] - 2026-11-21diff --git a/traffic/hookvm/eval.go b/traffic/hookvm/eval.goindex d96d56e..f4b22de 100644--- a/traffic/hookvm/eval.go+++ b/traffic/hookvm/eval.go@@ -330,24 +330,30 @@ func (e *vm) execRange(s *ast.RangeStmt, sc *env) (flowSignal, any) {var items []kvPairswitch x := e.eval(s.X, sc).(type) {case []byte:+ e.alloc(int64(len(x)) * 16)for i, v := range x {items = append(items, kvPair{int64(i), int64(v)})}case []any:+ e.alloc(int64(len(x)) * 16)for i, v := range x {items = append(items, kvPair{int64(i), v})}case []string:+ e.alloc(int64(len(x)) * 16)for i, v := range x {items = append(items, kvPair{int64(i), v})}case string:+ e.alloc(int64(len(x)) * 16)for i, r := range x {items = append(items, kvPair{int64(i), int64(r)})}case map[string]any:+ e.alloc(int64(len(x)) * 16)items = sortedMapPairs(x)case map[string][]string:+ e.alloc(int64(len(x)) * 16)items = sortedMapPairs(x)case nil:return flowNone, nildiff --git a/traffic/hookvm/vm_test.go b/traffic/hookvm/vm_test.goindex 11f2113..6527774 100644--- a/traffic/hookvm/vm_test.go+++ b/traffic/hookvm/vm_test.go@@ -204,6 +204,25 @@ func OnResponse(req *Request, resp *Response) error {}func TestResourceBoundsMemoryStepTimeoutPanicAndRegexp(t *testing.T) {+ t.Run("range_over_body_stopped_by_memory_budget", func(t *testing.T) {+ src := `package hook+func OnRequest(req *Request) error {+ for _, b := range req.Body {+ _ = b+ }+ return nil+}`+ prog, err := Compile("request", src)+ if err != nil {+ t.Fatal(err)+ }+ body := make([]byte, 256<<10)+ err = prog.RunRequest(context.Background(), &Request{Body: body}, RunOptions{MaxMemory: 64 << 10})+ if !errors.Is(err, ErrMemoryLimit) {+ t.Fatalf("err = %v, want ErrMemoryLimit", err)+ }+ })+t.Run("make_100MiB_stopped_by_memory_budget", func(t *testing.T) {src := `package hookfunc OnRequest(req *Request) error {