diff --git a/documentation/docs/experimental/includeBytes.mdx b/documentation/docs/experimental/includeBytes.mdx index 9ec78512a6..1a2ddb9a58 100644 --- a/documentation/docs/experimental/includeBytes.mdx +++ b/documentation/docs/experimental/includeBytes.mdx @@ -10,6 +10,8 @@ The **`includeBytes()`** function is used embed a file as a Uint8Array. >**Note**: Can only be used during build-time initialization, not when processing requests. +>**SECURITY**: `includeBytes()` is fully sandboxed to prevent access to files outside the directory that contains `fastly.toml`. All other files within that scope will be accessible, including through `..` and symlink navigation, including potentially sensitive files such as `.env`. + ## Syntax ```js diff --git a/integration-tests/js-compute/.hidden.txt b/integration-tests/js-compute/.hidden.txt new file mode 100644 index 0000000000..2c13915354 --- /dev/null +++ b/integration-tests/js-compute/.hidden.txt @@ -0,0 +1 @@ +this is for the includeBytes sandbox test diff --git a/integration-tests/js-compute/fixtures/app/.hidden.txt b/integration-tests/js-compute/fixtures/app/.hidden.txt new file mode 100644 index 0000000000..a453e43b88 --- /dev/null +++ b/integration-tests/js-compute/fixtures/app/.hidden.txt @@ -0,0 +1 @@ +idk diff --git a/integration-tests/js-compute/fixtures/app/src/include-bytes.js b/integration-tests/js-compute/fixtures/app/src/include-bytes.js index d10dbda348..14ea136ffe 100644 --- a/integration-tests/js-compute/fixtures/app/src/include-bytes.js +++ b/integration-tests/js-compute/fixtures/app/src/include-bytes.js @@ -17,11 +17,31 @@ routes.set('/includeBytes', () => { }); let nope = null; +let dotfileNotOk = null; +let dotfileOk = null; try { nope = includeBytes('../../../../README.md'); } catch {} +try { + dotfileOk = includeBytes('./.hidden.txt'); +} catch {} + +try { + dotfileNotOk = includeBytes('../../.hidden.txt'); +} catch {} + routes.set('/includeBytes/sandbox', () => { assert(nope, null, 'includeBytes sandboxes its path to the project dir'); + assert( + dotfileNotOk, + null, + 'includeBytes sandboxes its path to the project dir', + ); + assert( + Array.from(dotfileOk), + [105, 100, 107, 10], + 'dotfile is included just fine', + ); });