Kitura / BlueCryptor

Swift cross-platform crypto library using CommonCrypto/libcrypto
Apache License 2.0
191 stars 46 forks source link

fix: make byteArray return empty array on failure instead of fatal error #53

Closed Andrew-Lees11 closed 5 years ago

Andrew-Lees11 commented 5 years ago

Description

This PR changes byteArray so that on failure it returns an empty array instead of throwing a fatal error.

Motivation and Context

This is required because you make pass user code into the function (such as in Kitura-Session where a users Cookie is decoded). If it throws a fatal error on failure then a user can crash the system. If it returns an empty array the application can handle this in the correct way.

How Has This Been Tested?

This has been tested within Kitura-Session. Using this code makes the session reject the cookie instead of throwing a fatal error and crashing the server.

Checklist:

ianpartridge commented 5 years ago

Looks good to me 🙂 Would be nice to have a test.

billabt commented 5 years ago

I understand the rationale behind the PR but I just want make sure you know that it’s a potential source breaking change. The unexpected empty array could cause problems that could be difficult to detect and find. Have you considered this? @ianpartridge, you ok with this?

ianpartridge commented 5 years ago

Yeah I think we should make this change, the current behaviour is dangerous.

Andrew-Lees11 commented 5 years ago

So the only way this impacts existing applications is that if it was previously throwing a fatal error. This makes it unlikely that this will change expected behavior. In the next major release of BlueCryptor this function should probably throw but I think this fix will solve the current issue in a non breaking way.