Skip to content

Conversation

@steilerDev
Copy link

In a hardened environment, where shell access has been restricted, spinning up Backtrace leads to an unhandled exception:

node:internal/child_process:1120
    at new AttributeManager (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/sdk-core/lib/bundle.cjs:572:18)
    result.error = new ErrnoException(result.error, 'spawnSync ' + options.file);
                   ^
<ref *1> Error: spawnSync /bin/sh ENOENT
    at Object.spawnSync (node:internal/child_process:1120:20)
    at spawnSync (node:child_process:902:24)
    at Object.execSync (node:child_process:983:15)
    at MachineIdentitfierAttributeProvider.get (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/node/lib/bundle.cjs:878:33)
    at MachineIdentitfierAttributeProvider.generateGuid (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/node/lib/bundle.cjs:901:38)
    at AttributeManager.addProvider (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/sdk-core/lib/bundle.cjs:598:50)
    at new BacktraceCoreClient (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/sdk-core/lib/bundle.cjs:3042:33)
    at new BacktraceClient (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/node/lib/bundle.cjs:1162:9)
    at BacktraceClientBuilder.build (/usr/local/lib/node_modules/icloud-photos-sync/node_modules/@backtrace/node/lib/bundle.cjs:977:26) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawnSync /bin/sh',
    '-c',
  spawnargs: [
  path: '/bin/sh',
    '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :'
  error: [Circular *1],
  ],
  status: null,
  output: null,
  signal: null,
  pid: 0,
  stdout: undefined,
  stderr: undefined
}
Node.js v22.20.0

The proposed change handles any exception thrown, to return null and triggering the existing fallback case const guid = this.generateGuid() ?? IdGenerator.uuid();

Copy link
Contributor

@rick-bt rick-bt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @steilerDev! This would mask multiple exception types which is risky. Can't take this into main as-is. A good alt would be to not punch out to shell to get a consistent identifier, if you want to give that a try. Compose a few machine-stable identifiers and hash it to a uuid.

@steilerDev
Copy link
Author

Hey @rick-bt - I fully understand your input, my proposal is a very quick and dirty "fix".

However, the challenge I'm facing in my execution environment is that it's a hardened, ephemeral Docker container: No system tools or shell available, besides nodejs. Therefore any fingerprint created, would probably not survive a container restart.

I do have a user identifier available - maybe the 'correct' solution would be an option to allow the dev to supply a MachineIdentifier to the lib as a configuration option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants