fix(datasource-customizer): reject malformed binary filter values instead of crashing - #1835
Open
Tonours wants to merge 3 commits into
Open
fix(datasource-customizer): reject malformed binary filter values instead of crashing#1835Tonours wants to merge 3 commits into
Tonours wants to merge 3 commits into
Conversation
1 new issue
|
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (1)
🛟 Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

What
A
Binarycolumn filtered or written with a malformed value now raisesValidationErrorinstead of crashing or converting the wrong bytes.'Anthony'on a datauri columnTypeError, untyped → 500ValidationError'Anthony'on a hex column (every Binary PK/FK)ValidationError'data:text/plain,hello'85e965)ValidationError42TypeError, untyped → 500ValidationErrorWhy
convertScalarassumed its input was always a well-formed datauri or hex string. It isn't: the value comes from a filter or a record patch, so anything can arrive.Buffer.from('Anthony'.split(',')[1], 'base64')throws a rawTypeError— no HTTP status, so it surfaces as a generic 500 and the caller never learns what to send instead.The hex branch was worse than the crash:
Buffer.fromnever throws on bad hex, it stops at the first invalid character.'Anthony'yields an empty buffer, so a filter on a Binary primary key silently queried for an empty blob and returned wrong results with no error at all.shouldUseHexdefaults to true for every primary and foreign key, so that was the common path.How
parseDataUri, dropping a hand-rolled split that missed its hardening/^([0-9a-f]{2})*$/i, mirroring theMatchvalidation this decorator already advertises on hex fields — odd lengths included, sinceBuffer.from('303','hex')silently drops a digit5 tests, each asserting the message and that the underlying collection was never called.
Heads-up: writes are stricter too
create/updatego through the same conversion. Three datauri forms that previously reached the database now raise: a raw comma in aname=media type,data:base64,…with no semicolon, and uppercaseBASE64(parseDataUriis case-sensitive, RFC 2397 is not).These rules come from
parseDataUri, which already applies them to the S3 plugin's write path. If the uppercase form matters, fix it there for every caller rather than special-casing this decorator.Test
yarn workspace @forestadmin/datasource-customizer test -- test/decorators/binary/collection.test.tsAlso verified against a live agent: the same filter went from an opaque 500 to a 400 naming the expected format.
Definition of Done
General
Security