Skip to content
Merged
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
2 changes: 2 additions & 0 deletions documentation/docs/experimental/includeBytes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration-tests/js-compute/.hidden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is for the includeBytes sandbox test
1 change: 1 addition & 0 deletions integration-tests/js-compute/fixtures/app/.hidden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idk
20 changes: 20 additions & 0 deletions integration-tests/js-compute/fixtures/app/src/include-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
Loading