Skip to content

Restrict gltf URIs to relative paths by default; add --allowAbsolute as fallback to insecure behavior. #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions bin/gltf-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const argv = yargs
type: "boolean",
default: false,
},
"allow-absolute": {
alias: "a",
describe:
"Allow gltf files to refer to file URLs outside of their source path",
type: "boolean",
default: false,
},
json: {
alias: "j",
describe: "Convert the input glb to glTF.",
Expand Down Expand Up @@ -204,8 +211,15 @@ const options = {
dracoOptions: dracoOptions,
baseColorTextureNames: argv.baseColorTextureNames,
baseColorFactorNames: argv.baseColorFactorNames,
allowAbsolute: argv.allowAbsolute,
};

if (options.allowAbsolute) {
console.warn(
"Warning: Allowing absolute buffer URIs; please double-check your gltf for potentially dangerous buffer URIs.",
);
}

const inputIsBinary = inputExtension === ".glb";
const outputIsBinary = outputExtension === ".glb";

Expand Down
5 changes: 5 additions & 0 deletions lib/readResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ function readFile(object, uri, saveResourceId, options) {
? path.relative(resourceDirectory, absolutePath)
: path.basename(absolutePath);

if (relativePath.startsWith("..") && !options.allowAbsolute) {
throw new Error(
`Absolute paths are not permitted; use --allowAbsolute to disable this error.`,
);
}
if (!defined(object.name)) {
const extension = path.extname(relativePath);
object.name = path.basename(relativePath, extension);
Expand Down