Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-05-18 - [Insecure JavaScript Injection via String Interpolation in WebViews]
**Vulnerability:** Found a pattern in `src/screens/ShiftScreen.tsx` where string interpolation (`'${base64Json}'`) and manual quote replacement (`.replace(/'/g, "\\'")`) were used to pass a JSON payload directly into a `WebView`'s `injectJavaScript` function.
**Learning:** This approach creates an XSS / JS Injection vulnerability if the payload contains unescaped quotes or malicious executable sequences.
**Prevention:** To prevent this, always rely on `JSON.stringify()` to safely escape values before interpolating them into JavaScript code (e.g., `window.runTesseract(${JSON.stringify(base64Json)});`) rather than using manual text replacement and raw string interpolation.
51 changes: 24 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/screens/ShiftScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default function ShiftScreen() {
setOcrText('');

const base64List = result.assets.map(a => `data:image/jpeg;base64,${a.base64}`);
const base64Json = JSON.stringify(base64List).replace(/'/g, "\\'");
const base64Json = JSON.stringify(base64List);

const jsCode = `
if (window.runTesseract) {
window.runTesseract('${base64Json}');
window.runTesseract(${JSON.stringify(base64Json)});
} else {
window.ReactNativeWebView.postMessage(JSON.stringify({ success: false, error: "Motore OCR non pronto." }));
}
Expand Down
Loading