SAP SQL INJ AMDP SCRTY
Get Example source ABAP code based on a different SAP table
SQL Injections Using AMDP
When
There are currently no test tools available for checking the security of the implementation of a AMDP methods. Developers of AMDP methods are themselves responsible for their security, with dual control (Code Inspections) being a useful principle here. This is partly why the use of dynamic programming techniques is strongly
Implementations of
Latest notes:
The statements about AMDP made here apply in principle to all places in which implementations made in other programming languages are called from ABAP.
ABAP_HINT_END
Example ABAP Coding
An AMDP method is implemented as follows:
METHOD increase_seatsocc BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT.
EXEC 'UPDATE sflight SET seatsocc = seatsocc + ' || :seats;
ENDMETHOD.
ENDCLASS.>
This method uses the SQLScript statement
If the method is delivered without an appropriate check and the caller wants to pass value entered outside to it, the validity of the value must be checked first. In the case in question, only integers can be passed, which can be verified using the method
cl_demo_input=>request( CHANGING field = seats ).
TRY.
NEW cl_dyn_amdp( )->increase_seatsocc(
seats = |{ cl_abap_dyn_prg=>check_int_value( seats ) }| ).
CATCH cx_abap_not_an_integer INTO DATA(exc).
cl_demo_output=>display( exc->get_text( ) ).
ENDTRY.>
ABAP_EXAMPLE_END
Example ABAP Coding
An AMDP method is implemented as follows:
METHOD get_flights BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT
USING spfli.
flights = SELECT * FROM SPFLI WHERE mandt = :mandt;
flights = APPLY_FILTER(:flights, :filter);
ENDMETHOD.
ENDCLASS.>
This method uses the SQLScript statement
cl_demo_input=>add_field( CHANGING field = column ).
DATA value TYPE string.
cl_demo_input=>request( CHANGING field = value ).
TRY.
DATA(filter) = cl_abap_dyn_prg=>check_column_name( column )
` = `
cl_abap_dyn_prg=>quote( value ).
NEW cl_dyn_amdp( )->get_flights( EXPORTING mandt = sy-mandt
filter = filter
IMPORTING flights = DATA(result) ).
CATCH cx_abap_invalid_name cx_amdp_execution_failed INTO DATA(exc).
cl_demo_output=>display( exc->get_text( ) ).
ENDTRY.>
ABAP_EXAMPLE_END