Skip to content

Commit d436af8

Browse files
committed
fix(policy): avoid graphql persisted deny reason conflicts
1 parent cfca5ba commit d436af8

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

crates/openshell-sandbox/data/sandbox-policy.rego

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ request_deny_reason := reason if {
324324
input.request
325325
deny_request
326326
graphql_request_has_operations(input.request)
327+
not graphql_request_has_unregistered_persisted_query(input.request, matched_endpoint_config)
327328
reason := "GraphQL operation blocked by endpoint policy"
328329
}
329330

crates/openshell-sandbox/src/opa.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,30 @@ process:
20792079
assert!(!eval_l7(&engine, &input));
20802080
}
20812081

2082+
#[test]
2083+
fn l7_graphql_unregistered_hash_only_query_has_deny_reason() {
2084+
let engine = l7_engine();
2085+
let input = l7_graphql_input(
2086+
"api.graphql.com",
2087+
serde_json::json!([{
2088+
"operation_type": "",
2089+
"operation_name": "Viewer",
2090+
"fields": [],
2091+
"persisted_query": true,
2092+
"persisted_query_hash": "missing"
2093+
}]),
2094+
);
2095+
let mut eng = engine.engine.lock().unwrap();
2096+
eng.set_input_json(&input.to_string()).unwrap();
2097+
let val = eng
2098+
.eval_rule("data.openshell.sandbox.request_deny_reason".into())
2099+
.unwrap();
2100+
assert_eq!(
2101+
val,
2102+
regorus::Value::String("GraphQL persisted query is not registered".into())
2103+
);
2104+
}
2105+
20822106
#[test]
20832107
fn l7_graphql_parse_error_denied() {
20842108
let engine = l7_engine();

0 commit comments

Comments
 (0)