Hardened feature for importing answers from a JSON file#1027
Draft
nonprofittechy wants to merge 12 commits intomainfrom
Draft
Hardened feature for importing answers from a JSON file#1027nonprofittechy wants to merge 12 commits intomainfrom
nonprofittechy wants to merge 12 commits intomainfrom
Conversation
Member
Author
|
@ll-jgraszer your comments welcome too |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the “import answers from JSON” feature in AssemblyLine by adding structural validation, strict variable/class filtering, and user-facing reporting to reduce the risk of malicious or malformed payloads (per #481).
Changes:
- Added defensive JSON parsing and sanitization in
sessions.load_interview_json()(limits, protected variable blocking, object/class allowlisting, class remapping, dunder/key pattern checks). - Added an import report API (
get_last_import_report) and wired the saved-sessions interview flow to display warnings/rejections to the user. - Added unit tests and sample JSON fixtures covering adversarial cases and object graph handling; documented configuration options in the README.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docassemble/AssemblyLine/sessions.py | Core hardening: parse limits, variable/class allowlists, object envelope validation, and import reporting. |
| docassemble/AssemblyLine/test_sessions.py | New unit tests covering malformed JSON, limit enforcement, protected vars, object allowlisting/remaps, and adversarial payloads. |
| docassemble/AssemblyLine/data/sources/answer_set_import_samples/*.json | Test fixtures for safe and malicious import scenarios (object graphs, dunder/internal keys, malformed JSON). |
| docassemble/AssemblyLine/data/questions/al_visual.yml | Adds an interview-level gate (al_allow_answer_set_imports) to the “Import answer set” menu item visibility logic. |
| docassemble/AssemblyLine/data/questions/al_settings.yml | Defines al_allow_answer_set_imports (default True) for interview-level control of imports. |
| docassemble/AssemblyLine/data/questions/al_saved_sessions.yml | Uses is_valid_json() for validation; calls get_last_import_report() and displays warnings/rejections. |
| docassemble/AssemblyLine/data/questions/al_document.yml | Minor string quoting consistency changes. |
| README.md | Adds configuration documentation for the hardened JSON import behavior and limits. |
# Conflicts: # docassemble/AssemblyLine/sessions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens the answer import functionality significantly, although I'd still caution authors that they might not need to turn this on for normal use.
fix #481
__dunder__methods.An interactive interview to test with: