Skip to content

fix: stop Parse QR Code from participating in Magic (#2610)#2613

Open
Sanjays2402 wants to merge 1 commit into
gchq:masterfrom
Sanjays2402:fix/issue-2610
Open

fix: stop Parse QR Code from participating in Magic (#2610)#2613
Sanjays2402 wants to merge 1 commit into
gchq:masterfrom
Sanjays2402:fix/issue-2610

Conversation

@Sanjays2402

@Sanjays2402 Sanjays2402 commented Jun 27, 2026

Copy link
Copy Markdown

Description

Parse QR Code declared a checks regex that matched any JPEG, PNG, GIF, WEBP or BMP magic bytes. Magic._generateOpCriteria (in src/core/lib/Magic.mjs) aggregates every operation that exposes a checks property and runs each against the input, so any image fed to Magic (which happens implicitly whenever Magic is in the recipe, including via the URL/QueryString demo) triggered a full QR parse. The QR decoder then logged [BGChefWorker]: Could not read a QR code from the image. to the browser console for every image that didn't contain a QR code.

This PR removes the this.checks array from ParseQRCode's constructor (leaving a comment that points at the issue). There is no cheap way to know an image contains a QR code without actually attempting to decode one, so it can't be a sensible Magic candidate. The operation itself is unchanged and every other operation is unaffected; only Magic's automatic dispatch stops attempting QR parsing. Users who know their image has a QR code can still add Parse QR Code to the recipe manually.

Behaviour before: loading the 1px-PNG demo URL from the issue with DevTools open prints [BGChefWorker]: Could not read a QR code from the image.
Behaviour after: same URL, console is silent; Magic still recognises the input as an image and lists the usual image-render suggestions.

Existing Issue

Fixes #2610.

Screenshots

No visual changes to CyberChef. The only observable difference is the absence of a console error message; no UI is affected.

AI disclosure

This change was written with the assistance of Claude. I have reviewed the diff and the test, understand the root cause and the fix, and take responsibility for the submitted code.

Test Coverage

Adds tests/node/tests/ParseQRCode.mjs with an API-level regression test asserting that OperationConfig["Parse QR Code"] declares no checks. The test fails on master with the original checks regex and passes with this change (verified both directions). The full node and operations suites still pass locally (255 and 2057 tests respectively).

Parse QR Code declared a `checks` regex that matched any JPEG, PNG,
GIF, WEBP or BMP magic bytes. Magic aggregates every operation with a
`checks` property and runs them, so any image input triggered a full
QR parse attempt that produced a 'Could not read a QR code from the
image' warning in the browser console for every image, even when no QR
code was present.

There is no cheap way to detect a QR code without attempting a full
parse, so Parse QR Code should not participate in Magic. Users can add
it manually when they know the image contains a QR code.

Adds a regression test asserting Parse QR Code declares no `checks`.
@C85297

C85297 commented Jul 3, 2026

Copy link
Copy Markdown
Member

@GCHQDeveloper581 @tomdev123 @np748293 would appreciate your views here. This operation has been part of magic for quite a long time (since #515 ). It doesn't seem to be an accident - it was specifically added, so we should be making a conscious decision if we are to remove it.

@GCHQDeveloper581

GCHQDeveloper581 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

I originally suggested removing it from Magic when I raised Issue #2610, and have given my rationale there (and the mitigation).

However, as more instances of Magic detection running amok are found - (#2410, #2642) I'm beginning to think that the correct response is to alter Magic to catch OperationError without reporting the error, and simply to remove the operation from consideration for that stage of the processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: Spurious "Could not read a QR code from the image" console log messages when handling image data

3 participants