Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Prevent Injection in Config Processing
00:00
5 left

Prevent Injection in Config Processing

HardPython

Problem

Stripe Radar rules are supplied as JSON-like configuration objects. Implement safely_process_radar_rules to validate a nested rule tree and return a canonical JSON string that can be safely stored and later interpreted as data, not executable syntax. Return None for any invalid configuration.

The accepted root object has exactly version and rules. Each rule has exactly if and action, where action is allow, block, or review. Conditions are recursive expressions:

  • {"all": [expression, ...]}
  • {"any": [expression, ...]}
  • {"not": expression}
  • {"field": name, "op": operator, "value": value}

Allowed fields are amount, billing_country, card_country, and risk_level. Numeric fields accept numeric values, while country fields accept strings and risk_level accepts one of low, medium, or high. Operators must be compatible with the field type. The in operator accepts a non-empty list of compatible values.

Reject unknown keys, dangerous key names such as __proto__, control characters in strings, non-finite numbers, excessive nesting, and configurations exceeding the stated limits. Canonical output must use sorted keys, compact separators, and JSON escaping.

Constraints

  • The root object must contain exactly the keys version and rules
  • version must equal 1
  • 0 <= rules.length <= 100
  • The expression tree contains at most 1,000 nodes
  • Expression depth is at most 20
  • Strings contain at most 128 characters and no control characters
  • Numeric values must be finite JSON-compatible numbers
  • Only allowlisted fields, operators, and actions are accepted

Function Signature

def safely_process_radar_rules(config):
Interviewer

Your question is Prevent Injection in Config Processing. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.