Skip to content
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

Error when using apiPost with multipart in v5.0.1: "Signature hash does not match" #49

Open
hendaniel opened this issue May 10, 2024 · 3 comments

Comments

@hendaniel
Copy link

hendaniel commented May 10, 2024

Description

When attempting to make a POST request using the apiPost function with multipart/form-data in Node.js 18.16.1 and using sailthru-client version 5.0.1, I encounter a signature hash mismatch error. The error message returned is {"error":5,"errormsg":"Signature hash does not match"}. This issue does not occur when using sailthru-client version 5.0.0.

Steps to Reproduce

  1. Set up a Node.js environment with version 18.16.1.
  2. Use sailthru-client version 5.0.1.
  3. Implement a POST request using the apiPost function with multipart/form-data.
  4. Execute the request.

Expected Behavior

The API should successfully process the multipart POST request without returning a signature hash mismatch error.

Actual Behavior

The API call fails and returns the following error message: {"error":5,"errormsg":"Signature hash does not match"}. The error does not occur when downgrading to sailthru-client version 5.0.0.

Environment

  • OS: macOS
  • Node.js version: 18.16.1
  • Relevant libraries/frameworks:
    • sailthru-client version 5.0.1 (error occurs)
    • sailthru-client version 5.0.0 (no error)
  • Payload:
      const config = {
        job: 'update',
        report_email: 'email',
        file: './file.csv',
      }
      const multipart_params = ['file'] 
      apiPost('job', config, multipart_params)


@marcelhamel
Copy link
Contributor

After digging in, it seems that the issue is potentially this piece of code, line 300 in lib/sailthru.js:

json_payload_to_log = json_payload;

This appears to cause both variables to point to the same spot in memory, which means that when the following for/in loop runs immediately afterward....

for (param in binary_data) {
      value = binary_data[param];
      json_payload[param] = value;
      json_payload_to_log[param] = '[TRUNCATED]';
}

... the payload's file data is simply changed to a string value of '[TRUNCATED]' rather than the actual file object which needs to be passed. The signature hash itself is valid, but the invalid file format is throwing this error on the Sailthru backend for whatever reason. Changing the above variable definition to json_payload_to_log = this._json_payload(data) appears to completely remedy this issue.

@hendaniel
Copy link
Author

Thanks for looking into this! I'll be on the lookout for the fix release. We are also dealing with the JavaScript memory issue that was addressed in v5.0.1, so any updates would be greatly appreciated.

@expe
Copy link
Contributor

expe commented May 20, 2024

Thanks @marcelhamel, I've merged your PR and released 5.0.2.
@hendaniel could you try 5.0.2 to see if this fixes multipart POST requests for you?

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

No branches or pull requests

3 participants