Repository navigation
fix(ocr-service): drop node-tesseract-ocr and call the tesseract binary with execFile - #1362
Closed
Gustav-Ahrens wants to merge 1 commit into
Closed
Gustav-Ahrens wants to merge 1 commit into
Gustav-Ahrens wants to merge 1 commit into
Conversation
…ry with execFile node-tesseract-ocr builds one shell command string from the screenshot path and runs it with child_process.exec (GHSA-8j44-735h-w4w2, critical, no patched release since 2022). Run the system tesseract binary directly with execFile and an argument array instead, so the path and options never pass through a shell. The command and its output are unchanged. Closes webdriverio#1361 Co-Authored-By: Full Stack Ground Control <support@fullstack.co.za>
🦋 Changeset detectedLatest commit: 3272769 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Author
|
Closing this draft; the OCR service works as is for our use, and the advisory is tracked in #1361 for the maintainers to handle as they see fit. |
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.
Closes #1361
Summary
@wdio/ocr-servicedepended onnode-tesseract-ocr, which carries an unpatched critical advisory (GHSA-8j44-735h-w4w2, CVE-2026-26832: the file path is concatenated into a shell command and run withchild_process.exec). The package has had no release since May 2022 and the advisory lists no patched version, so every project that installs the OCR service gets onenpm auditcritical it cannot clear.This PR removes the dependency. The service now runs the system
tesseractbinary itself throughchild_process.execFilewith an argument array, so the screenshot path and the options never pass through a shell.isSystemTesseractAvailable()usesexecFileSyncfor the same reason.What changes
packages/ocr-service/src/utils/tesseract.ts: newrunSystemTesseract(filePath, { lang, oem, psm, presets })builds[filePath, 'stdout', '-l', lang, '--oem', oem, '--psm', psm, ...presets]and callsexecFile('tesseract', args, { maxBuffer: 10 MiB }).getSystemOcrData()calls it with the same options as before (eng, oem 1, psm 3,alto).isSystemTesseractAvailable()callsexecFileSync(binary, ['--version']).packages/ocr-service/package.jsonandpnpm-lock.yaml:node-tesseract-ocrremoved.node-tesseract-ocrmock is replaced byexecFile/execFileSyncmocks. Two new tests assert that a binary name and a file path containing shell metacharacters are passed through as single literal arguments.@wdio/ocr-service.What does not change
node-tesseract-ocrbuilt:tesseract <file> stdout -l <lang> --oem 1 --psm 3 alto. The only behavioural difference is the stdout buffer: 10 MiB instead of Node's 1 MiB default, so the ALTO XML of a busy full-screen capture no longer risksmaxBufferexceeded.tesseract.jsfallback path is untouched.Verification
pnpm vitest --run packages/ocr-service: 84 passed.pnpm build,pnpm run test:types,pnpm run test:lint: clean.packages/image-comparison-core/src/methods/processDiffPixels.test.ts. Those three fail identically onmainon this machine (Node 26.12, macOS) with the change stashed, so they are unrelated.node-tesseract-ocr.recognize()and the newrunSystemTesseract()on the same 1080x2400 app screenshot with identical options. The raw ALTO output was byte-identical (8304 bytes), andgetSystemOcrData()returned 31 words and 16 lines from it.Generated with Full Stack Ground Control (support@fullstack.co.za)