Skip to content

fix(odata-service-writer): avoid double slashes when adding new odata service #3197

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

Closed
wants to merge 4 commits into from

Conversation

815are
Copy link
Contributor

@815are 815are commented Apr 28, 2025

Problem happens if we pass service like:

{
  annotations: [
    {
      technicalName: '/TEST/DUMMY_SERVICE'
    }
  ]
}

then double forward slash is added here:
image

As fix - sanitize trailing slashes before creating uri for settings.localUri - trimSlashes

avoid double slashes when adding new data service
@815are 815are added the odata-service-writer @sap-ux/odata-servier-writer label Apr 28, 2025
Copy link

changeset-bot bot commented Apr 28, 2025

🦋 Changeset detected

Latest commit: 70fc4ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@sap-ux/odata-service-writer Patch
@sap-ux/adp-tooling Patch
@sap-ux/create Patch
@sap-ux/fiori-app-sub-generator Patch
@sap-ux/fiori-elements-writer Patch
@sap-ux/fiori-freestyle-writer Patch
@sap-ux/generator-simple-fe Patch
@sap-ux/adp-flp-config-sub-generator Patch
@sap-ux/flp-config-inquirer Patch
@sap-ux/generator-adp Patch
@sap-ux/preview-middleware Patch
@sap-ux/repo-app-import-sub-generator Patch
@sap-ux/flp-config-sub-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@815are 815are changed the title fix(odata-service-writer): avoid double slashes when adding new data service fix(odata-service-writer): avoid double slashes when adding new odata service Apr 28, 2025
815are added 3 commits April 28, 2025 09:57
changelog
additional test
sonar
Copy link

@815are 815are marked this pull request as ready for review April 28, 2025 07:52
@815are 815are requested a review from a team as a code owner April 28, 2025 07:52
* @returns The input string with leading and trailing slashes removed.
*/
function trimSlashes(input: string): string {
while (input.startsWith('/')) {
Copy link
Contributor

@IainSAP IainSAP Apr 28, 2025

Choose a reason for hiding this comment

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

Could this be used as an attack vector? Consider a limit on string size, or use regex with same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regex was giving following sonar issue for me:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think you would need to add a character limit anyway or Sonar would complain about DOS attack. Previously we needed to limit the '/' check.

// We remove trailing slashes (up to 10, infinite would allow DOS attack) from the host to avoid double slashes when appending the service path.
        this._destinationUrl = servicePath
            ? destUrl.replace(
                  `https://${destination.Name.toLowerCase()}.dest`,
                  destination.Host.replace(/\/{1,10}$/, '')
              )
            : destination.Host;

@815are 815are marked this pull request as draft April 29, 2025 13:22
@815are 815are closed this Jul 22, 2025
@815are 815are deleted the fix/avoidDoubleSlashesWhenAddingNewDataSource branch July 22, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
odata-service-writer @sap-ux/odata-servier-writer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants