mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
)
|
|
|
|
func TestCORSVerificationRejectsInvalidBoundProof(t *testing.T) {
|
|
s, finding, request := trafficEvidenceServer(t)
|
|
if _, err := s.m.pg.Exec(`UPDATE findings SET vulnclass='CORS' WHERE id=$1`, finding.FindingID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
trafficID := "cors-invalid-proof"
|
|
_, err := s.m.traffic.DB().Exec(`INSERT INTO exchanges(id,ts,host,method,url_template,url,status,content_type,req_len,resp_len,path)
|
|
VALUES(?,1,'evidence.local','GET','/','https://evidence.local/',200,'text/plain',0,?,'')`, trafficID, len("cors proof body"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = s.m.traffic.DB().Exec(`INSERT INTO exchange_bodies(id,req_head,resp_head,req_body,resp_body)
|
|
VALUES(?, ?, ?, ?, ?)`, trafficID,
|
|
"GET / HTTP/1.1\nOrigin: https://evil.com\n",
|
|
"HTTP/1.1 200 OK\nAccess-Control-Allow-Origin: https://other.example\n",
|
|
[]byte{}, []byte("cors proof body"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bindPath := fmt.Sprintf("/api/exploration/findings/%d/traffic", finding.FindingID)
|
|
if w := request("POST", bindPath, fmt.Sprintf(`{"traffic_refs":[{"traffic_id":%q,"role":"proof"}]}`, trafficID)); w.Code != 200 {
|
|
t.Fatalf("bind: %d %s", w.Code, w.Body)
|
|
}
|
|
msg, isErr := updateReport(t, s, finding.NodeID, `,"poe_level":3,"evidence_quotes":["cors proof body"]`)
|
|
if isErr || !strings.Contains(msg, "verification: unverified") {
|
|
t.Fatalf("unexpected result: err=%v %q", isErr, msg)
|
|
}
|
|
status, _, note, report := storedVerification(t, s, finding.FindingID)
|
|
if status != db.VerificationUnverified || !strings.Contains(note, "CORS proof validation failed") || report == "" {
|
|
t.Fatalf("stored: status=%s note=%q report=%q", status, note, report)
|
|
}
|
|
}
|