fix(compiler): reject includes that leave the sketch project before arduino-cli runs - #160
Merged
Merged
Conversation
…rduino-cli runs The REST compiler runs arduino-cli in the backend. An absolute or traversing include made it read any readable file and echo it in diagnostics (verified with a synthetic sentinel file). The env-leak part of the audit finding was falsified: /proc/*/environ reads as empty for both compilers in use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Purpose
R1 of the refactoring series (
docs/UNOSIM_REFACTORING_OPL.md), audit finding S1.POST /api/compilerunsarduino-cliinside the backend process/container, not in a sandbox. Unresolved#includelines are passed through unchanged and stderr reaches the client unfiltered.Verification of the finding (synthetic sentinels only)
#include "<file>"makes the compiler read any readable file and echo it in diagnosticsarduino-cli)/proc/self/environ//proc/1/environ#includeand.incbin; a synthetic env variable never appeared. No env allowlist is added..incbinembeds regular files into the HEX, which the REST response currently returns.includein inline asm echoes ~10 leading chars per line in assembler errors; string-literal concatenation defeats textual filteringBLOCKED_DECISION(sandboxed REST compile is an architecture decision)Change
server/services/compiler/include-guard.ts: conservative scan of every submitted file (main + headers) after line splicing. A directive candidate is any#/%:/??=preceded only by whitespace or comments.include,include_next,import,embedand__has_include(_next)must name a literal"file"or<file>that is not absolute, has no backslash, and – for quoted names – stays inside the project relative to the including file; angled names may not contain... Computed includes and escaped directive names are rejected.ArduinoCompiler.compileInternalrejects such sketches before the cache orarduino-cliis consulted, with a normal compile error (file:line: error: …).Tests
tests/server/services/compiler/include-guard.test.ts(25 cases incl. digraph, splices, comments, computed and project-internal../includes),tests/server/services/arduino-compiler-include-guard.test.ts(2).tests/integration/compile-include-boundary.test.tsin theintegration-toolchainproject: with realarduino-cli, the sentinel was in the response before the fix and is absent after it.../shared/pins.htests stay green (entry file insrc/).npm run check, ESLint, unit 2697 passed, integration-toolchain 15/15, pre-push incl. Sonar quality gate PASSED.🤖 Generated with Claude Code