@@ -48,9 +48,24 @@ func TestExtractSpogHeaders(t *testing.T) {
4848 want : map [string ]string {"x-databricks-org-id" : "12345" },
4949 },
5050 {
51- name : "first o= wins when duplicated" ,
52- httpPath : "/sql/1.0/warehouses/abc?o=first&o=second" ,
53- want : map [string ]string {"x-databricks-org-id" : "first" },
51+ name : "first numeric o= wins when duplicated" ,
52+ httpPath : "/sql/1.0/warehouses/abc?o=111&o=222" ,
53+ want : map [string ]string {"x-databricks-org-id" : "111" },
54+ },
55+ {
56+ name : "non-numeric o= value returns nil" ,
57+ httpPath : "/sql/1.0/warehouses/abc?o=abc123" ,
58+ want : nil ,
59+ },
60+ {
61+ name : "control-character o= value returns nil" ,
62+ httpPath : "/sql/1.0/warehouses/abc?o=123%0D%0AX-Injected:%20yes" ,
63+ want : nil ,
64+ },
65+ {
66+ name : "invalid o= falls back to valid cluster path segment" ,
67+ httpPath : "sql/protocolv1/o/6051921418418893/0528-220959-uzmcn1qt?o=abc123" ,
68+ want : map [string ]string {"x-databricks-org-id" : "6051921418418893" },
5469 },
5570 {
5671 name : "just ? with nothing after returns nil" ,
@@ -75,6 +90,21 @@ func TestExtractSpogHeaders(t *testing.T) {
7590 httpPath : "sql/protocolv1/o/111/0528-220959-uzmcn1qt?o=222" ,
7691 want : map [string ]string {"x-databricks-org-id" : "222" },
7792 },
93+ {
94+ name : "nested cluster path prefix returns nil" ,
95+ httpPath : "evil/sql/protocolv1/o/999/0528-220959-uzmcn1qt" ,
96+ want : nil ,
97+ },
98+ {
99+ name : "incomplete cluster path returns nil" ,
100+ httpPath : "sql/protocolv1/o/999/" ,
101+ want : nil ,
102+ },
103+ {
104+ name : "warehouse path containing cluster-looking suffix returns nil" ,
105+ httpPath : "/sql/1.0/warehouses/sql/protocolv1/o/999/cluster-id" ,
106+ want : nil ,
107+ },
78108 {
79109 // Regression guard: the new cluster-path regex must not match
80110 // warehouse paths (which never embed the workspace ID).
0 commit comments