René's URL Explorer Experiment


Title: fix: run the binary directly in verify_binary instead of through a shell (CWE-78) by 07souravkunda · Pull Request #43 · browserstack/browserstack-local-ruby · GitHub

Open Graph Title: fix: run the binary directly in verify_binary instead of through a shell (CWE-78) by 07souravkunda · Pull Request #43 · browserstack/browserstack-local-ruby

X Title: fix: run the binary directly in verify_binary instead of through a shell (CWE-78) by 07souravkunda · Pull Request #43 · browserstack/browserstack-local-ruby

Description: What LocalBinary#verify_binary built its command by string concatenation: IO.popen(bin_path + " --version") The single-string form of IO.popen passes the whole string to /bin/sh, so shell metacharacters in the binary path are interpreted instead of being treated as part of a filename (CWE-78, command injection). This PR switches to the array form, which execs the binary directly and never involves a shell: IO.popen([bin_path, '--version']) Why it's reachable bin_path is assembled in binary_path from @ordered_paths — the expanded home directory, Dir.pwd, and Dir.tmpdir — and none of those is sanitised. A directory name containing ;, ` or $() anywhere in that chain turns a routine version check into arbitrary command execution. Reproduced end to end through the public LocalBinary#binary_path entry point (no private-method access, no monkey-patching): with $HOME set to a directory named h;touch /tmp/marker;echo BrowserStack Local version 9.9;#, the injected touch ran, and because the injected echo also satisfied the version regex, verify_binary returned true and binary_path handed back the poisoned path. After this change the marker is never created. Bonus: fixes a benign failure for paths with spaces The same shell splitting broke verification for any path containing a space — routine on macOS and Windows. verify_binary returned false for a perfectly good binary at …/my binary dir/BrowserStackLocal, so binary_path deleted the valid cached binary and re-downloaded it on every run. The array form fixes that too, and there's a test for it. Deliberately out of scope Each of these is tracked separately; folding them in would make this diff hard to audit: the fail-open rescue StandardError → false in this same method the TOCTOU window between verification and execution the other shell-string call sites in local.rb (logfile in system(), start_command / stop_command, verbatim extra args) A character allowlist on the path was considered and rejected: with no shell involved it adds no security on this line, and it would reject exactly the legitimate space-containing paths this change fixes. Validating the provenance of a caller-supplied binarypath is a separate concern from this internally-computed path. Also noted but unchanged: IO.popen's IO object is never closed and the child never reaped (fd + zombie leak). The block form would fix it but waits for the child to exit, which would hang on a binary that prints a line and keeps running — so the non-block form is kept. Tests Three regression tests in BrowserStackLocalBinaryTest, all verified to fail before this change (test file kept, lib/browserstack/localbinary.rb reverted to master): Test Pre-fix Post-fix test_verify_binary_does_not_interpret_shell_metacharacters_in_path Expected: false, Actual: true (marker created) pass test_verify_binary_runs_a_real_binary_at_a_path_containing_shell_metacharacters shell metacharacters in the binary path were executed pass test_verify_binary_accepts_a_path_containing_spaces Expected: true, Actual: false pass The middle one is the load-bearing guard: the first test returns false post-fix via Errno::ENOENT, so on its own it would also pass under a character-allowlist remediation rather than the array form. Putting the metacharacters in the directory name of a real executable asserts both halves at once — the injected command never runs, and the legitimate binary at that hostile-looking path still verifies. Suite, ruby 3.2.10, credentials exported — fully green: 26 runs, 50 assertions, 0 failures, 0 errors, 0 skips An earlier run on this branch showed 3 errors in test_check_pid / test_is_running / test_multiple_binary, which reproduced identically on a pristine master clone. Cause confirmed and now cleared: those three call start with no localIdentifier and contend for daemon port 45691, which was held on the test box by an unrelated BrowserStackLocal --app process. Once that process exited the same suite went green on this branch with no code change — so they were never related to this diff. CI / security gates — read this before merging semgrep/ci failed on the first push of this PR and is worth stating plainly rather than leaving for the reviewer to discover: 1 blocking finding, ruby.lang.security.dangerous-exec.dangerous-exec, code-scanning alert #13 at lib/browserstack/localbinary.rb:138 (job 94071567985, exit 1), which put the PR in mergeStateStatus: BLOCKED. It is a false positive on the fixed code: the rule fires on any non-static first argument to IO.popen and does not model the array form — which is precisely this fix, since no /bin/sh is spawned at all. Evidence that the diff did not introduce it: the identical rule has been open against master as alert #9 since 2026-06-04, on the pre-fix line 136. The diff re-anchors a pre-existing alert; it does not add one. Resolved by a rule-scoped # nosemgrep: ruby.lang.security.dangerous-exec.dangerous-exec on that one line with the reason inline (comment-only, no behaviour change — the regression tests and the injection PoC were re-run after it and are unchanged). Every other IO.popen/exec finding in this file still reports. Alternative, if you'd rather not carry an inline suppression: triage alerts #13 and #9 on the platform as false positives and drop the comment — either resolves both. Confirmed green after the fix-up: semgrep/ci=SUCCESS, plus Semgrep OSS, CodeQL, Analyze (ruby), Analyze (actions) — all 5 checks passing, mergeable: MERGEABLE. The PR still reads BLOCKED only because it is a Draft awaiting review approval (reviewDecision: REVIEW_REQUIRED), no longer because of a failing check. Live verification: a real tunnel was opened through the patched binding (BrowserStack::Local#start) and a selenium-webdriver BrowserStack session (Windows 11 / Chrome) loaded a local page over it via bs-local.com, then stopped cleanly through the binding's .stop(). The cached 36 MB binary at ~/.browserstack/BrowserStackLocal meant binary_path took the early-return branch, so the new array-form verify_binary ran against the genuine binary and returned true — the tunnel could not have come up otherwise.

Open Graph Description: What LocalBinary#verify_binary built its command by string concatenation: IO.popen(bin_path + " --version") The single-string form of IO.popen passes the whole string to /bin/sh, so shell...

X Description: What LocalBinary#verify_binary built its command by string concatenation: IO.popen(bin_path + " --version") The single-string form of IO.popen passes the whole string to /bin/sh, ...

Opengraph URL: https://github.com/browserstack/browserstack-local-ruby/pull/43

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:06a80e90-6419-acd0-e343-c7dfb6e8fd75
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE892:281ABB:757021:A0A5EB:6B04788F
html-safe-nonce63cd4644b3ae4465017a02a5e8ddafe0ec9974a9ab2e75a588fda15bf93addf8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODkyOjI4MUFCQjo3NTcwMjE6QTBBNUVCOjZCMDQ3ODhGIiwidmlzaXRvcl9pZCI6IjcyNjc2NzgwMjA2NTQzNjQ4MTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca081cd567b6882eb40f7a0a0f55488a931a8c0aaae5a229883822fc1a173e1c3
hovercard-subject-tagpull_request:4260994303
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/browserstack/browserstack-local-ruby/pull/43/files
twitter:imagehttps://avatars.githubusercontent.com/u/50537259?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/50537259?s=400&v=4
og:image:altWhat LocalBinary#verify_binary built its command by string concatenation: IO.popen(bin_path + " --version") The single-string form of IO.popen passes the whole string to /bin/sh, so shell...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/browserstack/browserstack-local-ruby git https://github.com/browserstack/browserstack-local-ruby.git
octolytics-dimension-user_id1119453
octolytics-dimension-user_loginbrowserstack
octolytics-dimension-repository_id51922935
octolytics-dimension-repository_nwobrowserstack/browserstack-local-ruby
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id51922935
octolytics-dimension-repository_network_root_nwobrowserstack/browserstack-local-ruby
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecf73f57448d52b3a7b619195e182b33d3b3454ca
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/browserstack/browserstack-local-ruby/pull/43/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbrowserstack%2Fbrowserstack-local-ruby%2Fpull%2F43%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbrowserstack%2Fbrowserstack-local-ruby%2Fpull%2F43%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=browserstack%2Fbrowserstack-local-ruby
Reloadhttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
Reloadhttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
Reloadhttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
browserstackhttps://github.com/browserstack
browserstack-local-rubyhttps://github.com/browserstack/browserstack-local-ruby
Codehttps://github.com/browserstack/browserstack-local-ruby
Issues1 (1)https://github.com/browserstack/browserstack-local-ruby/issues
Pull requests6 (6)https://github.com/browserstack/browserstack-local-ruby/pulls
Actionshttps://github.com/browserstack/browserstack-local-ruby/actions
Projectshttps://github.com/browserstack/browserstack-local-ruby/projects
Security and qualityhttps://github.com/browserstack/browserstack-local-ruby/security
Insightshttps://github.com/browserstack/browserstack-local-ruby/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fbrowserstack%2Fbrowserstack-local-ruby%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fbrowserstack%2Fbrowserstack-local-ruby%2Fissues%2Fnew%2Fchoose
07souravkundahttps://github.com/07souravkunda
release_1.5.1https://github.com/browserstack/browserstack-local-ruby/tree/release_1.5.1
locsec/WI-cf38e835https://github.com/browserstack/browserstack-local-ruby/tree/locsec/WI-cf38e835
Conversation 11 https://github.com/browserstack/browserstack-local-ruby/pull/43
Commits 3 https://github.com/browserstack/browserstack-local-ruby/pull/43/commits
Checks 5 https://github.com/browserstack/browserstack-local-ruby/pull/43/checks
Files changed https://github.com/browserstack/browserstack-local-ruby/pull/43/files
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
fix: run the binary directly in verify_binary instead of through a shell (CWE-78) https://github.com/browserstack/browserstack-local-ruby/pull/43/files#top
Show all changes 3 commits https://github.com/browserstack/browserstack-local-ruby/pull/43/files
db623c3 fix: run the binary directly in verify_binary instead of through a sh… 07souravkunda Aug 12, 2026 https://github.com/browserstack/browserstack-local-ruby/pull/43/commits/db623c310a26a4da1537b70079acac8fa9220c59
ab48704 chore: scope-limited scanner suppression on the fixed verify_binary line 07souravkunda Aug 12, 2026 https://github.com/browserstack/browserstack-local-ruby/pull/43/commits/ab487043276cf4d417e45d6ccf14bc22b80271a2
e766c21 test: pin the array-form behaviour with a real binary at a hostile path 07souravkunda Aug 12, 2026 https://github.com/browserstack/browserstack-local-ruby/pull/43/commits/e766c21cc59a46dde601bc04f32d606d73d2901f
Clear filters https://github.com/browserstack/browserstack-local-ruby/pull/43/files
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
localbinary.rb https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-ff72856ad039a5854f8fd99713be5ed4241f757a1fdfcda7dabd5de5633d924b
browserstack-local-test.rb https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-0bc53e459a5550e42da6e5efbfb46daea5f95fa50416654c15f71e83ba97fa70
https://github.com/browserstack/browserstack-local-ruby/blob/release_1.5.1/CODEOWNERS#L1
lib/browserstack/localbinary.rbhttps://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-ff72856ad039a5854f8fd99713be5ed4241f757a1fdfcda7dabd5de5633d924b
View file https://github.com/browserstack/browserstack-local-ruby/blob/e766c21cc59a46dde601bc04f32d606d73d2901f/lib/browserstack/localbinary.rb
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/browserstack/browserstack-local-ruby/pull/43/{{ revealButtonHref }}
https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-ff72856ad039a5854f8fd99713be5ed4241f757a1fdfcda7dabd5de5633d924b
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765538352
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
job loghttps://github.com/browserstack/browserstack-local-ruby/actions/runs/31583419972/job/94071567985
#13https://github.com/browserstack/browserstack-local-ruby/pull/13
fix: run the binary directly in verify_binary instead of through a shell (CWE-78) #43https://github.com/browserstack/browserstack-local-ruby/pull/43
updated gemspec #9https://github.com/browserstack/browserstack-local-ruby/pull/9
#13https://github.com/browserstack/browserstack-local-ruby/pull/13
#9https://github.com/browserstack/browserstack-local-ruby/pull/9
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765588084
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
#13https://github.com/browserstack/browserstack-local-ruby/pull/13
#9https://github.com/browserstack/browserstack-local-ruby/pull/9
updated gemspec #9https://github.com/browserstack/browserstack-local-ruby/pull/9
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765626107
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765660626
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
updated gemspec #9https://github.com/browserstack/browserstack-local-ruby/pull/9
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-ff72856ad039a5854f8fd99713be5ed4241f757a1fdfcda7dabd5de5633d924b
https://github.com/browserstack/browserstack-local-ruby/blob/release_1.5.1/CODEOWNERS#L1
test/browserstack-local-test.rbhttps://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-0bc53e459a5550e42da6e5efbfb46daea5f95fa50416654c15f71e83ba97fa70
View file https://github.com/browserstack/browserstack-local-ruby/blob/e766c21cc59a46dde601bc04f32d606d73d2901f/test/browserstack-local-test.rb
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/browserstack/browserstack-local-ruby/pull/43/{{ revealButtonHref }}
https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-0bc53e459a5550e42da6e5efbfb46daea5f95fa50416654c15f71e83ba97fa70
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765539779
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765590044
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
07souravkundahttps://github.com/07souravkunda
Aug 12, 2026https://github.com/browserstack/browserstack-local-ruby/pull/43/files#r3765662274
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
https://github.com/browserstack/browserstack-local-ruby/pull/43/files#diff-0bc53e459a5550e42da6e5efbfb46daea5f95fa50416654c15f71e83ba97fa70
Please reload this pagehttps://github.com/browserstack/browserstack-local-ruby/pull/43/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.