T09 · Insecure Skill Coding Practices
- Location
psy-exp-coder/psychopy/demo/_raw/Choice_Reaction_Time_Task__choiceRTT_lastrun.py:452- Finding
Arbitrary Python Execution Through Unvalidated Condition-File Column Names
- Content
View full analysis
Vulnerability Details
File Location:
psy-exp-coder/psychopy/demo/_raw/Choice_Reaction_Time_Task__choiceRTT_lastrun.py:452-470
Additional Locations: The same legacy pattern appears in multiple PsychoPy raw demos and paradigm references, includingpsy-exp-coder/psychopy/paradigms/choice-reaction-time.md:497-504.
Vulnerability Type: Dynamic code execution using spreadsheet-controlled identifiers
Risk Level: HighVulnerable Code
python PracticeLoop = data.TrialHandler(nReps=1.0, method='random', extraInfo=expInfo, originPath=-1, trialList=data.importConditions('RTtimeConditions.xlsx'), seed=None, name='PracticeLoop') thisExp.addLoop(PracticeLoop) thisPracticeLoop = PracticeLoop.trialList[0] # abbreviate parameter names if possible if thisPracticeLoop != None: for paramName in thisPracticeLoop: exec('{} = thisPracticeLoop[paramName]'.format(paramName)) for thisPracticeLoop in PracticeLoop: currentLoop = PracticeLoop if thisPracticeLoop != None: for paramName in thisPracticeLoop: exec('{} = thisPracticeLoop[paramName]'.format(paramName))Technical Analysis
data.importConditions()loads column names from an external Excel condition file. Each column name becomesparamName, which is interpolated directly into Python source code and passed toexec().The program assumes every column name is a harmless Python identifier, but it performs no identifier validation or allowlisting. A maliciously constructed column name can terminate the intended assignment and insert additional Python statements. The resulting statements execute with the full privileges of the user running PsychoPy.
The repository itself identifies this legacy pattern as unsafe in
psy-exp-coder/psychopy/spec/README.md:694and prohibits it inpsy-exp-coder/psychopy/mapping/README.md:288-296. Nevertheless, executable demos containing the pattern remain ...[truncated 1512 chars]- Remediation
View remediation
Remediation Suggestions
-
Remove every use of
exec()for condition-variable injection from demos and paradigm references. -
Access condition fields explicitly:
python this_image = thisPracticeLoop["thisImage"] correct_answer = thisPracticeLoop["corrAns"] -
If generic field processing is necessary, validate fields against a fixed allowlist:
python ALLOWED_FIELDS = {"thisImage", "corrAns", "duration"} unexpected = set(thisPracticeLoop) - ALLOWED_FIELDS if unexpected: raise ValueError(f"Unexpected condition fields: {sorted(unexpected)}") -
Validate workbook provenance and integrity before execution.
-
Add an automated repository check that rejects
exec()and equivalent dynamic-evaluation patterns in executable demos and generated output. -
Clearly mark legacy raw demos as non-production references and ensure the generation pipeline cannot copy them verbatim.
-
Replace vulnerable code in the duplicated paradigm Markdown examples so unsafe patterns are not reintroduced by generated experiments.
-
