Skip links
Picture of Vahagn Vardanian

Vahagn Vardanian

Co-founder and CTO of RedRays

BSP Page Directive & , SAP security note 887168

SAP Note 887168

SAP security note 887168, “XSS Protection in BSP Page Directives”, is released on 08.10.2009. Below are the symptom and SAP recommended solution.

ComponentBC-BSP (Basis Components > Business Server Pages)
StatusReleased for Customer
Released on08.10.2009

Description

This security note addresses Cross-Site Scripting (XSS) vulnerabilities in SAP BSP (Business Server Pages) applications. XSS attacks can occur when user input is not properly validated and is directly rendered in the HTTP response, allowing malicious scripts to execute in the user’s browser.

Symptom

Vulnerable code may look like this:

<%@page language="abap"%>
<html><body><form>
  <% data: x type string.
     x = request->get_form_field( 'x' ).
  %>
  <input type=text name=x value="<%=x%>">
  <input type=submit>
</form></body></html>

In this example, input from the HTTP request is used directly in the response without validation, enabling potential XSS attacks.

Solution

To mitigate XSS vulnerabilities, it is essential to HTML encode all strings before rendering them. There are two primary approaches:

  • Manual Encoding: Developers can manually HTML encode user inputs:
    <% data: x type string.
       x = request->get_form_field( 'x' ).
       x = cl_http_utility=>html_encode( x ).
    %>
    <input type=text name=x value="<%=x%>">
  • Automated Encoding with Page Attribute: Enhance application security by adding the forceEncode attribute in the BSP page directive. This ensures all print statements are automatically HTML encoded:
    <%@page language="abap" forceEncode="html"%>
    <html><body><form>
      <% data: x type string.
         x = request->get_form_field( 'x' ).
      %>
      <input type=text name=x value="<%=x%>">
      <input type=submit>
    </form></body></html>

    The forceEncode attribute can be set to html, url, or javascript, depending on the encoding required.

Important: Do not confuse the print statement encoding with BSP element attribute encoding. For BSP elements, encoding should be handled within the element’s domain.

References

Full note on SAP: SAP Support Launchpad note 887168

Detailed exploitation and proof-of-concept material for this note is maintained in the RedRays Security Platform. For access, contact [email protected].

Explore More