Uh oh!
There was an error while loading. Please reload this page.
Expose load settings - #613
Conversation
7bbe013 to
caac676CompareThese values are often set to mitigate DOS attacks, so we want to expose them for JRuby users. See ruby#579
caac676 to
a0e5247Compareheadius
commented
Jan 26, 2023
@hsbt@tenderlove I would like to start shipping this feature, so users can configure the limits in the SnakeYAML parser. Is what I have here acceptable? Does libyaml have any similar configurations we could expose in the same way? |
hsbt
commented
Jan 27, 2023
It's reasonable to expose But I'm not sure we should allow to set |
headius
commented
Jan 31, 2023
hsbt
commented
Jan 31, 2023
Ah, I see. Thanks. |
headius
commented
Feb 6, 2023
I guess this is approved so I'm going to merge. If we find that these settings are configurable in libyaml we can deal with making the API the same at that point. |
What about this option in high-level API like Psych.load? Now I need to add a monkey patch to set the code point limit in Psych module method..., but this seems a bad way. |
headius
commented
Jul 13, 2023
@yvesll That's not a bad idea. Perhaps you could put together a PR that allows passing these values through as options? |
How can these load settings be defined in a rails app? (JRuby newbie here) I tried implementing the monkey patch as per @yvesll's comment, but that isn't working for me: We're on Rails 6 running on JRuby 9.4.3.0, and we're hitting the code point limit issue when loading big yaml fixtures for rspec: Is there a way to set it in a .jrubyrc config? I didn't find a |
yvesll
commented
Sep 6, 2023
HI, @oliverbarnes, here is my monkey patch which works fine for me, hope it can help you: modulePsychdefself.parse_streamyaml,filename: nil, &blockifblock_given?parser=Psych::Parser.new(Handlers::DocumentStream.new(&block))parser.code_point_limit=20_000_000parser.parseyaml,filenameelseparser=self.parserparser.parseyaml,filenameparser.code_point_limit=20_000_000parser.handler.rootendendifdefined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"end |
oliverbarnes
commented
Sep 6, 2023
Thanks @yvesll! I'm getting a new error now, but I think it's enough to make progress: |
headius
commented
Sep 7, 2023
I had not considered that many applications won't control the construction of the psych parser! I think we should add class methods to psych for setting the default values that then will be passed in for every parser creation. It may also be worth using higher defaults to begin with. Perhaps one of you could try to create a PR for that feature? |
@headius I'd be happy to do that (after some grokking), but I'm still encountering issues related to psych. Using @yvesll's monkey patch got me past the code point limitation, but now I'm stuck with vcr not recognizing http requests previously recorded in yaml fixtures. I have a hunch this is due to Psych now being compliant with YAML 1.2, as mentioned in other issues here on the repo. Being totally honest, I'm spiking migrating a project to jruby for a client, and before I can dedicate time contributing to jruby, I need to show some progress :) |
headius
commented
Sep 7, 2023
@oliverbarnes That is certainly possible, but there's always the possibility of a bug in SnakeYAML Engine. If you can show this parsing with another 1.2-compliant parser, we will know. Keep me posted...I want to help your experiment to succeed! |
headius
commented
Sep 10, 2023
@oliverbarnes Is there an issue filed for your YAML 1.2 problem? I want to make sure we track it but I'm not sure what other issues you were referring to. I found only one recent issue in the psych tracker since the upgrade. Given your report and the other I found I'm recommending that we not upgrade psych in the JRuby 9.3 line (jruby/jruby#7600), so having a complete bug report would be really helpful! |
This adds class-level accessors for the following SnakeYAML- specific parser settings: * max_aliases_for_collections * allow_duplicate_keys * allow_recursive_keys * code_point_limit The initial values are based on SnakeYAML Engine's defaults. This PR does not modify those default values. Using these accessors, it should be possible for users to globally change them for all future Psych parser instances without resorting to monkey patches as described in ruby#613 (comment).
headius
commented
Sep 10, 2023
@oliverbarnes Here, I'll trade you this for your YAML 1.2 issue report: #647 |
oliverbarnes
commented
Sep 11, 2023
This adds class-level accessors for the following SnakeYAML- specific parser settings: * max_aliases_for_collections * allow_duplicate_keys * allow_recursive_keys * code_point_limit The initial values are based on SnakeYAML Engine's defaults. This PR does not modify those default values. Using these accessors, it should be possible for users to globally change them for all future Psych parser instances without resorting to monkey patches as described in ruby#613 (comment).
These settings are not enforced at the parser level in SnakeYAML Engine, instead being enforced during the construction of the YAML node graph. Because the JRuby Psych wrapper around SnakeYAML only uses the parser directly, the settings have no effect. This commit removes the ineffective settings until we can decide what to do about them. See ruby#613, ruby#647, and ruby#649.
This builds off #612, adding access to some key DOS-related settings in the parser. See #579.
The PR in #612 should be merged before this one (and I will rebase to master when that happens).