Skip to content

Snapshot import 500s on a few env shapes, and leaks the raw error #8568

Description

@cstns

POST /api/v1/snapshots/import hands back a 500 for a few ordinary payloads, and the response carries the raw Node error text.

uploadSnapshot in forge/db/controllers/Snapshot.js reads the incoming env unguarded:

const keys = Object.keys(snapshot.settings.env)
keys.forEach((key) => {
    const env = snapshot.settings.env[key]
    if (env.hidden && env.$) {
        env.value = decryptValue(credentialSecret, env.$)

Three ways that blows up, all reproduced against a local platform:

  • no settings.env at all (the route's own body schema doesn't require it), 500 Cannot convert undefined or null to object
  • an env value of null, 500 on env.hidden
  • a snapshot with encrypted hidden env values and no credentialSecret, 500 The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

The third one also happens when the env vars are being thrown away anyway (components.envVars: false or "keys"), because the decrypt loop runs over the original snapshot before the component filtering is applied.

The raw messages go straight to the caller, which isn't great for a public endpoint.

Might be worth defaulting env to {}, skipping values that aren't objects, and returning a 400 when a secret is genuinely needed but missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiWork on the platform APItype:bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions