Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.1k stars 1.21k forks source link

Cannot create subscription inside topic in Azure Service Bus (JavaScript) #30979

Open CezaryBD opened 3 months ago

CezaryBD commented 3 months ago

Describe the bug The bug is happening on Mozilla Firefox browser only (so far). It seems that while executing subscription creation, there is a problem with xml payload created only on Mozilla Firefox browser.

To Reproduce Steps to reproduce the behavior:

  1. Create subscription like:
    
    this._sbAdminClient.createSubscription(
                        `myApp-${user}`, 
                        azureSubscriptionId,
                        {
                            autoDeleteOnIdle: 'PT1H',
                        }
                    )
    // {user} variable here is just a simple string and it does contain only simple latin characters

**Expected behavior**
Fix ASAP Mozilla Firefox integration with your library or provide a workaround.

**Screenshots**
n/a

**Additional context**
XML faulty payload generated by Firefox:
```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entry>
    <updated>2024-09-03T07:41:08.210Z</updated>
    <content type="application/xml">
        <SubscriptionDescription
            xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <AutoDeleteOnIdle>PT1H</AutoDeleteOnIdle>
        </SubscriptionDescription>
    </content>
</entry>

Response: 400 BAD_REQUEST Body:

<Error>
<Code>400</Code>
<Detail>The specified resource description is invalid.
 TrackingId: <id>, 
 SystemTracker:*name of my service bus*:Topic:*name of my topic*, 
 Timestamp:2024-08-16T08:05:54
</Detail>
</Error>
jeremymeng commented 3 months ago

@CezaryBD thanks for reporting the issue! It may be related to this issue https://github.com/Azure/azure-sdk-for-js/issues/4983

However, even if we had correct XML payload, this scenario wouldn't work in a secure environment either due to Azure Service Bus service not supporting CORS for the ATOM management API in browsers: https://github.com/Azure/azure-sdk-for-js/issues/4983

CezaryBD commented 2 months ago

Hi @jeremymeng, thanks for quick response. What is the workaround or proposed solution? Our project's functionality relies on this API's method.

jeremymeng commented 2 months ago

Hi @jeremymeng, thanks for quick response. What is the workaround or proposed solution? Our project's functionality relies on this API's method.

The CORS issue need support from the service team. But since you were able to send requests that means you already have a way around it?

Do you have to run the service bus code in the browsers? One alternative is to have a NodeJS backend to do that.

jeremymeng commented 2 months ago

@CezaryBD there's an untested and unsupported way to switch to use fast-xml-parser. It will increase the bundle size of your app.

cat '.\patches\@azure+core-xml+1.4.3.patch'


diff --git a/node_modules/@azure/core-xml/dist/browser/index.js b/node_modules/@azure/core-xml/dist/browser/index.js
index e3caeef..595f7fb 100644
--- a/node_modules/@azure/core-xml/dist/browser/index.js
+++ b/node_modules/@azure/core-xml/dist/browser/index.js
@@ -1,5 +1,5 @@
 // Copyright (c) Microsoft Corporation.
 // Licensed under the MIT license.
-export { stringifyXML, parseXML } from "./xml.js";
+export { stringifyXML, parseXML } from "../esm/xml.js";
 export { XML_ATTRKEY, XML_CHARKEY } from "./xml.common.js";
 //# sourceMappingURL=index.js.map
\ No newline at end of file```
CezaryBD commented 2 months ago

I currently have no CORS issues whatsoever, but I do have issues that e.g. in the Microsoft Edge the payload generated looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entry
    xmlns="http://www.w3.org/2005/Atom">
    <updated>2024-09-03T06:39:22.891Z</updated>
    <content type="application/xml">
        <SubscriptionDescription
            xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
            xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <AutoDeleteOnIdle>PT1H</AutoDeleteOnIdle>
        </SubscriptionDescription>
    </content>
</entry>

whereas generated for Firefox looks like in the original ticket.

Will there be a tested and supported way or do you completely stop supporting browsers?

Yes, I need to run Service Bus subscription creation code on our browser side, this is a critical part of our project's architecture. If I move it to our backend, what's the point of existence for this library?

jeremymeng commented 2 months ago

If I move it to our backend, what's the point of existence for this library?

This package supports both browsers and NodeJS.

I'd thought I linked to this above but apparently, I linked to the same issue twice... Yes, this is a bug on only FireFox. We will look into it. https://github.com/Azure/azure-sdk-for-js/issues/11655