Prevention of Cross-site Scripting (XSS) on SAPUI5

Prevention of Cross-site Scripting (XSS) on SAPUI5

Before I'm going to explain how we can prevent this type of issue in our SCP environment, I'd like to talk to you that problem can ocurr in any time and place if you don't prevent it! Now, I want you imagining for a moment that you were writing and testing a SAPUI5 application:

You have realized you could access another informations if you had passed other information through the JS when the application have called the OData through F12 on the Browser. But this must not happening never!

N?o foi fornecido texto alternativo para esta imagem

What is XSS?

Cross-site scripting (XSS) is a code injection attack that allows an attacker to execute malicious JavaScript in another user's browser.

Cross-site scripting (XSS) can be prevented by ensuring that it is not possible to inject script code into an application page that runs in a browser.

Controls must prohibit writing scripts to the page that comes from the application or from business data saved by a different user. To ensure this, the following two measures must be combined:

Validation of typed control properties

  • SAPUI5 core validates the value of properties set by the application against the type of the property. This guarantees that an int is always an int, and a sap.ui.core/CSSSize is a string representing a CSS size and does not contain a script tag. This also applies to enumerations and control IDs. The control renderer can rely on this check when writing the HTML. Property values that are typed in this way can be written without escaping.

Escaping

  • Control developers must ensure that string control properties and other values coming from the application and not sufficiently typed to rule out script tags being contained are escaped when written to the HTML. For this, the RenderManager and SAPUI5 core provide helper methods.

Avoiding XSS for a New Renderer

To ensure maximum security for a renderer, note the following:

  • For control properties, always use the most specific type that is available. For example, use sap.ui.core/CSSSize instead of string and instead of sap.ui.core/string for control properties that refer to a CSS size.
  • Use helper methods to escape the value of a string property that is written to the HTML:
  1. Use writeEscaped(oControl.getSomeStringProperty()) instead of just write(...) for writing plainly to the HTML.
  2. Use writeAttributeEscaped("someHtmlProperty", oControl.getSomeStringProperty()) instead of just writeAttribute(...) for writing attributes.
  3. Use jQuery.sap.encodeHTML(oControl.getSomeStringProperty()) for string properties where none of the other two options is possible to escape the string and then process it further.
N?o foi fornecido texto alternativo para esta imagem
  • Check your HTML coding whether application values can make their way into the HTML:
  1. Check where the variable values come from: Can the application set a value directly or only decide which of the hardcoded values are used?
  2. Escape values given in parameters in method calls of controls because they are currently not validated by SAPUI5 core.
  3. Keep in mind that XSS can happen anywhere and anytime in CSS classes, or in styles.
N?o foi fornecido texto alternativo para esta imagem

And the backend?

We don't never forget about the backend too! Never, never, never! On the Frontend we need to worry about Screen Rules and How these informations on the screen will persist in our Model, ok?

Thats right.

Before all the information persisting in our backend, we need to prevent the Model too. Does not matter if the Frontend is working against XSS, we must prevent the backend even so and even It causes double check on the information.

Double check for what? Before all the information will have been sent through OData to the Database.

If your RFC on the backend uses, for example, PERNR as Input field, first you must test your RFC if that user login is the same user for the PERNR field too.

In this way, we prevent both the backend and the frontend! 

N?o foi fornecido texto alternativo para esta imagem

Let me know if you have any doubts! Please, share and comment this topic. :)

Fabiana Bacon - SAP Cloud Platform Solutions Architect




Rajnish Kumar

SAP UI5 | FIORI | BAS CONSULTANT

5 年

Thanks for a very informative article. If you have some code samples on XSS prevention Plz share here. It will be more useful i believe.

Fabiana Bacon ??

Data, Analytics and AI Manager

5 年

Wouter van Heddeghem ?? please, share my new article ??

回复
Radhesh Shinde

SAP Fiori Full Stack Consultant @ Tech Mahindra | Architecture and Development

5 年

Thanks very helpful

要查看或添加评论,请登录

Fabiana Bacon ??的更多文章

  • Curso Gratuito de SAP ABAP

    Curso Gratuito de SAP ABAP

    WRITE 'Hello World'. Esse foi o primeiro comando que os meus alunos da INICIATIVA ABAP - Nome dado ao Curso Gratuito e…

    72 条评论
  • 3rd Class of the Cloud Course

    3rd Class of the Cloud Course

    What's up, Cloud Girl? Cloud Boy? xD First of all, join our group on Telegram: Cloud_All Missed your first class? Click…

    4 条评论
  • 3a Aula do Curso de Cloud

    3a Aula do Curso de Cloud

    E aí, Menina da Nuvem? Menino da Nuvem? xD Antes de tudo, junte-se ao nosso grupo no Telegram: Cloud_All Perdeu alguma…

    17 条评论
  • 2nd Class of the Cloud Course

    2nd Class of the Cloud Course

    What's up, Cloud Girl? Cloud Boy? xD First of all, join our group on Telegram: Cloud_All Missed your first class? Click…

    6 条评论
  • 2a Aula do Curso de Cloud

    2a Aula do Curso de Cloud

    E aí, Menina da Nuvem? Menino da Nuvem? xD Antes de tudo, junte-se ao nosso grupo no Telegram: Cloud_All Perdeu a…

    17 条评论
  • Welcome to the Cloud Course

    Welcome to the Cloud Course

    What's up, Cloud Girl? Cloud Boy? xD First of all, join our Telegram Group: Cloud_All Have you seen Dragon Ball??? Goku…

    12 条评论
  • Seja Bem-vinda(o) ao Curso de Cloud

    Seja Bem-vinda(o) ao Curso de Cloud

    E aí, Menina da Nuvem? Menino da Nuvem? xD Antes de tudo, junte-se ao nosso grupo no Telegram: Cloud_All Já viu Dragon…

    49 条评论
  • Como Eu Evoluí no Inglês!

    Como Eu Evoluí no Inglês!

    Olá, Linkedianos! (Portuguese Content) Queria contar sobre a minha evolu??o no Inglês e falar um pouquinho de minha…

    92 条评论
  • CER006: More interesting than SAP Certification Day? Is it true?!

    CER006: More interesting than SAP Certification Day? Is it true?!

    Yes, it's true! haha Option for SAP? Certifications beyond to the Certification Day? = "CER006" That's a tip given by…

    2 条评论
  • Getting started in SAP Cloud Platform: Learn the basics concepts - Part II

    Getting started in SAP Cloud Platform: Learn the basics concepts - Part II

    Hi, my friends! Fiiiiiiiiirst, if you are reading this subject without read the Part I, please see here: Getting…

    7 条评论

社区洞察

其他会员也浏览了