Use custom max depth for parsing of Blockly JSON#66769
Conversation
| ShareFiltering.should_filter_program(with_indicator, 'playlab') | ||
| end | ||
|
|
||
| def test_extract_text_blockly_handles_deeply_nested_json |
There was a problem hiding this comment.
I'm not sure these tests are necessary. They are basically just testing whether the max depth parameter works. Do they take a long time since they have to generate a long string?
There was a problem hiding this comment.
I ran these locally and they didn't take long at all. I don't have a strong preference!
There was a problem hiding this comment.
I don't think they are necessary!
There was a problem hiding this comment.
Although if we add a state of "project too big" for a share failure they may make sense!
|
|
||
| # Texts will include field values, text values in block inputs, comments, and variable names. | ||
| json = JSON.parse(stripped) | ||
| json = JSON.parse(stripped, max_nesting: DCDO.get('share_filtering_blockly_json_max_depth', JSON_MAX_DEPTH)) |
There was a problem hiding this comment.
If this fails, we will fail to load the project, right? This is maybe a longer-term fix but I wonder if we should still allow the project to load, but not allow it to be shared?
There was a problem hiding this comment.
Or could we catch the error and just return that there was a share failure, something like "project too big"?
There was a problem hiding this comment.
yeah! I was actually thinking about allowing the loading. But not sure about not allowing it to be shared...
There was a problem hiding this comment.
I think as an intermediate step having it load but not be shareable (if that is easy to do here) seems like the right call. If we can't parse it, we don't know if it's shareable.
There was a problem hiding this comment.
I think that makes sense. I'll add a new FailureType for PROGRAM_TOO_LARGE.
Just noting that in activites_controller, we have a rescue for WebPurify::TextTooLongError and the program is still allowed.
code-dot-org/dashboard/app/controllers/activities_controller.rb
Lines 61 to 71 in a98a055
There was a problem hiding this comment.
maybe worth checking with Sam?
There was a problem hiding this comment.
Here's the commit that made programs too large not shareable: 2639841
However, I reverted since we checked with @samantha-code on Slack, and she said to let these programs still be shareable.
| begin | ||
| json = JSON.parse(stripped, max_nesting: DCDO.get('share_filtering_blockly_json_max_depth', JSON_MAX_DEPTH)) | ||
| rescue JSON::NestingError | ||
| CDO.log.warn "ShareFiltering.extract_text_blockly: JSON too deep after #{JSON_MAX_DEPTH} levels" |
There was a problem hiding this comment.
for my information: where does this go?
There was a problem hiding this comment.
I'm not exactly sure! @bencodeorg I see you recently added a log in https://github.com/code-dot-org/code-dot-org/pull/65870/files. Do you know where we can access these afterwards?
There was a problem hiding this comment.
I thought CloudWatch Logs? But that could be wrong.
This is a follow-up to #66614 which added profanity/privacy filtering for open-ended project types geared for young users.
We started getting HoneyBadger reports of
JSON::NestingError: nesting of 101 is too deep. These are caused by Sprite Lab programs whose JSON has nesting greater than 100 levels.I checked a couple programs which triggered this error and the number of levels was between 100-300. Thus, I increased
max_nestinglevel ofJSON.parsefrom the default value of100to999. I added a DCDO key in case we need to update this value quickly (thinking about when classes begin in the fall).Links
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: