sentinel: harden FFI strict parsing for trust boundary 🛡️#2672
sentinel: harden FFI strict parsing for trust boundary 🛡️#2672EffortlessSteven wants to merge 1 commit into
Conversation
Hardened the JSON FFI boundary against setting block evasion by rejecting invalid top-level component types. Replaced silent default fallbacks with strict error responses for invalid nested configuration objects (e.g. `{"scan": "not an object"}`).
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Review limit reached
More reviews will be available in 6 minutes and 51 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Droid finished @EffortlessSteven's task —— View job Droid review complete for PR #2672. LGTM. The PR correctly hardens the FFI trust boundary by introducing a strict No review comments were generated for this PR. |
There was a problem hiding this comment.
Code Review
This pull request hardens the JSON FFI boundary in crates/tokmd-core by replacing silent default fallbacks with strict error responses when invalid nested configuration objects (such as scan, lang, module, etc.) are provided. It introduces a helper function get_settings_object to perform strict object validation and updates the parsing logic and tests accordingly. The review feedback suggests explicitly verifying that the top-level args is a JSON object in get_settings_object to prevent unexpected behavior, and moving the inline import in ffi_contract.rs to the top of the file to adhere to standard Rust style guidelines.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| pub(super) fn get_settings_object<'a>( | ||
| args: &'a Value, | ||
| field: &str, | ||
| ) -> Result<&'a Value, TokmdError> { | ||
| match args.get(field) { | ||
| None | Some(Value::Null) => Ok(args), | ||
| Some(v) if v.is_object() => Ok(v), | ||
| Some(_) => Err(TokmdError::invalid_field(field, "an object")), | ||
| } | ||
| } |
There was a problem hiding this comment.
If args is not a JSON object (e.g., if it is a string, array, or null), args.get(field) will return None, which currently causes get_settings_object to return Ok(args) (a non-object). To prevent silent fallback to defaults and ensure robust defensive programming, we should explicitly verify that args is a JSON object before attempting to retrieve the field.
pub(super) fn get_settings_object<'a>(
args: &'a Value,
field: &str,
) -> Result<&'a Value, TokmdError> {
if !args.is_object() {
return Err(TokmdError::invalid_json("Expected a JSON object"));
}
match args.get(field) {
None | Some(Value::Null) => Ok(args),
Some(v) if v.is_object() => Ok(v),
Some(_) => Err(TokmdError::invalid_field(field, "an object")),
}
}| "error envelope must not have 'data'" | ||
| ); | ||
| } | ||
| use serde_json::Value; |
Glass CockpitBase: origin/main Change Surface:
Composition:
Contracts:
Health: 100/100 (A) Review Plan
ReceiptsFull receipt data available in JSON format. |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_ad60a59e-a929-4e4a-a8ef-ef646a721fd3) |
The previous parsing logic for sub-objects like
scan,lang,module, andexportusedargs.get("scan").unwrap_or(args). Ifscanwas passed as a non-object (e.g., a string or array),Value::geton a non-object returnsNone, silently acting like an empty object instead of returning aninvalid_settingserror. This broke the contract of strict configuration parsing across the FFI trust boundary and allowed bindings to bypass validation checks silently.This PR introduces a strict
get_settings_objectvalidator and applies it across the configuration endpoints to ensure any non-object config value returns a properinvalid_settingserror.PR created automatically by Jules for task 3245254242784963356 started by @EffortlessSteven
Note
Medium Risk
Touches the untrusted FFI input boundary and changes behavior for malformed nested keys (previously silent success); well-formed callers are unaffected but bindings sending wrong types will now error.
Overview
Hardens the JSON FFI
run_jsonpath so nested mode blocks (scan,lang,module,export,analyze,cockpit,diff) cannot be passed as strings or arrays and still succeed with defaults.Replaces
scan_arg_objectandargs.get(field).unwrap_or(args)withget_settings_object, which treats a missing or null key as “use the top-level args object,” requires a JSON object when the key is present, and otherwise returnsTokmdError::invalid_field(invalid_settings). All mode-specific parsers insettings_parse.rsnow call this helper before reading fields.Adds unit coverage for the helper in
parse.rsand E2E contract tests inffi_contract.rs(e.g.{"scan": "not an object", "paths": ["src"]}must fail instead of ignoringpaths). Jules run metadata under.jules/runs/run-1/documents the decision and verification receipts; no runtime behavior change for well-formed JSON.Reviewed by Cursor Bugbot for commit 525a48b. Bugbot is set up for automated code reviews on this repo. Configure here.