Repository navigation
fix(assistant): say what approvals, settings and steps do #3577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ca32602
f8f2b78
17f9422
6e7fee4
cc2531f
e608d84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,16 @@ | |
| use egui::{RichText, Ui}; | ||
| use rustgis_engine::{Registry, policy::Review}; | ||
|
|
||
| /// The SQL a request runs, with the command that runs it, from the sanitized steps it asks about. | ||
| fn sql(review: &Review) -> Vec<(String, String)> { | ||
| let query = |step: &String| { | ||
| let (id, params) = step.split_once(' ').filter(|(id, _)| matches!(*id, "sql.query" | "layer.addSql"))?; | ||
| let params: serde_json::Value = serde_json::from_str(params).ok()?; | ||
| Some((id.to_string(), params.get("sql")?.as_str()?.to_string())) | ||
| }; | ||
| review.steps.iter().filter_map(query).collect() | ||
| } | ||
|
|
||
| /// Registry labels name operations without interpreting the request's script or parameters. | ||
| fn operation(registry: &Registry, id: &str) -> String { | ||
| registry.get(id).map_or_else(|| id.to_string(), |spec| tl_raw!(spec.label).to_string()) | ||
|
|
@@ -12,10 +22,12 @@ fn operation(registry: &Registry, id: &str) -> String { | |
| /// Callers bound the scroll area and keep their existing approval controls outside it. | ||
| pub(crate) fn show(ui: &mut Ui, registry: &Registry, review: &Review) { | ||
| ui.push_id((&review.what, &review.steps, &review.defaults, &review.lines), |ui| { | ||
| let queries = sql(review); | ||
| let mut operations = Vec::new(); | ||
| for id in review.details.iter().map(|d| &d.operation).chain(review.lines.iter().map(|(_, id)| id)) { | ||
| if !id.is_empty() && !operations.contains(id) { | ||
| operations.push(id.clone()); | ||
| let asked = review.details.iter().map(|d| &d.operation).chain(review.lines.iter().map(|(_, id)| id)).cloned(); | ||
| for id in asked.chain(queries.iter().map(|(id, _)| id.clone())) { | ||
| if !id.is_empty() && !operations.contains(&id) { | ||
| operations.push(id); | ||
| } | ||
| } | ||
| let actions = if operations.is_empty() { | ||
|
|
@@ -40,6 +52,15 @@ pub(crate) fn show(ui: &mut Ui, registry: &Registry, review: &Review) { | |
| ); | ||
| } | ||
| ui.add(egui::Label::new(RichText::new(reason(review)).small()).wrap()); | ||
| // What a query does is its text, so it isn't left under Details. | ||
| for (_, query) in &queries { | ||
| ui.add(egui::Label::new(RichText::new(query).monospace().small()).wrap().selectable(true)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This card now shows the query as what the request does, but the text is the sanitized review. Category: security
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 6e7fee4: when a query's secret values are left out of the card, a note under it says they're hidden and that the query runs with them. |
||
| } | ||
| // Secrets are left out of what is shown (a CREATE SECRET's options, a key): said, so the | ||
| // text isn't taken for the whole query. | ||
| if !queries.is_empty() && review.sql_hidden { | ||
| ui.label(RichText::new(tl!("Secret values in this query are hidden here, but the query runs with them.")).small().italics()); | ||
| } | ||
| for detail in &review.details { | ||
| let name = operation(registry, &detail.operation); | ||
| if !detail.targets.is_empty() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql_hiddenis documented as "secrets taken out", but it is set wheneverreview_paramsreturns a different value, andreview_valuechanges text for reasons that aren't secrets. Two cases I traced inproject_log.rs:review_value, theStringarm,out.push_str(&value.to_string())). SoSELECT json_extract('{"a": 1}', '$.a')comes out as{"a":1}. The flag goes true, the card says "Secret values in this query are hidden here, but the query runs with them", and the card shows SQL that differs from what runs, though nothing was secret.redacted_parameter(schemeless_query_cut) for any text the sanitiser shortens.Result: a false statement on the consent card, and the card's text is altered without the note saying what changed. Not run here. I traced the mechanism by reading the code; confidence high on the JSON case.
Suggested direction: have the sanitiser report that it removed a secret (as
sql_secrets_removeddoes for its own cases) and set the flag from that, not from inequality. Add a test thatSELECT '{"a": 1}'givessql_hidden == false(the existing "clean SELECT" assertion doesn't cover a{/[literal).Category: bug