Skip to content

Commit 7bbe013

Browse files
committed
Expose a few key LoadSettings values
These values are often set to mitigate DOS attacks, so we want to expose them for JRuby users. See #579
1 parent d772d8a commit 7bbe013

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

ext/java/org/jruby/ext/psych/PsychParser.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jcodings.unicode.UnicodeEncoding;
3535
import org.jruby.Ruby;
3636
import org.jruby.RubyArray;
37+
import org.jruby.RubyBoolean;
3738
import org.jruby.RubyClass;
3839
import org.jruby.RubyEncoding;
3940
import org.jruby.RubyFixnum;
@@ -487,6 +488,42 @@ public IRubyObject mark(ThreadContext context) {
487488
);
488489
}
489490

491+
@JRubyMethod(name = "max_aliases_for_collections=")
492+
public IRubyObject max_aliases_for_collections_set(IRubyObject max) {
493+
loadSettingsBuilder.setMaxAliasesForCollections(max.convertToInteger().getIntValue());
494+
495+
return max;
496+
}
497+
498+
@JRubyMethod(name = "max_aliases_for_collections")
499+
public IRubyObject max_aliases_for_collections(ThreadContext context) {
500+
return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections());
501+
}
502+
503+
@JRubyMethod(name = "allow_duplicate_keys=")
504+
public IRubyObject allow_duplicate_keys_set(IRubyObject allow) {
505+
loadSettingsBuilder.setAllowDuplicateKeys(allow.isTrue());
506+
507+
return allow;
508+
}
509+
510+
@JRubyMethod(name = "allow_duplicate_keys")
511+
public IRubyObject allow_duplicate_keys(ThreadContext context) {
512+
return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys());
513+
}
514+
515+
@JRubyMethod(name = "allow_recursive_keys=")
516+
public IRubyObject allow_recursive_keys_set(IRubyObject allow) {
517+
loadSettingsBuilder.setAllowRecursiveKeys(allow.isTrue());
518+
519+
return allow;
520+
}
521+
522+
@JRubyMethod(name = "allow_recursive_keys")
523+
public IRubyObject allow_recursive_keys(ThreadContext context) {
524+
return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys());
525+
}
526+
490527
private LoadSettings buildSettings() {
491528
return loadSettingsBuilder.build();
492529
}

0 commit comments

Comments
 (0)