mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-22 16:10:53 +08:00
Compare commits
49
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
449065aaaa | ||
|
|
5df46e22c1 | ||
|
|
83b35f844b | ||
|
|
9d7983f1a2 | ||
|
|
3ca8f217a3 | ||
|
|
132af98029 | ||
|
|
6ef01d4f24 | ||
|
|
f72311994e | ||
|
|
4171a041e6 | ||
|
|
db867f63a4 | ||
|
|
d59227c5d4 | ||
|
|
f37d09e365 | ||
|
|
5ce7ae6006 | ||
|
|
7b8be967cc | ||
|
|
09eb73c547 | ||
|
|
43ace17ad7 | ||
|
|
4f4bf201f7 | ||
|
|
444bca59d5 | ||
|
|
d86b22719a | ||
|
|
1e7696c572 | ||
|
|
f4c7184dcc | ||
|
|
0c55774613 | ||
|
|
a133b79a0e | ||
|
|
19110a4727 | ||
|
|
c8b771881e | ||
|
|
0eb66f4c44 | ||
|
|
9a8f366574 | ||
|
|
5bed53b6ae | ||
|
|
25217afdce | ||
|
|
a4a2ee4a51 | ||
|
|
cc573132c4 | ||
|
|
ca9aef6692 | ||
|
|
09a28a3bf8 | ||
|
|
55e2a4d037 | ||
|
|
8b4f890e61 | ||
|
|
ff287467aa | ||
|
|
c65034c50f | ||
|
|
df9536b7e5 | ||
|
|
13073ce18e | ||
|
|
1adfc21346 | ||
|
|
c3a055135d | ||
|
|
c90e2c980c | ||
|
|
b56ad38b43 | ||
|
|
bfaec521ac | ||
|
|
a3c082fdac | ||
|
|
d15166c476 | ||
|
|
59d514e37c | ||
|
|
b5bf99f5fb | ||
|
|
61478bb90b |
+7
-1
@@ -1,5 +1,6 @@
|
||||
# Docker deployment configuration (copy to .env)
|
||||
# The image is built locally by `docker compose build`; there is no registry tag.
|
||||
# docker-compose.yml builds the image locally. docker-compose.ghcr.yml pulls the
|
||||
# released GHCR image; pin it with ARTEX_IMAGE_TAG (latest or a vX.Y.Z tag).
|
||||
# Address the web UI is published on. 127.0.0.1 keeps it host-local; set 0.0.0.0
|
||||
# to reach it from another machine or from Windows when ARTEX runs inside WSL.
|
||||
ARTEX_BIND_ADDR=127.0.0.1
|
||||
@@ -11,8 +12,13 @@ ARTEX_TRUSTED_PROXIES=
|
||||
# Set it when ./keys is not persistent. Losing the key loses the stored secrets.
|
||||
# ARTEX_SECRET_KEY=
|
||||
POSTGRES_USER=artex
|
||||
# The server percent-encodes this into the connection URL, so / ? % @ : and
|
||||
# spaces are safe. Quote a value that contains #, and write $$ for a literal $,
|
||||
# because Compose reads this file that way.
|
||||
POSTGRES_PASSWORD=change-me-please
|
||||
POSTGRES_DB=artex
|
||||
# Prebuilt GHCR image tag for docker-compose.ghcr.yml. Unset uses latest.
|
||||
# ARTEX_IMAGE_TAG=latest
|
||||
|
||||
# LLM (fill one or both; you can also leave empty and configure in the UI)
|
||||
ANTHROPIC_API_KEY=
|
||||
|
||||
@@ -73,12 +73,12 @@ jobs:
|
||||
with:
|
||||
name: pkg-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: "dist/*.zip"
|
||||
# Upload raw Linux binaries separately for reuse by the docker job (avoids rebuilding the frontend + Go inside the image)
|
||||
- if: matrix.goos == 'linux'
|
||||
# Upload the raw linux/amd64 binary separately for the release job's Syft SBOM scan
|
||||
- if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bin-linux-${{ matrix.goarch }}
|
||||
path: dist/artex-linux-${{ matrix.goarch }}/artex
|
||||
name: bin-linux-amd64
|
||||
path: dist/artex-linux-amd64/artex
|
||||
|
||||
# ③ Collect all zips → create the GitHub Release
|
||||
release:
|
||||
@@ -152,45 +152,52 @@ jobs:
|
||||
generate_release_notes: false
|
||||
body_path: ${{ runner.temp }}/release-body.md
|
||||
|
||||
# ④ Multi-arch image → push to Docker Hub (reuses the Linux binaries built by the
|
||||
# binaries job; the image only installs tools + ships the binary; arm64 only needs
|
||||
# to emulate the apt layer, so builds are much faster)
|
||||
# Publishing the image needs Docker Hub credentials and a namespace we own, so the
|
||||
# job stays skipped unless the repository defines DOCKERHUB_ENABLED (set it to true
|
||||
# and provide DOCKERHUB_USERNAME / DOCKERHUB_TOKEN secrets plus DOCKERHUB_IMAGE).
|
||||
# ④ Multi-arch image → push to GitHub Container Registry (and optionally Docker Hub
|
||||
# when DOCKERHUB_ENABLED is set to 'true' alongside DOCKERHUB_IMAGE and
|
||||
# DOCKERHUB_USERNAME / DOCKERHUB_TOKEN secrets). Dry runs (workflow_dispatch)
|
||||
# build both platforms without logging in or pushing.
|
||||
docker:
|
||||
needs: binaries
|
||||
if: ${{ vars.DOCKERHUB_ENABLED == 'true' && github.event_name == 'push' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4 # fetch the Dockerfile and skills/
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bin-linux-amd64
|
||||
path: dist/amd64
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bin-linux-arm64
|
||||
path: dist/arm64
|
||||
- uses: actions/checkout@v4
|
||||
- uses: docker/setup-qemu-action@v3
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
- uses: docker/login-action@v3
|
||||
- name: Log in to GitHub Container Registry
|
||||
if: github.event_name == 'push'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Log in to Docker Hub
|
||||
if: github.event_name == 'push' && vars.DOCKERHUB_ENABLED == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- uses: docker/metadata-action@v5
|
||||
id: meta
|
||||
with:
|
||||
images: ${{ vars.DOCKERHUB_IMAGE }}
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
${{ vars.DOCKERHUB_ENABLED == 'true' && vars.DOCKERHUB_IMAGE || '' }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=semver,pattern={{version}}
|
||||
type=raw,value=latest
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
push: ${{ github.event_name == 'push' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: ARTEX_VERSION=${{ github.ref_name }}
|
||||
provenance: true
|
||||
sbom: true
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
|
||||
All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Live log subscribers can no longer crash the process**: a client disconnect closes its log channel. The sink now delivers a line while it still holds the subscriber lock, so that close cannot land in the middle of the send.
|
||||
- **Notification delivery ignores HTTP_PROXY**: the dial guard checks the address it connects to. An environment proxy made that address the proxy, so a link-local target could still be reached. Notification HTTP now connects directly.
|
||||
- **Captured traffic blobs are owner-only**: HTTP and raw-stream bodies spilled out of the database are written `0600`, and their bucket directory is `0700`. An existing blob is tightened when it is seen again.
|
||||
- **Asset URLs drop userinfo when parsing fails**: a URL `url.Parse` rejects is no longer stored unchanged. The `scheme://userinfo@` prefix is removed first, so a password in that prefix does not land in the asset row.
|
||||
- **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.
|
||||
- **Chat upload name search stops**: choosing `name`, `name-1`, `name-2`, … now returns an error when the filesystem rejects the path or after 10000 collisions, instead of looping while `Stat` keeps failing.
|
||||
- **Uploads do not follow a symlink**: chat and workspace uploads `Lstat` the destination and refuse to write when it is already a symlink. A dangling link is no longer treated as a free name.
|
||||
- **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-21
|
||||
|
||||
Agent-driven traffic capture (SOCKS5, transparent TCP and raw UDP), operator tampering hooks with their admin panel, the agentic injection and proof hardening from the #124 audit, LLM context telemetry and the worker cache-prefix split, capture-proxy rewrite rules, HAR import and export, and a large security batch across the interception gate, sessions, logs, the workspace file API and the model endpoint probe.
|
||||
|
||||
@@ -57,8 +57,9 @@ printed at startup:
|
||||
docker compose logs artex | grep "Setup token"
|
||||
```
|
||||
|
||||
> There is no prebuilt Docker image to pull: the image is always built from your checkout.
|
||||
> For all installation paths (script, binaries, source, release archives), see [Installation](#installation).
|
||||
> Multi-arch release images (`linux/amd64`, `linux/arm64`) are published to GitHub Container
|
||||
> Registry at `ghcr.io/baarai/artex`. For pulling the prebuilt image and all other installation
|
||||
> paths (script, binaries, source, release archives), see [Installation](#installation).
|
||||
|
||||
---
|
||||
|
||||
@@ -331,7 +332,9 @@ The UI listens on `127.0.0.1` by default. To reach it from another machine (or f
|
||||
ARTEX runs inside WSL), set `ARTEX_BIND_ADDR=0.0.0.0` in `.env` (the setup token still protects the
|
||||
first-run claim), or keep loopback and use a reverse proxy or SSH tunnel.
|
||||
|
||||
### Option 2: Docker Compose (manual)
|
||||
### Option 2: Docker (Compose checkout build or prebuilt GHCR image)
|
||||
|
||||
Build from a checkout with Docker Compose:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/BaaRai/ARTEX.git
|
||||
@@ -341,8 +344,73 @@ docker compose up -d --build
|
||||
# → http://localhost:8787
|
||||
```
|
||||
|
||||
Each `v*` release publishes a multi-arch image (`linux/amd64`, `linux/arm64`) to GitHub
|
||||
Container Registry with tags `:latest`, `:v<version>`, and `:<version>`. GHCR packages start
|
||||
private. After the first release, maintainers should check that the `artex` package visibility
|
||||
is set to Public and verify the pull below on a machine without GHCR credentials before
|
||||
announcing anonymous installation.
|
||||
|
||||
The standalone container requires an existing PostgreSQL database reachable from the container.
|
||||
Set the `ARTEX_PG_*` variables below. The example uses Docker Desktop's
|
||||
`host.docker.internal` to reach PostgreSQL on the host. On native Linux Docker Engine, add
|
||||
`--add-host=host.docker.internal:host-gateway` to `docker run` for a host database, or use
|
||||
the reachable hostname of your database server.
|
||||
|
||||
```bash
|
||||
docker pull ghcr.io/baarai/artex:latest
|
||||
|
||||
mkdir -p data keys
|
||||
docker run -d --name artex \
|
||||
--security-opt no-new-privileges:true \
|
||||
-p 127.0.0.1:8787:8787 \
|
||||
-p 127.0.0.1:8788:8788 \
|
||||
-e ARTEX_PG_HOST=host.docker.internal \
|
||||
-e ARTEX_PG_PORT=5432 \
|
||||
-e ARTEX_PG_USER=artex \
|
||||
-e ARTEX_PG_PASSWORD='yourpass' \
|
||||
-e ARTEX_PG_DBNAME=artex \
|
||||
-e ARTEX_PG_SSLMODE=disable \
|
||||
-e ARTEX_JWT_KEY_DIR=/app/keys \
|
||||
-v "$PWD/data:/app/data" \
|
||||
-v "$PWD/keys:/app/keys" \
|
||||
ghcr.io/baarai/artex:latest
|
||||
# → http://localhost:8787 (docker logs artex | grep "Setup token")
|
||||
```
|
||||
|
||||
In `docker-compose.yml` and `docker-compose.ghcr.yml`, `POSTGRES_PASSWORD` is passed to ARTEX as
|
||||
its own variable. The server percent-encodes it into the connection URL, so a password may contain
|
||||
`/`, `?`, `%`, `@`, `:` or spaces. In `.env`, quote a value that contains `#`, and write `$$` for a
|
||||
literal `$`. The `ARTEX_PG_*` variables take the password raw; quote it in a shell.
|
||||
|
||||
The image includes a scanner toolchain (`nmap`, `nuclei`, `httpx`, `katana`, `ffuf`, `dalfox`,
|
||||
`sqlmap`, `ripgrep`, `curl`, `npm`, …); `./skills` and `./data` are persisted via bind mounts.
|
||||
`sqlmap`, `ripgrep`, `curl`, `npm`, …) and built-in `/app/skills`. The GHCR Compose file below
|
||||
persists `./keys` and `./data`; it does not mount a host `skills/` directory, so the image's
|
||||
built-in skills are used.
|
||||
|
||||
#### Compose stack from the prebuilt image
|
||||
|
||||
`docker-compose.ghcr.yml` runs the same ARTEX + PostgreSQL stack from the released image, with no
|
||||
checkout build. Download it and `.env.example` once:
|
||||
|
||||
```bash
|
||||
curl -fsSLO https://raw.githubusercontent.com/BaaRai/ARTEX/main/docker-compose.ghcr.yml
|
||||
curl -fsSLO https://raw.githubusercontent.com/BaaRai/ARTEX/main/.env.example
|
||||
cp .env.example .env # set POSTGRES_PASSWORD, optionally an LLM key
|
||||
docker compose -f docker-compose.ghcr.yml pull
|
||||
docker compose -f docker-compose.ghcr.yml up -d
|
||||
# → http://localhost:8787 (docker compose -f docker-compose.ghcr.yml logs artex | grep "Setup token")
|
||||
```
|
||||
|
||||
Update the stack without a git checkout:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.ghcr.yml pull
|
||||
docker compose -f docker-compose.ghcr.yml up -d
|
||||
```
|
||||
|
||||
Pin a version with `ARTEX_IMAGE_TAG=v0.7.1` in `.env` (or `0.7.1`); unset uses `latest`. To use
|
||||
custom skills, copy them into a host directory and add `- ./skills:/app/skills` to the `artex`
|
||||
volumes, which overrides the built-in `/app/skills`.
|
||||
|
||||
For remote MCP you can choose `http` (Streamable HTTP) or `sse` (legacy SSE) in system settings.
|
||||
Legacy SSE servers usually establish the event stream with `GET /sse` and receive JSON-RPC over
|
||||
@@ -643,7 +711,7 @@ The script optionally `git pull`s, then offers **① Docker update** (`docker co
|
||||
`docker compose up -d artex`) or **② local build update** (rebuild the frontend static assets, then
|
||||
recompile `./artex`; restart the process for it to take effect).
|
||||
|
||||
#### Option 2: Docker Compose (manual)
|
||||
#### Option 2: Docker (Compose or GHCR image)
|
||||
|
||||
```bash
|
||||
cd ARTEX
|
||||
@@ -653,6 +721,15 @@ docker compose up -d artex
|
||||
docker image prune -f # optional
|
||||
```
|
||||
|
||||
If running the prebuilt `ghcr.io/baarai/artex` container directly, pull the new tag (`docker pull
|
||||
ghcr.io/baarai/artex:latest` or a pinned `:v<version>`) and recreate the container with the same
|
||||
`/app/data` and `/app/keys` mounts. If you run the prebuilt Compose stack, the update is:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.ghcr.yml pull
|
||||
docker compose -f docker-compose.ghcr.yml up -d
|
||||
```
|
||||
|
||||
#### Option 3: prebuilt binaries
|
||||
|
||||
Download the new zip, stop the old process, overwrite `artex` and `skills/` (keep `config.json` and
|
||||
|
||||
@@ -277,6 +277,34 @@ func TestProveGoalRefusesFalsePositiveFinding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// risk_accepted means a real finding with accepted risk, not an invalid one:
|
||||
// it must remain eligible to prove a goal (#269).
|
||||
func TestProveGoalAllowsRiskAcceptedFinding(t *testing.T) {
|
||||
if findingTriageBlocksGoal(db.FindingRiskAccepted) {
|
||||
t.Fatalf("findingTriageBlocksGoal(%q) = true, want false", db.FindingRiskAccepted)
|
||||
}
|
||||
d := testDB(t)
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
task, err := d.CreateTaskWithOptions("risk-accepted goal", "verify risk_accepted finding may prove a goal", db.TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
|
||||
s := d.Exploration(task.ExplorationID)
|
||||
goal := addGuardNode(t, s, db.KindGoal, map[string]any{"text": "prove auth bypass"}, "open")
|
||||
rec := seedProvenFinding(t, d, task, "ex-risk-1", "https://risk.example.test/admin",
|
||||
[]int64{seedFindingAsset(t, d, task, "https://risk.example.test/admin")})
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(context.Background(), rec.FindingID, db.FindingRiskAccepted); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tsx := NewToolSet(s, "planner")
|
||||
tsx.SetTrafficProofChecker(func(_ context.Context, id string) (bool, error) { return id == "ex-risk-1", nil })
|
||||
res := callGuardTool(t, tsx.proveGoal(), `{"goal_id":`+strconv.FormatInt(goal, 10)+`,"evidence_id":`+strconv.FormatInt(rec.NodeID, 10)+`,"reason":"accepted risk real finding"}`)
|
||||
if res.IsError || nodeState(t, s, goal) != "met" || !tsx.GoalMet {
|
||||
t.Fatalf("risk_accepted finding: IsError=%v state=%q GoalMet=%v %q", res.IsError, nodeState(t, s, goal), tsx.GoalMet, res.Flatten())
|
||||
}
|
||||
}
|
||||
|
||||
// factEvidenceLines keeps only substantive lines: a bare tool name or a short
|
||||
// status fragment cannot tie a claim to an activity, and duplicates cost a
|
||||
// lookup without adding a candidate.
|
||||
|
||||
@@ -20,10 +20,6 @@ type TrafficCaptureChecker interface {
|
||||
TrafficExists(ctx context.Context, trafficID string) (bool, error)
|
||||
}
|
||||
|
||||
// Tool-use guidance is appended without replacing the user's editable prompt.
|
||||
// It does not require capture or claim that unavailable traffic tools exist.
|
||||
const findingTrafficGuidance = "\n\n**Vulnerability traffic evidence**: when reporting a vulnerability via report_finding, bind real HTTP request/response IDs via traffic_refs in reproduction order; domains and times are only candidate filters and do not imply association. A finding without bound traffic stays recorded and visible, but cannot close a goal via prove_goal until verified traffic matching its asset host is bound (via report_finding or bind_finding_traffic). For TCP and other non-HTTP vulnerabilities, when nothing was captured, or when there is no exact match, omit traffic_refs or pass [], keep verifiable command output and logs in evidence, and close non-HTTP goals with an observed tool_output fact. Do not guess IDs, and do not re-probe just to capture packets."
|
||||
|
||||
func (t *ToolSet) SetFindingRecorder(r FindingRecorder) { t.findingRecorder = r }
|
||||
func (w *Worker) SetFindingRecorder(r FindingRecorder) { w.findingRecorder = r }
|
||||
func (p *Planner) SetFindingRecorder(r FindingRecorder) { p.findingRecorder = r }
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindingRecorderHasNoLegacyTrafficGuidance(t *testing.T) {
|
||||
// Check the declaration directly: an unused constant cannot affect prompt output.
|
||||
f, err := parser.ParseFile(token.NewFileSet(), "finding_recorder.go", nil, parser.SkipObjectResolution)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
if spec, ok := n.(*ast.ValueSpec); ok {
|
||||
for _, name := range spec.Names {
|
||||
if name.Name == "findingTrafficGuidance" {
|
||||
t.Fatal("finding_recorder.go declares the obsolete findingTrafficGuidance constant")
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
@@ -43,10 +43,82 @@ func findingTrafficBindingEnabled() bool {
|
||||
return f != nil && f()
|
||||
}
|
||||
|
||||
var (
|
||||
trafficCaptureMu sync.RWMutex
|
||||
trafficCaptureHook func() bool
|
||||
)
|
||||
|
||||
// SetTrafficCaptureEnabled installs (or, with nil, removes) the hook that
|
||||
// reports whether the server's global traffic capture switch is currently on.
|
||||
func SetTrafficCaptureEnabled(f func() bool) {
|
||||
trafficCaptureMu.Lock()
|
||||
trafficCaptureHook = f
|
||||
trafficCaptureMu.Unlock()
|
||||
}
|
||||
|
||||
// TrafficCaptureEnabled returns the current hook, or nil when none is set.
|
||||
func TrafficCaptureEnabled() func() bool {
|
||||
trafficCaptureMu.RLock()
|
||||
defer trafficCaptureMu.RUnlock()
|
||||
return trafficCaptureHook
|
||||
}
|
||||
|
||||
func trafficCaptureExplicitlyOff() bool {
|
||||
f := TrafficCaptureEnabled()
|
||||
return f != nil && !f()
|
||||
}
|
||||
|
||||
const (
|
||||
trafficCaptureOffProveGoalNote = "\nNote: traffic capture is currently OFF on this server, so no HTTP traffic is being recorded and findings cannot be bound to captured traffic to prove HTTP goals. Recorded findings stay visible, and non-HTTP goals can still be proved with an observed tool_output fact; enable traffic capture in System settings to make HTTP findings provable."
|
||||
trafficCaptureOffReportFindingNote = "\nNote: traffic capture is currently OFF on this server, so no HTTP traffic is being recorded. Findings still save with textual/command evidence, but cannot prove goals via prove_goal until traffic capture is enabled in System settings and verified traffic is bound."
|
||||
)
|
||||
|
||||
func trafficCaptureOffToolNote(toolName string, captureOff bool) string {
|
||||
if !captureOff {
|
||||
return ""
|
||||
}
|
||||
switch toolName {
|
||||
case "prove_goal":
|
||||
return trafficCaptureOffProveGoalNote
|
||||
case "report_finding":
|
||||
return trafficCaptureOffReportFindingNote
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic traffic binding off is a DIFFERENT switch from capture off: capture
|
||||
// can be on while binding is off, and then the disabled branch below strips
|
||||
// bind_finding_traffic and every traffic parameter from the schemas while the
|
||||
// tool descriptions keep promising the binding path. An agent then chases a tool
|
||||
// that is not in its toolset (observed: "the tool bind_finding_traffic must be
|
||||
// invoked as a tool", a bare Bash true, then grepping the transcripts and the
|
||||
// binary). These notes ride on the tool descriptions, exactly like the capture
|
||||
// notes above, so the standing guidance stays empty when the feature is off.
|
||||
const (
|
||||
findingBindingOffProveGoalNote = "\nNote: automatic traffic binding is OFF on this server, so a finding cannot be bound to captured traffic here and cannot close an HTTP goal. Recorded findings stay visible; non-HTTP goals still close with an observed tool_output fact. An operator can enable binding (System settings) or bind captured traffic manually on the finding page, after which a bound finding closes the goal."
|
||||
findingBindingOffReportFindingNote = "\nNote: automatic traffic binding is OFF on this server, so report_finding carries no traffic parameters and the bind_finding_traffic tool is not in your toolset. Findings still save with their evidence, but stay unverified and cannot prove a goal. Register a reproducible PoC in evidence as usual; do not guess traffic IDs and do not re-probe only to capture packets."
|
||||
findingBindingOffHintNote = "\nNote: automatic traffic binding is OFF on this server, so hint traffic parameters are not in this schema. Keep the verified evidence and the known real traffic IDs in the hint text; the receiving task registers the finding and the operator can bind captured traffic later."
|
||||
)
|
||||
|
||||
func findingBindingOffToolNote(toolName string) string {
|
||||
switch toolName {
|
||||
case "prove_goal":
|
||||
return findingBindingOffProveGoalNote
|
||||
case "report_finding":
|
||||
return findingBindingOffReportFindingNote
|
||||
case "add_hint", "add_task_hint":
|
||||
return findingBindingOffHintNote
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Applied after ToolResolve: user descriptions and prompts remain intact, while
|
||||
// all actual reporters (including Planner and custom chat agents) see the same
|
||||
// API contract. Disabled/unbound tools are never reintroduced here.
|
||||
func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.CoreTool, string) {
|
||||
captureOff := trafficCaptureExplicitlyOff()
|
||||
if !findingTrafficBindingEnabled() {
|
||||
out := make([]actool.CoreTool, 0, len(tools))
|
||||
for _, tool := range tools {
|
||||
@@ -56,18 +128,36 @@ func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.Co
|
||||
if agentKey == "reporter" && (tool.Name() == "traffic_search" || tool.Name() == "traffic_get" || tool.Name() == "traffic_blob" || tool.Name() == "traffic_messages") {
|
||||
continue
|
||||
}
|
||||
desc := tool.Description()
|
||||
schema := tool.InputSchema()
|
||||
decorated := false
|
||||
switch tool.Name() {
|
||||
case "report_finding", "add_hint", "add_task_hint":
|
||||
// Work on a copy: toggling back on must restore the original schema.
|
||||
raw, _ := json.Marshal(tool.InputSchema())
|
||||
var schema map[string]any
|
||||
if json.Unmarshal(raw, &schema) == nil {
|
||||
stripTrafficParameters(schema)
|
||||
tool = DecorateTool(tool, tool.Description(), schema)
|
||||
var s map[string]any
|
||||
if json.Unmarshal(raw, &s) == nil {
|
||||
stripTrafficParameters(s)
|
||||
schema = s
|
||||
decorated = true
|
||||
}
|
||||
}
|
||||
if note := trafficCaptureOffToolNote(tool.Name(), captureOff); note != "" {
|
||||
desc += note
|
||||
decorated = true
|
||||
}
|
||||
if note := findingBindingOffToolNote(tool.Name()); note != "" {
|
||||
desc += note
|
||||
decorated = true
|
||||
}
|
||||
if decorated {
|
||||
tool = DecorateTool(tool, desc, schema)
|
||||
}
|
||||
out = append(out, tool)
|
||||
}
|
||||
// The standing guidance stays empty: the binding-off notes ride on the
|
||||
// tool descriptions, so a disabled deployment keeps the same contract the
|
||||
// PG test asserts (def.FindingGuidance == "").
|
||||
return out, ""
|
||||
}
|
||||
out := append([]actool.CoreTool(nil), tools...)
|
||||
@@ -83,6 +173,9 @@ func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.Co
|
||||
case "get_finding_traffic", "bind_finding_traffic", "list_findings", "list_task_findings", "node_detail", "get_task_node_detail", "update_finding_report":
|
||||
note = findingIDGuidance
|
||||
}
|
||||
if capNote := trafficCaptureOffToolNote(tool.Name(), captureOff); capNote != "" {
|
||||
note += capNote
|
||||
}
|
||||
if note != "" {
|
||||
out[i] = DecorateTool(tool, tool.Description()+note, tool.InputSchema())
|
||||
}
|
||||
|
||||
@@ -39,6 +39,29 @@ func TestFindingWorkflowSharedAssemblyAndSwitch(t *testing.T) {
|
||||
if strings.Contains(system[0], "traffic_refs") != on {
|
||||
t.Fatalf("%s: guidance ignored switch: %v", role, on)
|
||||
}
|
||||
if !on {
|
||||
// The switch strips the tool and the schema, so the tool descriptions
|
||||
// must say so: otherwise the agent chases bind_finding_traffic, which
|
||||
// is not in its toolset, and burns turns on it.
|
||||
if def.FindingGuidance != "" {
|
||||
t.Fatalf("%s: disabled deployment must keep the standing guidance empty, got %q", role, def.FindingGuidance)
|
||||
}
|
||||
noted := false
|
||||
for _, tool := range out {
|
||||
if !strings.Contains(tool.Description(), "automatic traffic binding is OFF") {
|
||||
continue
|
||||
}
|
||||
noted = true
|
||||
// The tool that carries traffic parameters is the one whose
|
||||
// schema lost them, so it must name the absent tool.
|
||||
if tool.Name() == "report_finding" && !strings.Contains(tool.Description(), "bind_finding_traffic") {
|
||||
t.Fatalf("%s: report_finding note must name the absent tool", role)
|
||||
}
|
||||
}
|
||||
if !noted {
|
||||
t.Fatalf("%s: disabled deployment must state on the tools that binding is off", role)
|
||||
}
|
||||
}
|
||||
if on && (!strings.Contains(system[0], "TCP") || !strings.Contains(system[0], "evidence_hint_id")) {
|
||||
t.Fatal("missing optional/handoff contract")
|
||||
}
|
||||
@@ -70,3 +93,54 @@ func TestFindingWorkflowSharedAssemblyAndSwitch(t *testing.T) {
|
||||
t.Fatal("reintroduced disabled tool or its guidance")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindingWorkflowToolsTrafficCaptureOffNotice(t *testing.T) {
|
||||
oldPolicy, oldCapture, oldResolve, oldAugment := FindingTrafficBindingEnabled(), TrafficCaptureEnabled(), ToolResolve(), ToolAugment()
|
||||
t.Cleanup(func() {
|
||||
SetFindingTrafficBindingEnabled(oldPolicy)
|
||||
SetTrafficCaptureEnabled(oldCapture)
|
||||
SetToolResolve(oldResolve)
|
||||
SetToolAugment(oldAugment)
|
||||
})
|
||||
SetToolAugment(nil)
|
||||
SetToolResolve(nil)
|
||||
ts := NewToolSet(nil, "fixture")
|
||||
base := []actool.CoreTool{ts.proveGoal(), ts.addFinding(), ts.addHint()}
|
||||
|
||||
for _, binding := range []bool{false, true} {
|
||||
SetFindingTrafficBindingEnabled(func() bool { return binding })
|
||||
|
||||
calls := 0
|
||||
SetTrafficCaptureEnabled(func() bool {
|
||||
calls++
|
||||
return false
|
||||
})
|
||||
outOff, _, clOff := AugmentTools(t.Context(), "planner", base)
|
||||
clOff()
|
||||
if calls != 1 {
|
||||
t.Fatalf("binding=%v: capture hook called %d times for %d tools, want 1", binding, calls, len(base))
|
||||
}
|
||||
for _, tool := range outOff {
|
||||
desc := tool.Description()
|
||||
switch tool.Name() {
|
||||
case "prove_goal", "report_finding":
|
||||
if !strings.Contains(desc, "traffic capture is currently OFF") {
|
||||
t.Fatalf("binding=%v %s: expected capture-off notice in description, got %q", binding, tool.Name(), desc)
|
||||
}
|
||||
case "add_hint":
|
||||
if strings.Contains(desc, "traffic capture is currently OFF") {
|
||||
t.Fatalf("binding=%v add_hint: unexpected capture-off notice", binding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetTrafficCaptureEnabled(func() bool { return true })
|
||||
outOn, _, clOn := AugmentTools(t.Context(), "planner", base)
|
||||
clOn()
|
||||
for _, tool := range outOn {
|
||||
if strings.Contains(tool.Description(), "traffic capture is currently OFF") {
|
||||
t.Fatalf("binding=%v %s: unexpected capture-off notice when capture is ON", binding, tool.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -1103,14 +1103,10 @@ func findingPayloadStatus(n *db.Node) string {
|
||||
}
|
||||
|
||||
// findingTriageBlocksGoal is true when the finding's triage label says it is
|
||||
// not a vulnerability to close a goal on.
|
||||
// not a vulnerability to close a goal on. Delegates to db.FindingStatusInvalidatesGoal
|
||||
// so prove_goal and DB goal-reopen logic share one list and cannot drift (#269).
|
||||
func findingTriageBlocksGoal(status string) bool {
|
||||
switch status {
|
||||
case db.FindingFalsePositive, db.FindingDuplicate, db.FindingIgnored:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return db.FindingStatusInvalidatesGoal(status)
|
||||
}
|
||||
|
||||
func countActionableFindings(nodes []*db.Node) int {
|
||||
@@ -1696,7 +1692,9 @@ func factEvidenceLines(evidence string) []string {
|
||||
}
|
||||
}
|
||||
return out
|
||||
} // factProvenance classifies one fact against the intent's recorded activity.
|
||||
}
|
||||
|
||||
// factProvenance classifies one fact against the intent's recorded activity.
|
||||
// Beyond the activity tie it checks whether the quoted bytes were captured
|
||||
// coming back from the target through the proxy, in which case the target
|
||||
// authored them and the fact is classified target_response even when the model
|
||||
|
||||
+39
-2
@@ -157,7 +157,15 @@ func SkillDir() (string, error) {
|
||||
|
||||
// PostgresDSN resolves the connection string with precedence:
|
||||
//
|
||||
// env ARTEX_PG_DSN > config file (database.dsn, or assembled from fields)
|
||||
// env ARTEX_PG_DSN
|
||||
// > env ARTEX_PG_HOST / ARTEX_PG_PORT / ARTEX_PG_USER / ARTEX_PG_PASSWORD /
|
||||
// ARTEX_PG_DBNAME / ARTEX_PG_SSLMODE
|
||||
// > config file (database.dsn, or assembled from fields)
|
||||
//
|
||||
// The component variables are how Docker Compose passes a password that contains
|
||||
// URL-special characters: the password stays a raw environment value, and
|
||||
// buildDSN percent-encodes it. An explicit ARTEX_PG_DSN is returned unchanged,
|
||||
// so a value that was already assembled by something else is not rewritten.
|
||||
//
|
||||
// There is NO built-in fallback: when neither source supplies a database config,
|
||||
// it returns an error naming the config path it inspected, so startup fails loudly
|
||||
@@ -167,6 +175,9 @@ func PostgresDSN() (dsn, source string, err error) {
|
||||
if v := strings.TrimSpace(os.Getenv("ARTEX_PG_DSN")); v != "" {
|
||||
return v, "environment variable ARTEX_PG_DSN", nil
|
||||
}
|
||||
if d, ok, err := postgresDSNFromEnv(); ok || err != nil {
|
||||
return d, "environment variables ARTEX_PG_HOST/USER/PASSWORD/DBNAME", err
|
||||
}
|
||||
c, err := Load()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
@@ -178,7 +189,33 @@ func PostgresDSN() (dsn, source string, err error) {
|
||||
if db.Host != "" || db.DBName != "" || db.User != "" {
|
||||
return db.buildDSN(), "config file " + Path() + " (database fields)", nil
|
||||
}
|
||||
return "", "", fmt.Errorf("no database config found: the environment variable ARTEX_PG_DSN is not set, and config file %s provides no database (dsn or host/user/dbname). Create the config file or set the environment variable and retry", Path())
|
||||
return "", "", fmt.Errorf("no database config found: ARTEX_PG_DSN is not set, ARTEX_PG_HOST/USER/PASSWORD/DBNAME are not set, and config file %s provides no database (dsn or host/user/dbname). Create the config file or set the environment variable and retry", Path())
|
||||
}
|
||||
|
||||
// postgresDSNFromEnv assembles a URL from the component environment variables.
|
||||
// ok is false when none of them is set. The password is not trimmed: a space is
|
||||
// a legal character and is the case docker-compose used to break.
|
||||
func postgresDSNFromEnv() (dsn string, ok bool, err error) {
|
||||
host := strings.TrimSpace(os.Getenv("ARTEX_PG_HOST"))
|
||||
user := strings.TrimSpace(os.Getenv("ARTEX_PG_USER"))
|
||||
password := os.Getenv("ARTEX_PG_PASSWORD")
|
||||
dbname := strings.TrimSpace(os.Getenv("ARTEX_PG_DBNAME"))
|
||||
portStr := strings.TrimSpace(os.Getenv("ARTEX_PG_PORT"))
|
||||
ssl := strings.TrimSpace(os.Getenv("ARTEX_PG_SSLMODE"))
|
||||
if host == "" && user == "" && password == "" && dbname == "" && portStr == "" && ssl == "" {
|
||||
return "", false, nil
|
||||
}
|
||||
port := 0
|
||||
if portStr != "" {
|
||||
n, convErr := strconv.Atoi(portStr)
|
||||
if convErr != nil || n <= 0 || n > 65535 {
|
||||
return "", true, fmt.Errorf("ARTEX_PG_PORT %q is not a TCP port", portStr)
|
||||
}
|
||||
port = n
|
||||
}
|
||||
return Database{
|
||||
Host: host, Port: port, User: user, Password: password, DBName: dbname, SSLMode: ssl,
|
||||
}.buildDSN(), true, nil
|
||||
}
|
||||
|
||||
func (d Database) buildDSN() string {
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func clearPGComponentEnv(t *testing.T) {
|
||||
t.Helper()
|
||||
for _, k := range []string{
|
||||
"ARTEX_PG_HOST", "ARTEX_PG_PORT", "ARTEX_PG_USER", "ARTEX_PG_PASSWORD",
|
||||
"ARTEX_PG_DBNAME", "ARTEX_PG_SSLMODE",
|
||||
} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgresDSNPrecedence(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfgPath := filepath.Join(dir, "config.json")
|
||||
os.WriteFile(cfgPath, []byte(`{"database":{"host":"10.1.2.3","port":6000,"user":"u","password":"p","dbname":"d","sslmode":"require"}}`), 0o644)
|
||||
t.Setenv("ARTEX_CONFIG", cfgPath)
|
||||
clearPGComponentEnv(t)
|
||||
|
||||
// no env DSN → built from config file fields
|
||||
t.Setenv("ARTEX_PG_DSN", "")
|
||||
@@ -42,6 +54,53 @@ func TestPostgresDSNPrecedence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgresDSNEncodesComponentPassword(t *testing.T) {
|
||||
clearPGComponentEnv(t)
|
||||
t.Setenv("ARTEX_PG_DSN", "")
|
||||
t.Setenv("ARTEX_CONFIG", filepath.Join(t.TempDir(), "nope.json"))
|
||||
const password = "p/ss w@rd?#%"
|
||||
t.Setenv("ARTEX_PG_HOST", "postgres")
|
||||
t.Setenv("ARTEX_PG_PORT", "5432")
|
||||
t.Setenv("ARTEX_PG_USER", "artex")
|
||||
t.Setenv("ARTEX_PG_PASSWORD", password)
|
||||
t.Setenv("ARTEX_PG_DBNAME", "artex")
|
||||
t.Setenv("ARTEX_PG_SSLMODE", "disable")
|
||||
|
||||
got, source, err := PostgresDSN()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(source, "ARTEX_PG_HOST") {
|
||||
t.Fatalf("source %q", source)
|
||||
}
|
||||
u, err := url.Parse(got)
|
||||
if err != nil {
|
||||
t.Fatalf("parse %q: %v", got, err)
|
||||
}
|
||||
pw, ok := u.User.Password()
|
||||
if !ok || pw != password || u.User.Username() != "artex" || u.Host != "postgres:5432" || u.Path != "/artex" {
|
||||
t.Fatalf("dsn %q decoded user=%q password=%q ok=%v host=%q path=%q", got, u.User.Username(), pw, ok, u.Host, u.Path)
|
||||
}
|
||||
if u.Query().Get("sslmode") != "disable" {
|
||||
t.Fatalf("sslmode %q", u.RawQuery)
|
||||
}
|
||||
if strings.Contains(got, password) {
|
||||
t.Fatalf("password left raw in %q", got)
|
||||
}
|
||||
|
||||
// An explicit URL is not rewritten, even when the component password is set.
|
||||
t.Setenv("ARTEX_PG_DSN", "postgres://already/set")
|
||||
if got, _, err = PostgresDSN(); err != nil || got != "postgres://already/set" {
|
||||
t.Fatalf("explicit DSN got %q err %v", got, err)
|
||||
}
|
||||
|
||||
t.Setenv("ARTEX_PG_DSN", "")
|
||||
t.Setenv("ARTEX_PG_PORT", "nope")
|
||||
if _, _, err = PostgresDSN(); err == nil || !strings.Contains(err.Error(), "ARTEX_PG_PORT") {
|
||||
t.Fatalf("bad port: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A config file that exists but is not valid JSON must fail loudly, not run with
|
||||
// defaults (or report "no database config") as if the file were absent.
|
||||
func TestRedactMasksEveryDSNPasswordForm(t *testing.T) {
|
||||
@@ -66,6 +125,7 @@ func TestMalformedConfigIsAnError(t *testing.T) {
|
||||
os.WriteFile(cfgPath, []byte(`{"database":{"host":"h","password":"a"b","dbname":"d"},"skill_dir":"/s"}`), 0o644)
|
||||
t.Setenv("ARTEX_CONFIG", cfgPath)
|
||||
t.Setenv("ARTEX_PG_DSN", "")
|
||||
clearPGComponentEnv(t)
|
||||
t.Setenv("ARTEX_SKILL_DIR", "")
|
||||
|
||||
if _, _, err := PostgresDSN(); err == nil || !strings.Contains(err.Error(), "parse config file") {
|
||||
|
||||
+20
-1
@@ -165,7 +165,7 @@ func calcCSegment(ipStr string) string {
|
||||
func normalizeURL(raw string) string {
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return raw
|
||||
return stripURLUserinfo(raw)
|
||||
}
|
||||
u.Scheme = strings.ToLower(u.Scheme)
|
||||
u.Host = strings.ToLower(u.Host)
|
||||
@@ -177,6 +177,25 @@ func normalizeURL(raw string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// stripURLUserinfo removes scheme://userinfo@ when url.Parse cannot. The
|
||||
// userinfo is the span before the last @ that still sits in the authority.
|
||||
func stripURLUserinfo(raw string) string {
|
||||
i := strings.Index(raw, "://")
|
||||
if i < 0 {
|
||||
return raw
|
||||
}
|
||||
rest := raw[i+3:]
|
||||
authEnd := len(rest)
|
||||
if j := strings.IndexAny(rest, "/?#"); j >= 0 {
|
||||
authEnd = j
|
||||
}
|
||||
at := strings.LastIndex(rest[:authEnd], "@")
|
||||
if at < 0 {
|
||||
return raw
|
||||
}
|
||||
return raw[:i+3] + rest[at+1:]
|
||||
}
|
||||
|
||||
// parseURL extracts domain, port, service_name from a URL.
|
||||
func parseURL(raw string) (domain string, port int, serviceName string) {
|
||||
u, err := url.Parse(raw)
|
||||
|
||||
@@ -908,6 +908,7 @@ func TestNormalizeURL(t *testing.T) {
|
||||
{"https://user@example.com/", "https://example.com"},
|
||||
{"https://u:p@example.com:8443/users/@alice?x=1", "https://example.com:8443/users/@alice?x=1"},
|
||||
{"https://example.com/@me?r=http://a:b@x/", "https://example.com/@me?r=http://a:b@x/"},
|
||||
{"http://user:secret@ex ample.com/a", "http://ex ample.com/a"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
got := normalizeURL(tc.raw)
|
||||
|
||||
@@ -102,8 +102,9 @@ func coordinateWithSchemaMigration(tx *sql.Tx) error {
|
||||
}
|
||||
|
||||
// DSN resolves the PostgreSQL connection string and reports where it came from.
|
||||
// Precedence: env ARTEX_PG_DSN > config file (config.json). There is no
|
||||
// built-in default — it errors if neither source is configured.
|
||||
// Precedence: env ARTEX_PG_DSN > ARTEX_PG_HOST/USER/PASSWORD/DBNAME > config
|
||||
// file (config.json). There is no built-in default — it errors if no source
|
||||
// is configured.
|
||||
func DSN() (dsn, source string, err error) {
|
||||
return config.PostgresDSN()
|
||||
}
|
||||
|
||||
@@ -282,12 +282,14 @@ func (d *DB) FinishFindingRetest(id int64, status, reason string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if finalStatus == "completed" {
|
||||
if err := syncLessonsForFindingTx(context.Background(), tx, findingID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
if finalStatus == "completed" {
|
||||
d.syncLessonsForFinding(context.Background(), findingID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+30
-1
@@ -750,7 +750,36 @@ func (d *DB) DeleteFindingsByTask(taskID int64) (int64, error) {
|
||||
// do not care about notifications (parameter validation, retest flows) can
|
||||
// drive the status on their own.
|
||||
func (d *DB) SetFindingStatus(id int64, status string) (int64, error) {
|
||||
return d.setFindingCol(id, "status", "status", status)
|
||||
ctx := context.Background()
|
||||
tx, err := d.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var nodeID sql.NullInt64
|
||||
err = tx.QueryRowContext(ctx, `UPDATE findings SET status=$1 WHERE id=$2 RETURNING node_id`, status, id).Scan(&nodeID)
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, nil
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if nodeID.Valid {
|
||||
if _, err := tx.ExecContext(ctx, `UPDATE exploration_nodes
|
||||
SET payload = jsonb_set(payload, '{status}', to_jsonb($1::text))
|
||||
WHERE id = $2`, status, nodeID.Int64); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if FindingStatusInvalidatesGoal(status) {
|
||||
if err := reopenGoalsProvedByNodeTx(ctx, tx, nodeID.Int64); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
// SetFindingReportState updates one finding's report stage and mirrors it onto
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindingStatusReopensProvedGoals(t *testing.T) {
|
||||
d := notifyTestDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
newTaskWithProvedGoal := func(t *testing.T, label string) (taskID int64, es *ExplorationStore, findingID, findingNodeID, goalID int64) {
|
||||
t.Helper()
|
||||
task, err := d.CreateTaskWithOptions("reopen-"+label, "goal "+label, TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
|
||||
es = d.Exploration(task.ExplorationID)
|
||||
goalID, err = es.AddNode(KindGoal, map[string]any{"text": "prove " + label}, 0, "open", "goals", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rec, err := es.RecordFinding(ctx, RecordFindingInput{
|
||||
TaskID: task.ID,
|
||||
ExplorationID: task.ExplorationID,
|
||||
VulnClass: "sqli",
|
||||
Name: "finding " + label,
|
||||
Severity: "high",
|
||||
Summary: "summary " + label,
|
||||
Worker: "worker-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='finding' AND source_id=$1)`, rec.FindingID)
|
||||
})
|
||||
if err := es.Link(rec.NodeID, RelProves, goalID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := es.SetNodeState(goalID, "met"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return task.ID, es, rec.FindingID, rec.NodeID, goalID
|
||||
}
|
||||
|
||||
assertGoalState := func(t *testing.T, es *ExplorationStore, goalID int64, want string) {
|
||||
t.Helper()
|
||||
n, err := es.GetNode(goalID)
|
||||
if err != nil || n == nil {
|
||||
t.Fatalf("GetNode(%d): %v", goalID, err)
|
||||
}
|
||||
if n.State != want {
|
||||
t.Fatalf("goal %d state = %q, want %q", goalID, n.State, want)
|
||||
}
|
||||
}
|
||||
|
||||
assertProvesEdgeKept := func(t *testing.T, fromID, toID int64) {
|
||||
t.Helper()
|
||||
var cnt int
|
||||
if err := d.QueryRow(`SELECT COUNT(*) FROM exploration_edges WHERE src_id=$1 AND dst_id=$2 AND rel=$3`, fromID, toID, RelProves).Scan(&cnt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cnt != 1 {
|
||||
t.Fatalf("proves edge (%d -> %d) count = %d, want 1 (must be preserved for history)", fromID, toID, cnt)
|
||||
}
|
||||
}
|
||||
|
||||
goalContentVersion := func(t *testing.T, goalID int64) int {
|
||||
t.Helper()
|
||||
var v int
|
||||
if err := d.QueryRow(`SELECT content_version FROM exploration_nodes WHERE id=$1`, goalID).Scan(&v); err != nil {
|
||||
t.Fatalf("SELECT content_version(%d): %v", goalID, err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
t.Run("single_status_path_reopens_for_fp_duplicate_ignored", func(t *testing.T) {
|
||||
for _, status := range []string{FindingFalsePositive, FindingDuplicate, FindingIgnored} {
|
||||
t.Run(status, func(t *testing.T) {
|
||||
_, es, fid, fnid, gid := newTaskWithProvedGoal(t, "single-"+status)
|
||||
vBefore := goalContentVersion(t, gid)
|
||||
_, found, _, err := d.SetFindingStatusWithNotify(ctx, fid, status)
|
||||
if err != nil || !found {
|
||||
t.Fatalf("SetFindingStatusWithNotify(%s): found=%v err=%v", status, found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "open")
|
||||
if vAfter := goalContentVersion(t, gid); vAfter != vBefore+1 {
|
||||
t.Fatalf("goal %d content_version = %d, want %d (bumped on reopen)", gid, vAfter, vBefore+1)
|
||||
}
|
||||
assertProvesEdgeKept(t, fnid, gid)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("bulk_status_path_reopens_all_proved_goals", func(t *testing.T) {
|
||||
_, es1, fid1, fnid1, gid1 := newTaskWithProvedGoal(t, "bulk-1")
|
||||
_, es2, fid2, fnid2, gid2 := newTaskWithProvedGoal(t, "bulk-2")
|
||||
res, err := d.SetFindingStatusesWithNotify(ctx, []int64{fid1, fid2}, FindingFalsePositive)
|
||||
if err != nil || len(res) != 2 {
|
||||
t.Fatalf("SetFindingStatusesWithNotify: res=%+v err=%v", res, err)
|
||||
}
|
||||
assertGoalState(t, es1, gid1, "open")
|
||||
assertGoalState(t, es2, gid2, "open")
|
||||
assertProvesEdgeKept(t, fnid1, gid1)
|
||||
assertProvesEdgeKept(t, fnid2, gid2)
|
||||
})
|
||||
|
||||
t.Run("retest_path_uses_same_tx_semantics", func(t *testing.T) {
|
||||
_, es, fid, fnid, gid := newTaskWithProvedGoal(t, "retest")
|
||||
// Retest concluding "fixed" calls SetFindingStatusTx(FindingFixed): goal stays met.
|
||||
rt, conv, _, err := d.CreateFindingRetest(ctx, fid, "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='retest' AND source_id=$1)`, rt.ID)
|
||||
_ = d.DeleteConversation(conv.ID)
|
||||
})
|
||||
if _, err := d.StartFindingRetest(ctx, rt.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.RecordFindingRetestResult(ctx, conv.ID, "fixed", "patched", "verified 403"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.FinishFindingRetest(rt.ID, "completed", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "met")
|
||||
|
||||
// In-transaction rollback check: SetFindingStatusTx(FindingFalsePositive) reopens inside
|
||||
// the same tx, and rolling back the tx leaves the goal met.
|
||||
tx, err := d.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found, changed, _, err := SetFindingStatusTx(ctx, tx, fid, FindingFalsePositive); err != nil || !found || !changed {
|
||||
tx.Rollback()
|
||||
t.Fatalf("SetFindingStatusTx: found=%v changed=%v err=%v", found, changed, err)
|
||||
}
|
||||
var stateInTx string
|
||||
if err := tx.QueryRowContext(ctx, `SELECT state FROM exploration_nodes WHERE id=$1`, gid).Scan(&stateInTx); err != nil {
|
||||
tx.Rollback()
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stateInTx != "open" {
|
||||
tx.Rollback()
|
||||
t.Fatalf("goal state inside tx = %q, want open", stateInTx)
|
||||
}
|
||||
_ = tx.Rollback()
|
||||
assertGoalState(t, es, gid, "met")
|
||||
assertProvesEdgeKept(t, fnid, gid)
|
||||
})
|
||||
|
||||
t.Run("finding_that_never_proved_a_goal_does_not_touch_other_goals", func(t *testing.T) {
|
||||
taskID, es, _, fnid1, gid1 := newTaskWithProvedGoal(t, "unlinked")
|
||||
rec2, err := es.RecordFinding(ctx, RecordFindingInput{
|
||||
TaskID: taskID,
|
||||
ExplorationID: es.ID(),
|
||||
VulnClass: "xss",
|
||||
Name: "unlinked finding",
|
||||
Severity: "medium",
|
||||
Summary: "never proved any goal",
|
||||
Worker: "worker-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='finding' AND source_id=$1)`, rec2.FindingID)
|
||||
})
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, rec2.FindingID, FindingFalsePositive); err != nil || !found {
|
||||
t.Fatalf("SetFindingStatusWithNotify(unlinked): found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid1, "met")
|
||||
assertProvesEdgeKept(t, fnid1, gid1)
|
||||
})
|
||||
|
||||
t.Run("risk_accepted_keeps_proved_goal_met", func(t *testing.T) {
|
||||
_, es, fid, fnid, gid := newTaskWithProvedGoal(t, "risk-accepted")
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingRiskAccepted); err != nil || !found {
|
||||
t.Fatalf("SetFindingStatusWithNotify(risk_accepted): found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "met")
|
||||
assertProvesEdgeKept(t, fnid, gid)
|
||||
})
|
||||
|
||||
t.Run("stays_met_when_another_valid_finding_proves_goal", func(t *testing.T) {
|
||||
taskID, es, fidA, fnidA, gid := newTaskWithProvedGoal(t, "multi-finding-A")
|
||||
recB, err := es.RecordFinding(ctx, RecordFindingInput{
|
||||
TaskID: taskID,
|
||||
ExplorationID: es.ID(),
|
||||
VulnClass: "sqli",
|
||||
Name: "finding B",
|
||||
Severity: "high",
|
||||
Summary: "independent confirmed finding",
|
||||
Worker: "worker-2",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='finding' AND source_id=$1)`, recB.FindingID)
|
||||
})
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, recB.FindingID, FindingConfirmed); err != nil || !found {
|
||||
t.Fatalf("confirm finding B: found=%v err=%v", found, err)
|
||||
}
|
||||
if err := es.Link(recB.NodeID, RelProves, gid); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Invalidating A while confirmed B still proves the goal must keep the goal met.
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, fidA, FindingFalsePositive); err != nil || !found {
|
||||
t.Fatalf("invalidate finding A: found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "met")
|
||||
assertProvesEdgeKept(t, fnidA, gid)
|
||||
assertProvesEdgeKept(t, recB.NodeID, gid)
|
||||
|
||||
// Once B is also invalidated, no valid proof remains and the goal reopens.
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, recB.FindingID, FindingFalsePositive); err != nil || !found {
|
||||
t.Fatalf("invalidate finding B: found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "open")
|
||||
assertProvesEdgeKept(t, fnidA, gid)
|
||||
assertProvesEdgeKept(t, recB.NodeID, gid)
|
||||
})
|
||||
|
||||
t.Run("stays_met_when_observed_tool_output_fact_proves_goal", func(t *testing.T) {
|
||||
_, es, fidA, fnidA, gid := newTaskWithProvedGoal(t, "finding-and-fact")
|
||||
factID, err := es.AddNode(KindFact, map[string]any{
|
||||
"summary": "admin shell confirmed",
|
||||
"confidence": "observed",
|
||||
"source": "tool_output",
|
||||
"provenance": "activity_verified",
|
||||
}, 0, "confirmed", "worker-1", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := es.Link(factID, RelProves, gid); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, fidA, FindingFalsePositive); err != nil || !found {
|
||||
t.Fatalf("invalidate finding A: found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "met")
|
||||
assertProvesEdgeKept(t, fnidA, gid)
|
||||
assertProvesEdgeKept(t, factID, gid)
|
||||
})
|
||||
|
||||
t.Run("reopens_when_remaining_fact_fails_prove_goal_gate", func(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
payload map[string]any
|
||||
}{
|
||||
{"inferred_fact", map[string]any{"summary": "guess", "confidence": "inferred", "source": "tool_output"}},
|
||||
{"target_response_fact", map[string]any{"summary": "banner", "confidence": "observed", "source": "target_response"}},
|
||||
{"unverified_fact", map[string]any{"summary": "paraphrase", "confidence": "observed", "source": "tool_output", "provenance": "unverified"}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, es, fidA, fnidA, gid := newTaskWithProvedGoal(t, "invalid-fact-"+tc.name)
|
||||
factID, err := es.AddNode(KindFact, tc.payload, 0, "confirmed", "worker-1", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := es.Link(factID, RelProves, gid); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found, _, err := d.SetFindingStatusWithNotify(ctx, fidA, FindingFalsePositive); err != nil || !found {
|
||||
t.Fatalf("invalidate finding A: found=%v err=%v", found, err)
|
||||
}
|
||||
assertGoalState(t, es, gid, "open")
|
||||
assertProvesEdgeKept(t, fnidA, gid)
|
||||
assertProvesEdgeKept(t, factID, gid)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
+135
-52
@@ -6,8 +6,8 @@ import (
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -63,9 +63,39 @@ func lessonDedupeKey(kind string, categoryID, companyID int64, cue, action strin
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func taskLessonScope(ctx context.Context, d *DB, taskID int64) (categoryID int64, companyIDs []int64, err error) {
|
||||
type sqlExecQuerier interface {
|
||||
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||||
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
|
||||
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
|
||||
}
|
||||
|
||||
// lessonSyncTxTestHook is nil in production; tests set it to inject an
|
||||
// extraction failure inside a status or retest transaction.
|
||||
var lessonSyncTxTestHook func(ctx context.Context, tx *sql.Tx, taskID int64) error
|
||||
|
||||
func taskCompanyIDsQ(ctx context.Context, q sqlExecQuerier, taskID int64) ([]int64, error) {
|
||||
rows, err := q.QueryContext(ctx, `
|
||||
SELECT company_id FROM task_scope
|
||||
WHERE task_id=$1 AND kind='company' AND company_id IS NOT NULL
|
||||
ORDER BY id`, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []int64
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, id)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func taskLessonScopeQ(ctx context.Context, q sqlExecQuerier, taskID int64) (categoryID int64, companyIDs []int64, err error) {
|
||||
var cat sql.NullInt64
|
||||
err = d.QueryRowContext(ctx,
|
||||
err = q.QueryRowContext(ctx,
|
||||
`SELECT category_id FROM tasks WHERE id=$1 AND deleted_at IS NULL`, taskID).
|
||||
Scan(&cat)
|
||||
if err != nil {
|
||||
@@ -74,7 +104,7 @@ func taskLessonScope(ctx context.Context, d *DB, taskID int64) (categoryID int64
|
||||
if cat.Valid {
|
||||
categoryID = cat.Int64
|
||||
}
|
||||
companyIDs, err = d.TaskCompanyIDsContext(ctx, taskID)
|
||||
companyIDs, err = taskCompanyIDsQ(ctx, q, taskID)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
@@ -84,6 +114,10 @@ func taskLessonScope(ctx context.Context, d *DB, taskID int64) (categoryID int64
|
||||
return categoryID, companyIDs, nil
|
||||
}
|
||||
|
||||
func taskLessonScope(ctx context.Context, d *DB, taskID int64) (categoryID int64, companyIDs []int64, err error) {
|
||||
return taskLessonScopeQ(ctx, d.DB, taskID)
|
||||
}
|
||||
|
||||
// lessonExtractCompanyID is the company written onto a new lesson. The row has
|
||||
// one company_id. Scope only when the task has exactly one company. Zero
|
||||
// companies → generic (NULL). ExtractLessonsForTask still retracts when there
|
||||
@@ -107,7 +141,22 @@ func lessonExtractCompanyID(companyIDs []int64) int64 {
|
||||
// not gain a lesson, but a reversed disposition still withdraws evidence written
|
||||
// while it had one company. Returns the number of distinct lessons written.
|
||||
func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, error) {
|
||||
categoryID, companyIDs, err := taskLessonScope(ctx, d, taskID)
|
||||
return extractLessonsForTaskQ(ctx, d.DB, taskID)
|
||||
}
|
||||
|
||||
// ExtractLessonsForTaskTx runs lesson extraction/retraction inside the caller's
|
||||
// transaction so status changes and lesson updates commit or roll back together.
|
||||
func ExtractLessonsForTaskTx(ctx context.Context, tx *sql.Tx, taskID int64) (int, error) {
|
||||
if lessonSyncTxTestHook != nil {
|
||||
if err := lessonSyncTxTestHook(ctx, tx, taskID); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return extractLessonsForTaskQ(ctx, tx, taskID)
|
||||
}
|
||||
|
||||
func extractLessonsForTaskQ(ctx context.Context, q sqlExecQuerier, taskID int64) (int, error) {
|
||||
categoryID, companyIDs, err := taskLessonScopeQ(ctx, q, taskID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -117,7 +166,18 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
companyID := lessonExtractCompanyID(companyIDs)
|
||||
// Only a completed retest with a verdict is an outcome. A pending, running,
|
||||
// failed or stopped retest can carry a staged verdict that never finished.
|
||||
rows, err := d.QueryContext(ctx, `
|
||||
// Buffer rows before writing so a single-connection *sql.Tx is never busy.
|
||||
type findingRow struct {
|
||||
findingID int64
|
||||
vulnclass string
|
||||
name string
|
||||
summary string
|
||||
severity string
|
||||
status string
|
||||
retestID int64
|
||||
verdict string
|
||||
}
|
||||
rows, err := q.QueryContext(ctx, `
|
||||
SELECT f.id, f.vulnclass, f.name, f.summary, f.severity, f.status,
|
||||
COALESCE(r.id,0), COALESCE(r.verdict,'')
|
||||
FROM findings f
|
||||
@@ -131,16 +191,25 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
touched := map[int64]bool{}
|
||||
var findings []findingRow
|
||||
for rows.Next() {
|
||||
var findingID int64
|
||||
var vulnclass, name, summary, severity, status, verdict string
|
||||
var retestID int64
|
||||
if err := rows.Scan(&findingID, &vulnclass, &name, &summary, &severity, &status, &retestID, &verdict); err != nil {
|
||||
var fr findingRow
|
||||
if err := rows.Scan(&fr.findingID, &fr.vulnclass, &fr.name, &fr.summary, &fr.severity, &fr.status, &fr.retestID, &fr.verdict); err != nil {
|
||||
rows.Close()
|
||||
return 0, err
|
||||
}
|
||||
findings = append(findings, fr)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
rows.Close()
|
||||
return 0, err
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
touched := map[int64]bool{}
|
||||
for _, fr := range findings {
|
||||
findingID, vulnclass, name, summary, severity, status, retestID, verdict :=
|
||||
fr.findingID, fr.vulnclass, fr.name, fr.summary, fr.severity, fr.status, fr.retestID, fr.verdict
|
||||
cue := lessonText(vulnclass, lessonCueMax)
|
||||
if cue == "" {
|
||||
cue = lessonText(name, lessonCueMax)
|
||||
@@ -162,17 +231,16 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
if cue == "" || action == "" || sourceID == 0 {
|
||||
return nil // evidence gate: no write without cue + action + source
|
||||
}
|
||||
id, err := d.upsertLesson(ctx, lessonDedupeKey(kind, categoryID, companyID, cue, action),
|
||||
id, err := upsertLessonQ(ctx, q, lessonDedupeKey(kind, categoryID, companyID, cue, action),
|
||||
kind, cue, action, categoryID, companyID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := d.ExecContext(ctx, `
|
||||
if _, err := q.ExecContext(ctx, `
|
||||
INSERT INTO rsi_lesson_evidence(lesson_id,source_kind,source_id,detail)
|
||||
VALUES($1,$2,$3,$4)
|
||||
ON CONFLICT (lesson_id, source_kind, source_id) DO UPDATE SET
|
||||
detail=EXCLUDED.detail,
|
||||
withdrawn_at=NULL`,
|
||||
ON CONFLICT (lesson_id, source_kind, source_id) WHERE withdrawn_at IS NULL
|
||||
DO UPDATE SET detail=EXCLUDED.detail`,
|
||||
id, sourceKind, sourceID, lessonText(detail, lessonDetailMax)); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -200,7 +268,7 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := d.retractLessonEvidence(ctx, "finding", findingID, "negative", ""); err != nil {
|
||||
if err := retractLessonEvidenceQ(ctx, q, "finding", findingID, "negative", ""); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
case "false_positive", "duplicate", "ignored", "risk_accepted":
|
||||
@@ -218,7 +286,7 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
suffix := " (prior " + status + ")"
|
||||
room := lessonActionMax - utf8.RuneCountInString(prefix) - utf8.RuneCountInString(suffix)
|
||||
action := prefix + lessonText(label, room) + suffix
|
||||
if err := d.retractLessonEvidence(ctx, "finding", findingID, "negative", lessonText(action, lessonActionMax)); err != nil {
|
||||
if err := retractLessonEvidenceQ(ctx, q, "finding", findingID, "negative", lessonText(action, lessonActionMax)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if write {
|
||||
@@ -226,23 +294,23 @@ func (d *DB) ExtractLessonsForTask(ctx context.Context, taskID int64) (int, erro
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
if err := d.retractLessonEvidence(ctx, "finding", findingID, "positive", ""); err != nil {
|
||||
if err := retractLessonEvidenceQ(ctx, q, "finding", findingID, "positive", ""); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := d.retractFindingRetestEvidence(ctx, findingID, "positive"); err != nil {
|
||||
if err := retractFindingRetestEvidenceQ(ctx, q, findingID, "positive"); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := d.retractFindingRetestEvidence(ctx, findingID, "caution"); err != nil {
|
||||
if err := retractFindingRetestEvidenceQ(ctx, q, findingID, "caution"); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(touched), rows.Err()
|
||||
return len(touched), nil
|
||||
}
|
||||
|
||||
func (d *DB) upsertLesson(ctx context.Context, key, kind, cue, action string, categoryID, companyID int64) (int64, error) {
|
||||
func upsertLessonQ(ctx context.Context, q sqlExecQuerier, key, kind, cue, action string, categoryID, companyID int64) (int64, error) {
|
||||
var id int64
|
||||
err := d.QueryRowContext(ctx, `
|
||||
err := q.QueryRowContext(ctx, `
|
||||
INSERT INTO rsi_lessons(dedupe_key,kind,cue,action,category_id,company_id)
|
||||
VALUES($1,$2,$3,$4,NULLIF($5,0),NULLIF($6,0))
|
||||
ON CONFLICT (dedupe_key) DO UPDATE SET
|
||||
@@ -260,14 +328,14 @@ func (d *DB) upsertLesson(ctx context.Context, key, kind, cue, action string, ca
|
||||
return id, err
|
||||
}
|
||||
|
||||
// retractLessonEvidence withdraws this source from lessons of fromKind and
|
||||
// retractLessonEvidenceQ withdraws this source from lessons of fromKind and
|
||||
// retires any of those lessons that now have zero live evidence. The row stays,
|
||||
// with withdrawn_at set, so the lesson still names what it rested on. Shared
|
||||
// lessons that still have other live evidence stay active. A non-empty
|
||||
// keepAction spares lessons with that action, compared without case as the
|
||||
// dedupe key does.
|
||||
func (d *DB) retractLessonEvidence(ctx context.Context, sourceKind string, sourceID int64, fromKind, keepAction string) error {
|
||||
rows, err := d.QueryContext(ctx, `
|
||||
func retractLessonEvidenceQ(ctx context.Context, q sqlExecQuerier, sourceKind string, sourceID int64, fromKind, keepAction string) error {
|
||||
rows, err := q.QueryContext(ctx, `
|
||||
UPDATE rsi_lesson_evidence e
|
||||
SET withdrawn_at=now()
|
||||
FROM rsi_lessons l
|
||||
@@ -285,13 +353,13 @@ func (d *DB) retractLessonEvidence(ctx context.Context, sourceKind string, sourc
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return d.retireLessonsIfEmpty(ctx, ids)
|
||||
return retireLessonsIfEmptyQ(ctx, q, ids)
|
||||
}
|
||||
|
||||
// retractFindingRetestEvidence withdraws every retest of this finding from
|
||||
// retractFindingRetestEvidenceQ withdraws every retest of this finding from
|
||||
// lessons of fromKind, not only the latest row.
|
||||
func (d *DB) retractFindingRetestEvidence(ctx context.Context, findingID int64, fromKind string) error {
|
||||
rows, err := d.QueryContext(ctx, `
|
||||
func retractFindingRetestEvidenceQ(ctx context.Context, q sqlExecQuerier, findingID int64, fromKind string) error {
|
||||
rows, err := q.QueryContext(ctx, `
|
||||
UPDATE rsi_lesson_evidence e
|
||||
SET withdrawn_at=now()
|
||||
FROM rsi_lessons l, finding_retests r
|
||||
@@ -309,7 +377,7 @@ func (d *DB) retractFindingRetestEvidence(ctx context.Context, findingID int64,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return d.retireLessonsIfEmpty(ctx, ids)
|
||||
return retireLessonsIfEmptyQ(ctx, q, ids)
|
||||
}
|
||||
|
||||
func collectLessonIDs(rows *sql.Rows) ([]int64, error) {
|
||||
@@ -332,11 +400,11 @@ func collectLessonIDs(rows *sql.Rows) ([]int64, error) {
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (d *DB) retireLessonsIfEmpty(ctx context.Context, ids []int64) error {
|
||||
func retireLessonsIfEmptyQ(ctx context.Context, q sqlExecQuerier, ids []int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
_, err := d.ExecContext(ctx, `
|
||||
_, err := q.ExecContext(ctx, `
|
||||
UPDATE rsi_lessons l
|
||||
SET status='retired', updated_at=now()
|
||||
WHERE l.id=ANY($1::bigint[])
|
||||
@@ -424,32 +492,47 @@ func (d *DB) LogLessonUsage(ctx context.Context, taskID int64, lessonIDs []int64
|
||||
return nil
|
||||
}
|
||||
|
||||
// syncLessonsForFinding re-runs extraction for the finding's task after a
|
||||
// disposition or retest has committed. A failure is logged and does not undo
|
||||
// the status change. Terminal-status extraction still runs later.
|
||||
func (d *DB) syncLessonsForFinding(ctx context.Context, findingID int64) {
|
||||
// syncLessonsForFindingTx re-runs extraction for the finding's task inside the
|
||||
// caller's transaction so a failure rolls back the status or retest change and
|
||||
// never leaves a stale lesson selectable (#269).
|
||||
func syncLessonsForFindingTx(ctx context.Context, tx *sql.Tx, findingID int64) error {
|
||||
var taskID sql.NullInt64
|
||||
err := d.QueryRowContext(ctx, `SELECT task_id FROM findings WHERE id=$1`, findingID).Scan(&taskID)
|
||||
if err != nil || !taskID.Valid || taskID.Int64 == 0 {
|
||||
return
|
||||
err := tx.QueryRowContext(ctx, `SELECT task_id FROM findings WHERE id=$1`, findingID).Scan(&taskID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
if _, err := d.ExtractLessonsForTask(ctx, taskID.Int64); err != nil {
|
||||
log.Printf("[rsi] lesson extraction failed for task %d: %v", taskID.Int64, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !taskID.Valid || taskID.Int64 == 0 {
|
||||
return nil
|
||||
}
|
||||
_, err = ExtractLessonsForTaskTx(ctx, tx, taskID.Int64)
|
||||
return err
|
||||
}
|
||||
|
||||
// syncLessonsForTasks re-runs extraction once per task.
|
||||
func (d *DB) syncLessonsForTasks(ctx context.Context, taskIDs []int64) {
|
||||
// syncLessonsForFindingsTx re-runs extraction once per distinct task for all
|
||||
// changed findings inside the caller's transaction.
|
||||
func syncLessonsForFindingsTx(ctx context.Context, tx *sql.Tx, findingIDs []int64) error {
|
||||
seen := map[int64]bool{}
|
||||
for _, taskID := range taskIDs {
|
||||
if taskID == 0 || seen[taskID] {
|
||||
for _, fid := range findingIDs {
|
||||
var taskID sql.NullInt64
|
||||
err := tx.QueryRowContext(ctx, `SELECT task_id FROM findings WHERE id=$1`, fid).Scan(&taskID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
continue
|
||||
}
|
||||
seen[taskID] = true
|
||||
if _, err := d.ExtractLessonsForTask(ctx, taskID); err != nil {
|
||||
log.Printf("[rsi] lesson extraction failed for task %d: %v", taskID, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !taskID.Valid || taskID.Int64 == 0 || seen[taskID.Int64] {
|
||||
continue
|
||||
}
|
||||
seen[taskID.Int64] = true
|
||||
if _, err := ExtractLessonsForTaskTx(ctx, tx, taskID.Int64); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RenderLessons builds the prompt block. The text is data, not instructions:
|
||||
|
||||
@@ -2,6 +2,8 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -1482,3 +1484,223 @@ func lessonStatusSupport(t *testing.T, d *DB, lessonID int64) (status string, su
|
||||
}
|
||||
return status, support
|
||||
}
|
||||
|
||||
// Re-confirming a previously withdrawn finding must NOT clear withdrawn_at on
|
||||
// the old evidence row: the withdrawal row stays for history and re-confirmation
|
||||
// inserts a new live row (#269).
|
||||
func TestReconfirmingFindingPreservesWithdrawalHistory(t *testing.T) {
|
||||
d := notifyTestDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
task, err := d.CreateTaskWithOptions("withdraw-history", "test withdrawal history", TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
|
||||
es := d.Exploration(task.ExplorationID)
|
||||
rec, err := es.RecordFinding(ctx, RecordFindingInput{
|
||||
TaskID: task.ID,
|
||||
ExplorationID: task.ExplorationID,
|
||||
VulnClass: "ssrf",
|
||||
Name: "SSRF on webhook",
|
||||
Severity: "high",
|
||||
Summary: "SSRF on webhook endpoint",
|
||||
Worker: "worker-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fid := rec.FindingID
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='finding' AND source_id=$1)`, fid)
|
||||
})
|
||||
|
||||
// 1. Confirm -> positive lesson created with 1 live evidence row.
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingConfirmed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var lessonID, firstRowID int64
|
||||
if err := d.QueryRow(`SELECT e.lesson_id, e.id
|
||||
FROM rsi_lesson_evidence e JOIN rsi_lessons l ON l.id=e.lesson_id
|
||||
WHERE l.kind='positive' AND e.source_kind='finding' AND e.source_id=$1 AND e.withdrawn_at IS NULL`,
|
||||
fid).Scan(&lessonID, &firstRowID); err != nil {
|
||||
t.Fatalf("positive evidence row: %v", err)
|
||||
}
|
||||
|
||||
// 2. Flip to false_positive -> firstRowID gets withdrawn_at set.
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingFalsePositive); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var withdrawnAt1 sql.NullTime
|
||||
if err := d.QueryRow(`SELECT withdrawn_at FROM rsi_lesson_evidence WHERE id=$1`, firstRowID).Scan(&withdrawnAt1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !withdrawnAt1.Valid {
|
||||
t.Fatalf("expected firstRowID=%d to have withdrawn_at set after false_positive", firstRowID)
|
||||
}
|
||||
|
||||
// 3. Re-confirm -> old withdrawal row stays untouched, new live row is inserted.
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingConfirmed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var withdrawnAt2 sql.NullTime
|
||||
if err := d.QueryRow(`SELECT withdrawn_at FROM rsi_lesson_evidence WHERE id=$1`, firstRowID).Scan(&withdrawnAt2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !withdrawnAt2.Valid || !withdrawnAt2.Time.Equal(withdrawnAt1.Time) {
|
||||
t.Fatalf("old withdrawal row %d was altered: got %v, want %v", firstRowID, withdrawnAt2, withdrawnAt1)
|
||||
}
|
||||
|
||||
var secondRowID int64
|
||||
if err := d.QueryRow(`SELECT id FROM rsi_lesson_evidence
|
||||
WHERE lesson_id=$1 AND source_kind='finding' AND source_id=$2 AND withdrawn_at IS NULL`,
|
||||
lessonID, fid).Scan(&secondRowID); err != nil {
|
||||
t.Fatalf("new live evidence row missing after re-confirm: %v", err)
|
||||
}
|
||||
if secondRowID == firstRowID {
|
||||
t.Fatalf("re-confirm reused old row %d instead of inserting a new live row", firstRowID)
|
||||
}
|
||||
|
||||
// 4. Repeat extraction is idempotent: still 1 live + 1 withdrawn row.
|
||||
if _, err := d.ExtractLessonsForTask(ctx, task.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var totalRows, liveRows, withdrawnRows int
|
||||
if err := d.QueryRow(`SELECT COUNT(*), COUNT(*) FILTER (WHERE withdrawn_at IS NULL), COUNT(*) FILTER (WHERE withdrawn_at IS NOT NULL)
|
||||
FROM rsi_lesson_evidence WHERE lesson_id=$1 AND source_kind='finding' AND source_id=$2`,
|
||||
lessonID, fid).Scan(&totalRows, &liveRows, &withdrawnRows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if totalRows != 2 || liveRows != 1 || withdrawnRows != 1 {
|
||||
t.Fatalf("evidence rows = total %d live %d withdrawn %d, want 2 / 1 / 1", totalRows, liveRows, withdrawnRows)
|
||||
}
|
||||
if status, support := lessonStatusSupport(t, d, lessonID); status != "candidate" || support != 1 {
|
||||
t.Fatalf("lesson status=%s support=%d, want candidate / 1", status, support)
|
||||
}
|
||||
}
|
||||
|
||||
// Lesson extraction now runs inside the same transaction as status changes and
|
||||
// retest completion (#269). If extraction fails, the status / retest write
|
||||
// rolls back atomically so the DB never ends up with a flipped finding status
|
||||
// and a stale selectable lesson.
|
||||
func TestLessonExtractionFailureRollsBackStatusAndRetest(t *testing.T) {
|
||||
d := notifyTestDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
task, err := d.CreateTaskWithOptions("lesson-tx-rollback", "test lesson extraction tx rollback", TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
|
||||
es := d.Exploration(task.ExplorationID)
|
||||
rec, err := es.RecordFinding(ctx, RecordFindingInput{
|
||||
TaskID: task.ID,
|
||||
ExplorationID: task.ExplorationID,
|
||||
VulnClass: "sqli",
|
||||
Name: "SQLi in filter",
|
||||
Severity: "high",
|
||||
Summary: "Boolean SQLi in filter param",
|
||||
Worker: "worker-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fid := rec.FindingID
|
||||
t.Cleanup(func() {
|
||||
_, _ = d.Exec(`DELETE FROM rsi_lessons WHERE id IN (SELECT lesson_id FROM rsi_lesson_evidence WHERE source_kind='finding' AND source_id=$1)`, fid)
|
||||
})
|
||||
|
||||
// Seed a confirmed finding and its positive lesson.
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingConfirmed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var posLessonID int64
|
||||
if err := d.QueryRow(`SELECT e.lesson_id
|
||||
FROM rsi_lesson_evidence e JOIN rsi_lessons l ON l.id=e.lesson_id
|
||||
WHERE l.kind='positive' AND e.source_kind='finding' AND e.source_id=$1 AND e.withdrawn_at IS NULL`,
|
||||
fid).Scan(&posLessonID); err != nil {
|
||||
t.Fatalf("positive lesson missing: %v", err)
|
||||
}
|
||||
|
||||
injected := errors.New("injected lesson extraction failure")
|
||||
prevHook := lessonSyncTxTestHook
|
||||
t.Cleanup(func() { lessonSyncTxTestHook = prevHook })
|
||||
|
||||
// 1. Single status path: failure during lesson extraction rolls back status.
|
||||
lessonSyncTxTestHook = func(ctx context.Context, tx *sql.Tx, taskID int64) error { return injected }
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingFalsePositive); !errors.Is(err, injected) {
|
||||
t.Fatalf("single status err=%v, want %v", err, injected)
|
||||
}
|
||||
f, err := d.GetFinding(fid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Status != FindingConfirmed {
|
||||
t.Fatalf("single status leaked %q after rollback, want %q", f.Status, FindingConfirmed)
|
||||
}
|
||||
if status, support := lessonStatusSupport(t, d, posLessonID); status != "candidate" || support != 1 {
|
||||
t.Fatalf("positive lesson after single rollback: status=%s support=%d, want candidate / 1", status, support)
|
||||
}
|
||||
|
||||
// 2. Bulk status path: failure during lesson extraction rolls back status.
|
||||
if _, err := d.SetFindingStatusesWithNotify(ctx, []int64{fid}, FindingFalsePositive); !errors.Is(err, injected) {
|
||||
t.Fatalf("bulk status err=%v, want %v", err, injected)
|
||||
}
|
||||
f, err = d.GetFinding(fid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Status != FindingConfirmed {
|
||||
t.Fatalf("bulk status leaked %q after rollback, want %q", f.Status, FindingConfirmed)
|
||||
}
|
||||
|
||||
// 3. Retest path: failure during lesson extraction rolls back both retest
|
||||
// completion and the finding status transition.
|
||||
lessonSyncTxTestHook = nil
|
||||
retest, conv, _, err := d.CreateFindingRetest(ctx, fid, "verify fix")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteConversation(conv.ID) })
|
||||
if _, err := d.StartFindingRetest(ctx, retest.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.RecordFindingRetestResult(ctx, conv.ID, "fixed", "patched", "verified 400 on payload"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lessonSyncTxTestHook = func(ctx context.Context, tx *sql.Tx, taskID int64) error { return injected }
|
||||
if err := d.FinishFindingRetest(retest.ID, "completed", ""); !errors.Is(err, injected) {
|
||||
t.Fatalf("FinishFindingRetest err=%v, want %v", err, injected)
|
||||
}
|
||||
f, err = d.GetFinding(fid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Status != FindingConfirmed {
|
||||
t.Fatalf("retest status leaked %q after rollback, want %q", f.Status, FindingConfirmed)
|
||||
}
|
||||
var retestStatus string
|
||||
if err := d.QueryRow(`SELECT status FROM finding_retests WHERE id=$1`, retest.ID).Scan(&retestStatus); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if retestStatus == "completed" {
|
||||
t.Fatalf("retest status committed %q despite lesson extraction rollback", retestStatus)
|
||||
}
|
||||
|
||||
// 4. Once extraction succeeds, the status flip and lesson retirement commit together.
|
||||
lessonSyncTxTestHook = nil
|
||||
if _, _, _, err := d.SetFindingStatusWithNotify(ctx, fid, FindingFalsePositive); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err = d.GetFinding(fid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Status != FindingFalsePositive {
|
||||
t.Fatalf("status=%q after retry, want %q", f.Status, FindingFalsePositive)
|
||||
}
|
||||
if status, support := lessonStatusSupport(t, d, posLessonID); status != "retired" || support != 0 {
|
||||
t.Fatalf("positive lesson after FP commit: status=%s support=%d, want retired / 0", status, support)
|
||||
}
|
||||
}
|
||||
|
||||
+14
-5
@@ -139,9 +139,10 @@ func assertEmbeddedApplied(t *testing.T, d *DB) []appliedMigration {
|
||||
}{{1, llmRecordsMigration}, {2, llmUsageMigration}, {3, "0003_task_scope_icp_index.sql"}, {4, "0004_llm_usage_ts_index.sql"},
|
||||
{5, "0005_traffic_rewrite_rules.sql"}, {6, "0006_activity_outbox.sql"}, {7, "0007_finding_report_state.sql"},
|
||||
{8, "0008_traffic_evidence_rewrite_flag.sql"}, {9, "0009_llm_context.sql"}, {10, "0010_dashboard_usage_indexes.sql"},
|
||||
{11, "0011_traffic_tamper_hooks.sql"}, {12, "0012_lesson_withdrawn.sql"}}
|
||||
{11, "0011_traffic_tamper_hooks.sql"}, {12, "0012_lesson_withdrawn.sql"},
|
||||
{13, "0013_lesson_evidence_history.sql"}}
|
||||
if len(applied) != len(want) {
|
||||
t.Fatalf("schema_migrations = %+v, want versions 1 to 12", applied)
|
||||
t.Fatalf("schema_migrations = %+v, want versions 1 to 13", applied)
|
||||
}
|
||||
for i, w := range want {
|
||||
content, err := fs.ReadFile(migrationsFS(), w.name)
|
||||
@@ -432,10 +433,11 @@ func TestLessonWithdrawnMigrationKeepsExistingEvidence(t *testing.T) {
|
||||
}
|
||||
// The migration file alone adds the column to a table without it.
|
||||
for _, q := range []string{
|
||||
`DROP INDEX IF EXISTS uq_rsi_lesson_evidence_live`,
|
||||
`ALTER TABLE rsi_lesson_evidence DROP COLUMN withdrawn_at`,
|
||||
string(migrationSQL),
|
||||
`ALTER TABLE rsi_lesson_evidence DROP COLUMN withdrawn_at`,
|
||||
`DELETE FROM schema_migrations WHERE version=12`,
|
||||
`DELETE FROM schema_migrations WHERE version IN (12, 13)`,
|
||||
`INSERT INTO rsi_lessons(dedupe_key,kind,cue,action,status)
|
||||
VALUES ('legacy-lesson','positive','xss','Confirmed xss: legacy','adopted')`,
|
||||
`INSERT INTO rsi_lesson_evidence(lesson_id,source_kind,source_id,detail)
|
||||
@@ -479,8 +481,15 @@ func TestLessonWithdrawnMigrationKeepsExistingEvidence(t *testing.T) {
|
||||
}
|
||||
check(d)
|
||||
before := readApplied(t, d)
|
||||
if last := before[len(before)-1]; last.version != 12 || last.name != migrationName {
|
||||
t.Fatalf("last applied migration = %+v, want 0012", last)
|
||||
has12 := false
|
||||
for _, m := range before {
|
||||
if m.version == 12 && m.name == migrationName {
|
||||
has12 = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !has12 {
|
||||
t.Fatalf("applied migrations = %+v, missing 0012", before)
|
||||
}
|
||||
d.Close()
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
-- Keep withdrawal history on rsi_lesson_evidence (#269): replace the composite
|
||||
-- primary key (lesson_id, source_kind, source_id) with a surrogate id and a
|
||||
-- partial unique index over live rows (withdrawn_at IS NULL). Re-confirming a
|
||||
-- previously withdrawn finding inserts a new live row while preserving the old
|
||||
-- withdrawal row and its withdrawn_at timestamp.
|
||||
ALTER TABLE rsi_lesson_evidence ADD COLUMN IF NOT EXISTS id BIGSERIAL;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conrelid = 'rsi_lesson_evidence'::regclass
|
||||
AND contype = 'p'
|
||||
AND conname = 'rsi_lesson_evidence_pkey'
|
||||
AND array_length(conkey, 1) > 1
|
||||
) THEN
|
||||
ALTER TABLE rsi_lesson_evidence DROP CONSTRAINT rsi_lesson_evidence_pkey;
|
||||
ALTER TABLE rsi_lesson_evidence ADD PRIMARY KEY (id);
|
||||
END IF;
|
||||
END $$;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_rsi_lesson_evidence_live
|
||||
ON rsi_lesson_evidence(lesson_id, source_kind, source_id)
|
||||
WHERE withdrawn_at IS NULL;
|
||||
+89
-19
@@ -502,15 +502,19 @@ func assetDisplayName(typ, domain, ip, url, appName, bundleID string) string {
|
||||
// already succeeded and the caller must not report an error for it.
|
||||
func (d *DB) SetFindingStatusWithNotify(ctx context.Context, id int64, status string) (from string, found bool, notified bool, err error) {
|
||||
err = d.WithEvidenceTx(ctx, func(tx *sql.Tx) error {
|
||||
var changed bool
|
||||
var txErr error
|
||||
from, found, _, notified, txErr = SetFindingStatusTx(ctx, tx, id, status)
|
||||
return txErr
|
||||
from, found, changed, notified, txErr = SetFindingStatusTx(ctx, tx, id, status)
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
if found && changed {
|
||||
return syncLessonsForFindingTx(ctx, tx, id)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return from, found, notified, err
|
||||
}
|
||||
if found && from != status {
|
||||
d.syncLessonsForFinding(ctx, id)
|
||||
return from, found, false, err
|
||||
}
|
||||
return from, found, notified, nil
|
||||
}
|
||||
@@ -532,33 +536,94 @@ type FindingStatusBatchResult struct {
|
||||
func (d *DB) SetFindingStatusesWithNotify(ctx context.Context, ids []int64, status string) ([]FindingStatusBatchResult, error) {
|
||||
out := make([]FindingStatusBatchResult, 0, len(ids))
|
||||
err := d.WithEvidenceTx(ctx, func(tx *sql.Tx) error {
|
||||
changedIDs := make([]int64, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
from, found, changed, notified, err := SetFindingStatusTx(ctx, tx, id, status)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changed {
|
||||
changedIDs = append(changedIDs, id)
|
||||
}
|
||||
out = append(out, FindingStatusBatchResult{ID: id, From: from, Found: found, Changed: changed, Notified: notified})
|
||||
}
|
||||
return nil
|
||||
return syncLessonsForFindingsTx(ctx, tx, changedIDs)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
taskIDs := make([]int64, 0, len(out))
|
||||
for _, r := range out {
|
||||
if !r.Changed {
|
||||
continue
|
||||
}
|
||||
var taskID sql.NullInt64
|
||||
if err := d.QueryRowContext(ctx, `SELECT task_id FROM findings WHERE id=$1`, r.ID).Scan(&taskID); err != nil || !taskID.Valid {
|
||||
continue
|
||||
}
|
||||
taskIDs = append(taskIDs, taskID.Int64)
|
||||
}
|
||||
d.syncLessonsForTasks(ctx, taskIDs)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GoalInvalidatingFindingStatuses is the single source of truth for finding
|
||||
// triage statuses that mean "not a valid vulnerability" and therefore cannot
|
||||
// prove or keep a goal met (#269). Both db goal-reopen logic and agent
|
||||
// prove_goal checks use this list so they cannot drift.
|
||||
//
|
||||
// FindingRiskAccepted is deliberately excluded: it represents a real finding
|
||||
// whose risk is accepted, not an invalid one, so it may prove a goal and must
|
||||
// never reopen one.
|
||||
var GoalInvalidatingFindingStatuses = []string{
|
||||
FindingFalsePositive,
|
||||
FindingDuplicate,
|
||||
FindingIgnored,
|
||||
}
|
||||
|
||||
// FindingStatusInvalidatesGoal reports whether a finding disposition means the
|
||||
// finding is not a valid vulnerability and therefore cannot prove or keep a
|
||||
// goal met.
|
||||
func FindingStatusInvalidatesGoal(status string) bool {
|
||||
s := strings.ToLower(strings.TrimSpace(status))
|
||||
for _, inv := range GoalInvalidatingFindingStatuses {
|
||||
if s == inv {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// reopenGoalsProvedByNodeTx resets any goal node proved by nodeID back to open
|
||||
// inside the caller's transaction, unless another valid proof still exists for
|
||||
// that goal (a finding whose status is not in GoalInvalidatingFindingStatuses,
|
||||
// or an observed non-target_response non-unverified fact matching prove_goal's
|
||||
// gate). All proves edges are preserved for history; only the goal state changes.
|
||||
func reopenGoalsProvedByNodeTx(ctx context.Context, tx *sql.Tx, nodeID int64) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
UPDATE exploration_nodes g
|
||||
SET state = 'open',
|
||||
blocked_reason = NULL,
|
||||
content_version = content_version + 1
|
||||
FROM exploration_edges e
|
||||
WHERE e.src_id = $1
|
||||
AND e.rel = $2
|
||||
AND g.id = e.dst_id
|
||||
AND g.kind = $3
|
||||
AND g.state = 'met'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM exploration_edges pe
|
||||
JOIN exploration_nodes src ON src.id = pe.src_id
|
||||
WHERE pe.dst_id = g.id
|
||||
AND pe.rel = $2
|
||||
AND src.id <> $1
|
||||
AND (
|
||||
(src.kind = $4 AND EXISTS (
|
||||
SELECT 1
|
||||
FROM findings f
|
||||
WHERE f.node_id = src.id
|
||||
AND NOT (LOWER(BTRIM(f.status)) = ANY($6::text[]))
|
||||
))
|
||||
OR
|
||||
(src.kind = $5
|
||||
AND LOWER(BTRIM(COALESCE(src.payload->>'confidence', ''))) = 'observed'
|
||||
AND LOWER(BTRIM(COALESCE(src.payload->>'source', ''))) <> 'target_response'
|
||||
AND LOWER(BTRIM(COALESCE(src.payload->>'provenance', ''))) <> 'unverified')
|
||||
)
|
||||
)`,
|
||||
nodeID, RelProves, KindGoal, KindFinding, KindFact, GoalInvalidatingFindingStatuses)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetFindingStatusTx updates a finding's status and registers a status-change delivery
|
||||
// event inside the **caller's transaction**.
|
||||
//
|
||||
@@ -602,6 +667,11 @@ FROM findings WHERE id=$1 FOR UPDATE`, id).
|
||||
WHERE id = $2`, status, nodeID.Int64); err != nil {
|
||||
return from, true, false, false, err
|
||||
}
|
||||
if FindingStatusInvalidatesGoal(status) {
|
||||
if err := reopenGoalsProvedByNodeTx(ctx, tx, nodeID.Int64); err != nil {
|
||||
return from, true, false, false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
var assets []int64
|
||||
_ = json.Unmarshal(assetIDs, &assets)
|
||||
|
||||
+8
-6
@@ -1560,19 +1560,21 @@ CREATE TABLE IF NOT EXISTS rsi_lessons (
|
||||
CREATE INDEX IF NOT EXISTS idx_rsi_lessons_scope ON rsi_lessons(company_id, category_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_rsi_lessons_kind ON rsi_lessons(kind, updated_at DESC);
|
||||
|
||||
-- One row per (lesson, source). The primary key makes extraction idempotent:
|
||||
-- a second run for the same task adds nothing and cannot inflate support.
|
||||
-- withdrawn_at keeps a retracted source on the row. Support and selection
|
||||
-- count only rows that are still live.
|
||||
-- Live evidence is unique per (lesson, source) via uq_rsi_lesson_evidence_live,
|
||||
-- making repeated extraction idempotent without inflating support. Withdrawn
|
||||
-- rows keep withdrawn_at set for history; re-confirming inserts a new live row.
|
||||
CREATE TABLE IF NOT EXISTS rsi_lesson_evidence (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
lesson_id BIGINT NOT NULL REFERENCES rsi_lessons(id) ON DELETE CASCADE,
|
||||
source_kind TEXT NOT NULL,
|
||||
source_id BIGINT NOT NULL,
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
withdrawn_at TIMESTAMPTZ,
|
||||
PRIMARY KEY (lesson_id, source_kind, source_id)
|
||||
withdrawn_at TIMESTAMPTZ
|
||||
);
|
||||
ALTER TABLE rsi_lesson_evidence ADD COLUMN IF NOT EXISTS withdrawn_at TIMESTAMPTZ;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_rsi_lesson_evidence_live
|
||||
ON rsi_lesson_evidence(lesson_id, source_kind, source_id)
|
||||
WHERE withdrawn_at IS NULL;
|
||||
|
||||
-- What was shown to which task, and in which mode (shadow = logged but not
|
||||
-- injected; inject = appended to the planner/worker system prompt).
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# ARTEX from the published GHCR image, with the same PostgreSQL service as
|
||||
# docker-compose.yml. Use this file to run and update without a git checkout:
|
||||
#
|
||||
# docker compose -f docker-compose.ghcr.yml pull
|
||||
# docker compose -f docker-compose.ghcr.yml up -d
|
||||
#
|
||||
# Set POSTGRES_PASSWORD in .env. Pin the image with ARTEX_IMAGE_TAG=v0.7.1 in
|
||||
# .env; unset uses latest. The image carries the built-in /app/skills; this file
|
||||
# does not mount a host skills/ directory. To use custom skills, copy them into a
|
||||
# host directory and add `- ./skills:/app/skills` to the artex volumes.
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-artex}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Please set POSTGRES_PASSWORD in .env}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-artex}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-artex} -d ${POSTGRES_DB:-artex}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
restart: unless-stopped
|
||||
|
||||
artex:
|
||||
image: ghcr.io/baarai/artex:${ARTEX_IMAGE_TAG:-latest}
|
||||
# Agent processes run as an unprivileged executor (-exec-uid): no setuid program
|
||||
# or file capability may raise them back to root.
|
||||
security_opt:
|
||||
- "no-new-privileges:true"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
# Parts, not a pasted URL. PostgresDSN percent-encodes the password, so a
|
||||
# value with / ? % @ : or a space still connects.
|
||||
ARTEX_PG_HOST: postgres
|
||||
ARTEX_PG_PORT: "5432"
|
||||
ARTEX_PG_USER: ${POSTGRES_USER:-artex}
|
||||
ARTEX_PG_PASSWORD: ${POSTGRES_PASSWORD:?Please set POSTGRES_PASSWORD in .env}
|
||||
ARTEX_PG_DBNAME: ${POSTGRES_DB:-artex}
|
||||
ARTEX_PG_SSLMODE: disable
|
||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
|
||||
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
|
||||
ARTEX_LLM_PROVIDER: ${ARTEX_LLM_PROVIDER:-}
|
||||
ARTEX_LLM_MODEL: ${ARTEX_LLM_MODEL:-}
|
||||
ARTEX_LLM_BASE_URL: ${ARTEX_LLM_BASE_URL:-}
|
||||
ARTEX_LLM_PROXY: ${ARTEX_LLM_PROXY:-}
|
||||
# Exact host:port list the model-list fetch may reach on private addresses
|
||||
# (e.g. host.docker.internal:11434 for Ollama).
|
||||
ARTEX_LLM_PRIVATE_ENDPOINTS: ${ARTEX_LLM_PRIVATE_ENDPOINTS:-}
|
||||
ARTEX_JWT_KEY_DIR: /app/keys
|
||||
# Optional: key for secrets at rest; empty = keys/secret.key (generated at
|
||||
# first start).
|
||||
ARTEX_SECRET_KEY: ${ARTEX_SECRET_KEY:-}
|
||||
ARTEX_TRUSTED_PROXIES: ${ARTEX_TRUSTED_PROXIES:-}
|
||||
# Untrusted-output boundary: on by default (empty = on); set 0 to disable.
|
||||
ARTEX_UNTRUSTED_BOUNDARY: ${ARTEX_UNTRUSTED_BOUNDARY:-}
|
||||
ARTEX_UPDATE_CHECK: ${ARTEX_UPDATE_CHECK:-}
|
||||
# Noise profile for target requests: off (default) | quiet | balanced | aggressive.
|
||||
ARTEX_NOISE_PROFILE: ${ARTEX_NOISE_PROFILE:-}
|
||||
ARTEX_TARGET_USER_AGENT: ${ARTEX_TARGET_USER_AGENT:-}
|
||||
# Hierarchical run budgets: unset or 0 = unlimited. See README.
|
||||
ARTEX_TASK_BUDGET_TOKENS: ${ARTEX_TASK_BUDGET_TOKENS:-}
|
||||
ARTEX_TASK_BUDGET_TURNS: ${ARTEX_TASK_BUDGET_TURNS:-}
|
||||
ARTEX_INTENT_BUDGET_TOKENS: ${ARTEX_INTENT_BUDGET_TOKENS:-}
|
||||
ARTEX_INTENT_BUDGET_TURNS: ${ARTEX_INTENT_BUDGET_TURNS:-}
|
||||
ports:
|
||||
- "${ARTEX_BIND_ADDR:-127.0.0.1}:8787:8787"
|
||||
- "127.0.0.1:8788:8788"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./keys:/app/keys
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
+9
-1
@@ -31,7 +31,15 @@ services:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
ARTEX_PG_DSN: postgres://${POSTGRES_USER:-artex}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-artex}?sslmode=disable
|
||||
# Parts, not a pasted URL. PostgresDSN percent-encodes the password, so a
|
||||
# value with / ? % @ : or a space still connects. ARTEX_PG_DSN, when set,
|
||||
# would override these and is responsible for its own escaping.
|
||||
ARTEX_PG_HOST: postgres
|
||||
ARTEX_PG_PORT: "5432"
|
||||
ARTEX_PG_USER: ${POSTGRES_USER:-artex}
|
||||
ARTEX_PG_PASSWORD: ${POSTGRES_PASSWORD:?Please set POSTGRES_PASSWORD in .env}
|
||||
ARTEX_PG_DBNAME: ${POSTGRES_DB:-artex}
|
||||
ARTEX_PG_SSLMODE: disable
|
||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
|
||||
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
|
||||
ARTEX_LLM_PROVIDER: ${ARTEX_LLM_PROVIDER:-}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ boundary and trusted proxies. No password or token value is ever logged there.
|
||||
| Setting | Resolution order | Code |
|
||||
| --- | --- | --- |
|
||||
| Config file | `ARTEX_CONFIG` → `./config.json` → `config.json` next to the binary | `config.Path` |
|
||||
| PostgreSQL DSN | `ARTEX_PG_DSN` → `database.dsn` → assembled `host/port/user/password/dbname` | `config.PostgresDSN` |
|
||||
| PostgreSQL DSN | `ARTEX_PG_DSN` → `ARTEX_PG_HOST` / `ARTEX_PG_PORT` / `ARTEX_PG_USER` / `ARTEX_PG_PASSWORD` / `ARTEX_PG_DBNAME` / `ARTEX_PG_SSLMODE` → `database.dsn` → assembled `host/port/user/password/dbname` | `config.PostgresDSN` |
|
||||
| Skill directory | `ARTEX_SKILL_DIR` → `skill_dir` → `<binary dir>/skills` | `config.SkillDir` |
|
||||
| JWT / secret key directory | `ARTEX_JWT_KEY_DIR` → `<binary dir>` (never the browsable data dir) | `config.KeyDir` |
|
||||
| Secret encryption key | `ARTEX_SECRET_KEY` → `<key dir>/secret.key` → newly generated key file | `db.InitSecrets` |
|
||||
|
||||
+50
-2
@@ -29,8 +29,10 @@ ensure_docker(){
|
||||
case "$(uname -s)" in
|
||||
Linux)
|
||||
if [ "$(ask 'Install Docker automatically? (y/n)' y)" = y ]; then
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
install_docker_linux
|
||||
sudo usermod -aG docker "$USER" || true
|
||||
docker compose version >/dev/null 2>&1 || sudo docker compose version >/dev/null 2>&1 \
|
||||
|| die "docker installed but 'docker compose' is unavailable; install the compose v2 plugin and retry"
|
||||
ok "Docker installed (re-login required for the group change to take effect)"
|
||||
else
|
||||
die "please install docker yourself and retry"
|
||||
@@ -40,6 +42,52 @@ ensure_docker(){
|
||||
esac
|
||||
}
|
||||
|
||||
# install_docker_linux uses get.docker.com only on the distros it supports. That
|
||||
# script keys its repo URL off /etc/os-release ID + codename, so on derivatives
|
||||
# such as Kali it writes a repo for a nonexistent release (debian kali-rolling)
|
||||
# and leaves apt broken. Other apt-based distros get the distro's own packages.
|
||||
install_docker_linux(){
|
||||
local id="" id_like=""
|
||||
if [ -r /etc/os-release ]; then
|
||||
id="$(. /etc/os-release && echo "${ID:-}")"
|
||||
id_like="$(. /etc/os-release && echo "${ID_LIKE:-}")"
|
||||
fi
|
||||
case "$id" in
|
||||
ubuntu|debian|raspbian|centos|fedora|rhel|sles)
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
return ;;
|
||||
esac
|
||||
command -v apt-get >/dev/null 2>&1 \
|
||||
|| die "automatic Docker install is not supported on '${id:-unknown}'; please install docker + the compose plugin yourself and retry"
|
||||
info "'${id:-unknown}' (like: ${id_like:-n/a}) is not supported by get.docker.com; installing from the distro's apt repos"
|
||||
# Drop a broken repo left by an earlier get.docker.com run (it fails every apt update).
|
||||
# Match the URI and the distro id anywhere in the file: in a one-line .list entry
|
||||
# they share a line, but in a deb822 .sources file the URIs and Suites fields are
|
||||
# on separate lines. -w keeps "kali" matching inside "kali-rolling".
|
||||
local f
|
||||
for f in /etc/apt/sources.list.d/docker.list /etc/apt/sources.list.d/docker.sources; do
|
||||
if [ -n "$id" ] && [ -f "$f" ] \
|
||||
&& grep -qF "download.docker.com/linux/debian" "$f" 2>/dev/null \
|
||||
&& grep -qwF "$id" "$f" 2>/dev/null; then
|
||||
warn "removing broken Docker repo $f"
|
||||
sudo rm -f "$f"
|
||||
fi
|
||||
done
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io
|
||||
# The compose v2 package name varies across Debian derivatives; take the first that exists.
|
||||
local p
|
||||
for p in docker-compose-plugin docker-compose-v2 docker-compose; do
|
||||
if apt-cache madison "$p" 2>/dev/null | grep -q .; then
|
||||
sudo apt-get install -y "$p" && break
|
||||
fi
|
||||
done
|
||||
# Kali (and some others) don't start services on package install.
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
sudo systemctl enable --now docker || true
|
||||
fi
|
||||
}
|
||||
|
||||
# ── 1) All-Docker ───────────────────────────────
|
||||
install_docker(){
|
||||
ensure_docker
|
||||
@@ -107,7 +155,7 @@ JSON
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
info "building frontend static assets..."
|
||||
( cd web && npm ci --ignore-scripts && npm run build:static )
|
||||
rm -rf server/webui/dist && cp -r web/out server/webui/dist
|
||||
rm -rf server/webui/dist && mkdir -p server/webui && cp -r web/out server/webui/dist
|
||||
info "compiling embedded single binary..."
|
||||
CGO_ENABLED=0 go build -tags embedui -trimpath -o artex ./cmd/artex
|
||||
else
|
||||
|
||||
@@ -104,6 +104,10 @@ var notifyTransport = func() *http.Transport {
|
||||
return &http.Transport{}
|
||||
}
|
||||
clone := t.Clone()
|
||||
// Clone keeps ProxyFromEnvironment. The dial would then be to the proxy, so
|
||||
// blockInternalDial would see the proxy address and a link-local target
|
||||
// could still be reached through it. Notifications go direct.
|
||||
clone.Proxy = nil
|
||||
clone.DialContext = (&net.Dialer{Timeout: 10 * time.Second, Control: blockInternalDial}).DialContext
|
||||
return clone
|
||||
}()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package notify
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNotifyTransportIgnoresEnvironmentProxy(t *testing.T) {
|
||||
if notifyTransport.Proxy != nil {
|
||||
t.Fatal("notification transport must dial the target, not an environment proxy")
|
||||
}
|
||||
}
|
||||
@@ -223,6 +223,7 @@ func seedPrompts(pg *db.DB) {
|
||||
// and default params get injected. MCP/skill/host tools have no row and pass through.
|
||||
func wireTools(pg *db.DB, domainReg map[string]actool.CoreTool) {
|
||||
agent.SetFindingTrafficBindingEnabled(func() bool { return pg.GetBool(settingAgentTrafficBinding, false) })
|
||||
agent.SetTrafficCaptureEnabled(func() bool { return pg.GetBool(settingTrafficCapture, false) })
|
||||
// Seed the built-in domain tools (first-insert only; DO NOTHING preserves edits).
|
||||
// No startup prune: rows we didn't seed are left alone so future user-defined
|
||||
// custom tools (system=false, added via the UI) survive restarts.
|
||||
|
||||
+31
-8
@@ -21,6 +21,10 @@ const (
|
||||
// Allow multipart headers and boundaries in addition to the file data.
|
||||
chatUploadMultipartOverhead = 1 << 20 // 1 MiB
|
||||
chatUploadLimitMessage = "files exceed the 512 MiB upload limit"
|
||||
// maxUploadNameTries bounds the name-1, name-2, … search. A Stat error that
|
||||
// is not "not exist" (a component the filesystem rejects) must stop the
|
||||
// search instead of spinning.
|
||||
maxUploadNameTries = 10000
|
||||
)
|
||||
|
||||
// safeChatID guards the {id} path segment against traversal — task ids are numeric,
|
||||
@@ -123,7 +127,11 @@ func (s *Server) chatUpload(w http.ResponseWriter, r *http.Request) {
|
||||
if name == "" || name == "." || name == ".." || strings.ContainsAny(name, `/\`) {
|
||||
continue
|
||||
}
|
||||
dest := uniqueUploadPath(dir, name)
|
||||
dest, err := uniqueUploadPath(dir, name)
|
||||
if err != nil {
|
||||
writeErr(w, 500, "Save failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
if err := saveUpload(hdr, dest); err != nil {
|
||||
writeErr(w, 500, "Save failed: "+err.Error())
|
||||
return
|
||||
@@ -136,19 +144,34 @@ func (s *Server) chatUpload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// uniqueUploadPath returns dir/name, or dir/name-1, dir/name-2… when it already exists,
|
||||
// so re-uploading the same filename never clobbers a prior attachment.
|
||||
func uniqueUploadPath(dir, name string) string {
|
||||
dest := filepath.Join(dir, name)
|
||||
if _, err := os.Stat(dest); os.IsNotExist(err) {
|
||||
return dest
|
||||
func uniqueUploadPath(dir, name string) (string, error) {
|
||||
if dest, ok, err := uploadPathFree(filepath.Join(dir, name)); err != nil || ok {
|
||||
return dest, err
|
||||
}
|
||||
ext := filepath.Ext(name)
|
||||
stem := strings.TrimSuffix(name, ext)
|
||||
for i := 1; ; i++ {
|
||||
for i := 1; i <= maxUploadNameTries; i++ {
|
||||
cand := filepath.Join(dir, fmt.Sprintf("%s-%d%s", stem, i, ext))
|
||||
if _, err := os.Stat(cand); os.IsNotExist(err) {
|
||||
return cand
|
||||
dest, ok, err := uploadPathFree(cand)
|
||||
if err != nil || ok {
|
||||
return dest, err
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no free name for upload %q", name)
|
||||
}
|
||||
|
||||
// uploadPathFree reports whether path can be created. ok is false when a file
|
||||
// or a symlink (including a dangling one) is already there. Any other Lstat
|
||||
// error is returned so the caller stops.
|
||||
func uploadPathFree(path string) (dest string, ok bool, err error) {
|
||||
_, err = os.Lstat(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return path, true, nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
// composeAgentMessage appends an attachment manifest to the user's message so the agent
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUniqueUploadPathSuffixesCollisions(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "note.txt"), []byte("a"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "note-1.txt"), []byte("b"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := uniqueUploadPath(dir, "note.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if filepath.Base(got) != "note-2.txt" {
|
||||
t.Fatalf("got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniqueUploadPathStopsOnUnstorableName(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
name := strings.Repeat("a", 300) + ".txt"
|
||||
if _, err := uniqueUploadPath(dir, name); err == nil {
|
||||
t.Fatal("an overlong file name must not be searched forever")
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -3,7 +3,9 @@ package server
|
||||
import "os"
|
||||
|
||||
// secretEnv lists the credentials read from the environment only at startup:
|
||||
// ARTEX_PG_DSN and ARTEX_SECRET_KEY by NewManager, the API keys by agent.FromEnv inside New.
|
||||
// ARTEX_PG_DSN and ARTEX_PG_PASSWORD by NewManager (the password is a separate
|
||||
// variable so Docker Compose does not paste it into a URL), ARTEX_SECRET_KEY,
|
||||
// and the API keys by agent.FromEnv inside New.
|
||||
// agent.FromEnv also reads ARTEX_LLM_PROXY and ARTEX_LLM_BASE_URL: both are URLs that
|
||||
// can carry credentials in their userinfo (http://user:pass@proxy:3128). The archive
|
||||
// store also captures ARTEX_ARCHIVE_S3_* credentials during New, before the scrub,
|
||||
@@ -16,7 +18,7 @@ import "os"
|
||||
// credentials or config file, or from the instance metadata service, are not in
|
||||
// the environment: the scrub does not hide them from child processes.
|
||||
var secretEnv = []string{
|
||||
"ARTEX_PG_DSN", "ARTEX_SECRET_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY",
|
||||
"ARTEX_PG_DSN", "ARTEX_PG_PASSWORD", "ARTEX_SECRET_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY",
|
||||
"ARTEX_LLM_PROXY", "ARTEX_LLM_BASE_URL",
|
||||
"ARTEX_ARCHIVE_S3_ACCESS_KEY_ID", "ARTEX_ARCHIVE_S3_SECRET_ACCESS_KEY", "ARTEX_ARCHIVE_S3_SESSION_TOKEN",
|
||||
"AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY", "AWS_SECRET_ACCESS_KEY", "AWS_SECRET_KEY", "AWS_SESSION_TOKEN",
|
||||
|
||||
+3
-2
@@ -13,8 +13,9 @@ import (
|
||||
|
||||
// Sealing the server environment. ScrubSecretEnv removes the secrets from the Go
|
||||
// environment, but the kernel keeps the environment block the process was executed
|
||||
// with: /proc/<pid>/environ still shows ARTEX_PG_DSN, ARTEX_SECRET_KEY and the API
|
||||
// keys to any process that can read it. SealProcessEnv re-executes the server once,
|
||||
// with: /proc/<pid>/environ still shows ARTEX_PG_DSN, ARTEX_PG_PASSWORD,
|
||||
// ARTEX_SECRET_KEY and the API keys to any process that can read it.
|
||||
// SealProcessEnv re-executes the server once,
|
||||
// with those variables left out of the block; the values travel to the new image
|
||||
// through an inherited pipe and are put back into the Go environment there, so the
|
||||
// readers that run next see the same configuration.
|
||||
|
||||
@@ -51,6 +51,7 @@ func TestSealedEnvironmentHandoff(t *testing.T) {
|
||||
}
|
||||
want := map[string]string{
|
||||
"ARTEX_PG_DSN": "postgres://artex:p@ss@db.internal/artex?sslmode=disable\nsecond line\twith tab",
|
||||
"ARTEX_PG_PASSWORD": "p/ss w@rd?#%",
|
||||
"ARTEX_SECRET_KEY": "",
|
||||
"ANTHROPIC_API_KEY": "sk-ant-test",
|
||||
"OPENAI_API_KEY": "=leading-equals",
|
||||
|
||||
+8
-9
@@ -152,9 +152,15 @@ func (s *logSinkT) add(l LogLine) {
|
||||
s.ring = s.ring[len(s.ring)-s.cap:]
|
||||
}
|
||||
ch := s.dbCh
|
||||
subs := make([]chan LogLine, 0, len(s.subs))
|
||||
// Fan-out stays under the lock. subscribe's cancel removes the channel and
|
||||
// then closes it; a send on a closed channel panics even inside select, so
|
||||
// the send and the close must not interleave. The send does not block: a
|
||||
// full buffer drops the line.
|
||||
for sub := range s.subs {
|
||||
subs = append(subs, sub)
|
||||
select {
|
||||
case sub <- l:
|
||||
default:
|
||||
}
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
@@ -165,13 +171,6 @@ func (s *logSinkT) add(l LogLine) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
for _, sub := range subs {
|
||||
select {
|
||||
case sub <- l:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// recent returns ring lines with Seq > since (capped to limit), and the latest seq.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLogSinkUnsubscribeDuringAddDoesNotPanic(t *testing.T) {
|
||||
s := &logSinkT{cap: 8, subs: map[chan LogLine]struct{}{}, out: io.Discard}
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 32; i++ {
|
||||
_, unsub := s.subscribe()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
unsub()
|
||||
}()
|
||||
s.add(LogLine{Text: "line"})
|
||||
}
|
||||
wg.Wait()
|
||||
s.add(LogLine{Text: "after"})
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRefuseUploadSymlink(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
target := filepath.Join(dir, "secret")
|
||||
if err := os.WriteFile(target, []byte("keep"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
link := filepath.Join(dir, "upload")
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
t.Skipf("symlink: %v", err)
|
||||
}
|
||||
if err := refuseUploadSymlink(link); err == nil {
|
||||
t.Fatal("symlink destination was accepted")
|
||||
}
|
||||
body, err := os.ReadFile(target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(body) != "keep" {
|
||||
t.Fatalf("target changed to %q", body)
|
||||
}
|
||||
missing := filepath.Join(dir, "fresh")
|
||||
if err := refuseUploadSymlink(missing); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
+23
-1
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@@ -340,12 +341,15 @@ func (s *Server) wsUpload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func saveUpload(hdr *multipart.FileHeader, dest string) error {
|
||||
if err := refuseUploadSymlink(dest); err != nil {
|
||||
return err
|
||||
}
|
||||
src, err := hdr.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
out, err := os.Create(dest)
|
||||
out, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -354,6 +358,24 @@ func saveUpload(hdr *multipart.FileHeader, dest string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// refuseUploadSymlink rejects a destination that is already a symlink. os.Create
|
||||
// follows one, including a dangling link that Stat reports as missing, so an
|
||||
// agent that can write the uploads directory could aim the server's write at
|
||||
// another path. Lstat sees the link itself.
|
||||
func refuseUploadSymlink(dest string) error {
|
||||
fi, err := os.Lstat(dest)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if fi.Mode()&os.ModeSymlink != 0 {
|
||||
return fmt.Errorf("refusing to write through a symlink")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanitizeFilename strips characters unsafe for a Content-Disposition filename token.
|
||||
func sanitizeFilename(name string) string {
|
||||
name = strings.ReplaceAll(name, "\"", "")
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package traffic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSpillBlobIsOwnerOnly(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
tr := &Traffic{dir: dir}
|
||||
body := bytes.Repeat([]byte("a"), maxInlineBody+1)
|
||||
got := tr.spill(body, "text/plain")
|
||||
if got.hash == "" {
|
||||
t.Fatal("expected a spilled blob")
|
||||
}
|
||||
blobDir := filepath.Join(dir, "_blobs", "sha256", got.hash[:2])
|
||||
blobPath := filepath.Join(blobDir, got.hash+".bin")
|
||||
info, err := os.Stat(blobPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dirInfo, err := os.Stat(blobDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
if info.Mode().Perm() != 0o600 {
|
||||
t.Fatalf("blob mode %o, want 0600", info.Mode().Perm())
|
||||
}
|
||||
if dirInfo.Mode().Perm() != 0o700 {
|
||||
t.Fatalf("blob dir mode %o, want 0700", dirInfo.Mode().Perm())
|
||||
}
|
||||
}
|
||||
@@ -330,24 +330,30 @@ func (e *vm) execRange(s *ast.RangeStmt, sc *env) (flowSignal, any) {
|
||||
var items []kvPair
|
||||
switch 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, nil
|
||||
|
||||
@@ -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 hook
|
||||
func OnRequest(req *Request) error {
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ func (t *Traffic) spillRawDir(data []byte, previewCap int) (preview []byte, blob
|
||||
sum := sha256.Sum256(data)
|
||||
h := hex.EncodeToString(sum[:])
|
||||
blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2])
|
||||
if err := os.MkdirAll(blobDir, 0o755); err != nil {
|
||||
if err := os.MkdirAll(blobDir, 0o700); err != nil {
|
||||
log.Printf("[traffic/socks5] failed to create blob directory: %v", err)
|
||||
return append([]byte(nil), data[:previewCap]...), ""
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func writeBlobAtomic(blobDir, blobPath, hash string, data []byte) error {
|
||||
_ = tmp.Close()
|
||||
return err
|
||||
}
|
||||
if err := tmp.Chmod(0o644); err != nil {
|
||||
if err := tmp.Chmod(0o600); err != nil {
|
||||
_ = tmp.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
+7
-2
@@ -873,16 +873,21 @@ func (t *Traffic) spillAt(body []byte, contentType string, maxInline int) stored
|
||||
// One bucket level (256 buckets) is enough to keep any single directory small;
|
||||
// the store only ever holds bodies above maxInlineBody, deduplicated by hash.
|
||||
blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2])
|
||||
if err := os.MkdirAll(blobDir, 0o755); err != nil {
|
||||
if err := os.MkdirAll(blobDir, 0o700); err != nil {
|
||||
log.Printf("[traffic] failed to create blob directory: %v", err)
|
||||
return storedBody{inline: clipBytes(body, blobPreview), index: indexText()}
|
||||
}
|
||||
if err := os.Chmod(blobDir, 0o700); err != nil {
|
||||
log.Printf("[traffic] failed to restrict blob directory: %v", err)
|
||||
}
|
||||
blobPath := filepath.Join(blobDir, h+".bin")
|
||||
if _, err := os.Stat(blobPath); os.IsNotExist(err) {
|
||||
if err := os.WriteFile(blobPath, body, 0o644); err != nil {
|
||||
if err := os.WriteFile(blobPath, body, 0o600); err != nil {
|
||||
log.Printf("[traffic] failed to write blob %s: %v", h, err)
|
||||
return storedBody{inline: clipBytes(body, blobPreview), index: indexText()}
|
||||
}
|
||||
} else if err := os.Chmod(blobPath, 0o600); err != nil {
|
||||
log.Printf("[traffic] failed to restrict blob %s: %v", h, err)
|
||||
}
|
||||
sb := storedBody{hash: h, index: indexText()}
|
||||
if text {
|
||||
|
||||
@@ -57,7 +57,7 @@ update_local(){
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
info "Rebuilding frontend static assets…"
|
||||
( cd web && npm ci --ignore-scripts && npm run build:static )
|
||||
rm -rf server/webui/dist && cp -r web/out server/webui/dist
|
||||
rm -rf server/webui/dist && mkdir -p server/webui && cp -r web/out server/webui/dist
|
||||
info "Recompiling the embedded single binary…"
|
||||
CGO_ENABLED=0 go build -tags embedui -trimpath -o artex ./cmd/artex
|
||||
else
|
||||
|
||||
@@ -139,6 +139,9 @@ export default function SetupPage() {
|
||||
>
|
||||
{loading ? t("Saving...") : t("Set password and sign in")}
|
||||
</Button>
|
||||
<p className="rounded-md border bg-muted/40 px-3 py-2 text-xs text-muted-foreground">
|
||||
{t("Traffic capture is off by default. Enable it in System settings after setup if you need provable HTTP findings — captured traffic is required for findings to prove goals.")}
|
||||
</p>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -572,7 +572,9 @@ export default function DashboardPage() {
|
||||
<span>{t("Recording")}</span>
|
||||
</>
|
||||
) : (
|
||||
<span>{t("Capture is off")}</span>
|
||||
<Link href="/system/settings" className="text-amber-500 hover:underline">
|
||||
{t("Capture is off · required for provable findings")}
|
||||
</Link>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -1164,19 +1166,29 @@ export default function DashboardPage() {
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between rounded-lg border bg-muted/20 px-3 py-2">
|
||||
<div className="text-[10px] text-muted-foreground">{t("Traffic capture")}</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"text-[10px]",
|
||||
settings?.traffic_capture
|
||||
? "border-violet-500/30 bg-violet-500/10 text-violet-400"
|
||||
: "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{settings?.traffic_capture ? t("On") : t("Off")}
|
||||
</Badge>
|
||||
<div className="rounded-lg border bg-muted/20 px-3 py-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-[10px] text-muted-foreground">{t("Traffic capture")}</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"text-[10px]",
|
||||
settings?.traffic_capture
|
||||
? "border-violet-500/30 bg-violet-500/10 text-violet-400"
|
||||
: "border-amber-500/30 bg-amber-500/10 text-amber-500",
|
||||
)}
|
||||
>
|
||||
{settings?.traffic_capture ? t("On") : t("Off")}
|
||||
</Badge>
|
||||
</div>
|
||||
{settings && !settings.traffic_capture && (
|
||||
<p className="mt-1.5 text-[10px] leading-relaxed text-amber-500">
|
||||
{t("Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.")}{" "}
|
||||
<Link href="/system/settings" className="underline">
|
||||
{t("Enable in settings")}
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{activeProfile && (
|
||||
|
||||
@@ -320,16 +320,23 @@ export default function SystemSettingsPage() {
|
||||
)}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex items-center justify-between gap-4">
|
||||
<Label htmlFor="traffic-capture" className="text-sm font-normal text-muted-foreground">
|
||||
{trafficCapture ? t("On · recording traffic and injecting proxy") : t("Off · no recording, no proxy injection")}
|
||||
</Label>
|
||||
<Switch
|
||||
id="traffic-capture"
|
||||
checked={trafficCapture}
|
||||
disabled={!loaded || saving}
|
||||
onCheckedChange={toggleTraffic}
|
||||
/>
|
||||
<CardContent className="space-y-2.5">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<Label htmlFor="traffic-capture" className="text-sm font-normal text-muted-foreground">
|
||||
{trafficCapture ? t("On · recording traffic and injecting proxy") : t("Off · no recording, no proxy injection")}
|
||||
</Label>
|
||||
<Switch
|
||||
id="traffic-capture"
|
||||
checked={trafficCapture}
|
||||
disabled={!loaded || saving}
|
||||
onCheckedChange={toggleTraffic}
|
||||
/>
|
||||
</div>
|
||||
{loaded && !trafficCapture && (
|
||||
<p className="rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-600 dark:text-amber-400">
|
||||
{t("Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.")}
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -2709,5 +2709,9 @@
|
||||
"Hashes": "Özetler",
|
||||
"Masked (HMAC)": "Maskeli (HMAC)",
|
||||
"Resulting request": "Ortaya çıkan istek",
|
||||
"Resulting response": "Ortaya çıkan yanıt"
|
||||
"Resulting response": "Ortaya çıkan yanıt",
|
||||
"Traffic capture is off by default. Enable it in System settings after setup if you need provable HTTP findings — captured traffic is required for findings to prove goals.": "Trafik yakalama varsayılan olarak kapalıdır. Kanıtlanabilir HTTP bulguları gerekiyorsa kurulumdan sonra Sistem ayarlarından etkinleştirin — bulguların hedefleri kanıtlaması için yakalanmış trafik gereklidir.",
|
||||
"Capture is off · required for provable findings": "Yakalama kapalı · kanıtlanabilir bulgular için gerekli",
|
||||
"Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.": "Trafik yakalama kapalı: bulgular kaydedilmeye devam eder ancak kanıtlanabilir bulgular için yakalanmış HTTP trafiği gereklidir.",
|
||||
"Enable in settings": "Ayarlardan etkinleştir"
|
||||
}
|
||||
|
||||
@@ -2709,5 +2709,9 @@
|
||||
"Hashes": "哈希",
|
||||
"Masked (HMAC)": "已脱敏 (HMAC)",
|
||||
"Resulting request": "结果请求",
|
||||
"Resulting response": "结果响应"
|
||||
"Resulting response": "结果响应",
|
||||
"Traffic capture is off by default. Enable it in System settings after setup if you need provable HTTP findings — captured traffic is required for findings to prove goals.": "流量捕获默认关闭。如需可证明的 HTTP 漏洞发现,请在初始化后前往系统设置开启——漏洞证明目标需要已捕获的 HTTP 流量。",
|
||||
"Capture is off · required for provable findings": "捕获已关闭 · 可证明漏洞所需",
|
||||
"Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.": "流量捕获已关闭:漏洞仍会被记录,但证明目标需要已捕获的 HTTP 流量。",
|
||||
"Enable in settings": "前往设置开启"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user