Skip to content

Select the SOAP binding that matches the request envelope - #1335

Open
2836048681 wants to merge 1 commit into
loopbackio:masterfrom
2836048681:fix/345-select-soap-binding
Open

2836048681 wants to merge 1 commit into
loopbackio:masterfrom
2836048681:fix/345-select-soap-binding

Conversation

@2836048681

Copy link
Copy Markdown

When SOAP 1.1 and SOAP 1.2 WSDL ports share a URL, the server uses the first port listed at that path. With the SOAP 1.1 port listed first, a SOAP 1.2 request can run the SOAP 1.1 handler and receive a SOAP 1.1 Fault.

Record the SOAP version from each WSDL binding and prefer the port at the request path whose binding matches the envelope namespace. Fall back to the first port at that path when no version matches, or to the first WSDL port when no path matches.

Closes #345

Tests

  • The shared address regression exercises both SOAP versions over HTTP and checks the fault namespace and body. Before the fix the SOAP 1.2 case received the SOAP 1.1 fault. Both cases pass with the fix.
  • npm run build passed on Node.js 24.22.1.
  • npm test reported 255 passing and 5 pending, with one timeout in a test that calls a public Marketo endpoint. The same test timed out on the unmodified base. Rerunning with only that test excluded produced 255 passing and 5 pending.

Fixes #345.

@achrinza achrinza left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contributions @2836048681. Please do the DCO signoff as yourself (the human operating the agent) instead of the coding agent itself. Note that the email address can be your GitHub hidden email address (ending in @users.noreply.github.com)

Please do note the implications of a DCO sign off (which used in place of a CLA): https://loopback.io/doc/en/contrib/code-contrib.html#developer-certificate-of-origin-dco.


Please also follow Conventional Commits for the commit message.


I've added some comments for your kind amendments.


A change on (incorrect) behaviour to note:

On the old fallback path, serviceName and portName came from the last port the loop visited, while binding came from the first. This PR fixes this as well. Though setups that (incorrectly) only implemented handlers for the last port worked before by accident and will now break. No changes needed for this. Just documenting it here for posterity.

Comment thread src/server.js
Comment on lines +25 to +26
const SOAP11_ENVELOPE = 'http://schemas.xmlsoap.org/soap/envelope/';
const SOAP12_ENVELOPE = 'http://www.w3.org/2003/05/soap-envelope';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the refactor. Can we go one step and get rid of these in favour of helper.namespaces.soap / .soap12?

Comment thread src/parser/xmlHandler.js
}

xmlToJson(nsContext, xml, descriptor) {
xmlToJson(nsContext, xml, descriptor, onRootElement) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note this signature change to include a callback. May lead to argument bloat over time if we keep adding callbacks.

One potential alternative is a dedicated static helper to extract the root element:

// src/parser/xmlHandler.js
static parseRootQName(xml) {
  const parser = sax.parser(true, {xmlns: true});
  let root;
  parser.onopentag = function(node) {
    if (!root) root = new QName(node.uri, node.local, node.prefix);
  };
  parser.onerror = function() { parser.error = null; parser.resume(); };
  // Only feed until the root tag has been seen
  for (let i = 0; i < xml.length && !root; i += 1024) {
    parser.write(xml.slice(i, i + 1024));
  }
  return root;
}

Then it can be used as such:

// src/server.js _process
const root = XMLHandler.parseRootQName(input);
const soapVersion = root && root.name === 'Envelope' &&
  {[SOAP11_ENVELOPE]: '1.1', [SOAP12_ENVELOPE]: '1.2'}[root.nsURI];
const obj = this.xmlHandler.xmlToJson(null, input);

Not a big blocker for me, but to consider for long-term maintainability.

Signed-off-by: MingYang Lu <121647131+2836048681@users.noreply.github.com>
@2836048681
2836048681 force-pushed the fix/345-select-soap-binding branch from e9180f3 to 40ffffb Compare December 2, 2026 08:56
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.

SOAP fault coerces SOAP 1.2 request to SOAP 1.1 response

2 participants