Limit maximum revocation list credential size #339
Merged
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.
Add a size limit for HTTP(S) responses when loading a revocation list credential. Revocation list credentials are received from remote sources and loaded into memory for credential status checking. This change is to prevent resource exhaustion due to attempting to load unboundedly large responses.
The limit is added as a constant value (
ssi::revocation::MAX_RESPONSE_LENGTH
), set to 2MB for now. An error type variant is added for the case of an oversize revocation list credential response.Testing
The remote credential loading functionality is not tested in
ssi
currently. It also isn't tested in DIDKit's tests (Pending in spruceid/didkit#239). DIDKit CLI doesn't have a way to check credential status currently (Relevant issue: spruceid/didkit#240).To perform a test, here is a patch to DIDKit to enable checking
credentialStatus
during credential verification on the CLI:Here is then a patch to a test vector verifiable credential case-14.json from
vc-api-test-suite
that usescredentialStatus
withRevocationList2020Status
, patching it to use an oversized revocation list credential. This replaces the revocation list credential URL with a URL to a resource of size 4096KB (Generated usingdd if=/dev/zero bs=1024 count=4096 > 4096k
):Attempting to verify that credential then results in an error, resulting from the newly added size limit:
WebAssembly Limitation
reqwest
doesn't have the chunk orbytes_stream
methods in its WebAssembly backend: it doesn't offer chunked/streamed response reading. An issue about this is here: seanmonstar/reqwest#1234. This PR addresses the WebAssembly case by performing a less comprensive check: thecontent-length
header is checked, and then the payload size is checked after receiving the entire payload. This means that it is possible that an unusually large response could cause a problem for a user of the library in WASM - i.e. if the content-header is missing or set incorrectly. But this seems like the best that can be done currently. The length is still checked in this case after receiving the body, so in the case of an oversized response, execution will not proceed to JSON-LD parsing.