Skip to content

Commit 3eba4ef

Browse files
committed
Raise error if too many recursive contexts loaded.
1 parent 550ce79 commit 3eba4ef

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/json/ld.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ module LD
9191
array_nl: "\n"
9292
)
9393

94+
MAX_CONTEXTS_LOADED = 50
95+
9496
class JsonLdError < StandardError
9597
def to_s
9698
"#{self.class.instance_variable_get :@code}: #{super}"
@@ -134,6 +136,7 @@ class InvalidVocabMapping < JsonLdError; @code = "invalid vocab mapping"; end
134136
class KeywordRedefinition < JsonLdError; @code = "keyword redefinition"; end
135137
class LoadingDocumentFailed < JsonLdError; @code = "loading document failed"; end
136138
class LoadingRemoteContextFailed < JsonLdError; @code = "loading remote context failed"; end
139+
class ContextOverflow < JsonLdError; @code = "maximum number of @context URLs exceeded"; end
137140
class MultipleContextLinkHeaders < JsonLdError; @code = "multiple context link headers"; end
138141
class ProcessingModeConflict < JsonLdError; @code = "processing mode conflict"; end
139142
class RecursiveContextInclusion < JsonLdError; @code = "recursive context inclusion"; end

lib/json/ld/context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ def parse(local_context, remote_contexts = [])
419419

420420
raise JsonLdError::RecursiveContextInclusion, "#{context}" if remote_contexts.include?(context.to_s)
421421
remote_contexts << context.to_s
422+
raise JsonLdError::ContextOverflow, "#{context}" if remote_contexts.length >= MAX_CONTEXTS_LOADED
422423

423424
context_no_base = result.dup
424425
context_no_base.base = nil

0 commit comments

Comments
 (0)