Skip to content

🔒 Fix unsafe JSON deserialization in Parametric models#54

Open
derrynknife wants to merge 4 commits intomasterfrom
security/fix-unsafe-json-deserialization-6319190020759174654
Open

🔒 Fix unsafe JSON deserialization in Parametric models#54
derrynknife wants to merge 4 commits intomasterfrom
security/fix-unsafe-json-deserialization-6319190020759174654

Conversation

@derrynknife
Copy link
Owner

🎯 What: The from_json and from_dict methods in surpyval/univariate/parametric/parametric.py allowed instantiating arbitrary classes and functions from the surpyval module via getattr based on user-provided JSON/dict input.
⚠️ Risk: An attacker could exploit this by providing a crafted JSON file containing an unexpected "distribution" value (e.g., __builtins__ or other internal modules/functions). This unsafe deserialization could lead to unexpected behavior, denial of service, or potentially arbitrary code execution depending on the available targets.
🛡️ Solution: Added a hardcoded whitelist (ALLOWED_DISTRIBUTIONS) containing only valid parametric distributions. The from_dict method now strictly checks the requested distribution against this whitelist and raises a ValueError if the distribution is not recognized, explicitly blocking unsafe deserialization attempts.


PR created automatically by Jules for task 6319190020759174654 started by @derrynknife

Co-authored-by: derrynknife <18457108+derrynknife@users.noreply.github.com>
@google-labs-jules
Copy link

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34c0b742c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +35 to +38
"MixtureModel",
"NeverOccurs",
"Normal",
"Parametric",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude non-fitters from allowed distribution whitelist

ALLOWED_DISTRIBUTIONS currently includes symbols like MixtureModel, NeverOccurs, and Parametric that are not valid Parametric fitters. In from_dict, these names pass the new whitelist check and then flow into out = cls(dist, ...), where Parametric.__init__ expects dist.k/dist.bounds/dist.param_map; this raises an internal AttributeError instead of the intended ValueError for unrecognized input. A crafted JSON payload using one of these entries can still crash deserialization, so the new validation is not fully enforced for untrusted input.

Useful? React with 👍 / 👎.

google-labs-jules bot and others added 3 commits March 7, 2026 10:35
…nd fix CI

Co-authored-by: derrynknife <18457108+derrynknife@users.noreply.github.com>
Co-authored-by: derrynknife <18457108+derrynknife@users.noreply.github.com>
Co-authored-by: derrynknife <18457108+derrynknife@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant