1

I am making form with user input form as you can see the image.

enter image description here

Because of XSS, I am using Apex's own security option:

Restricted characters : Blocklist &<>"/;,*|=% and --

Is there any way that when I type "&" this automatically convert into &amp? or can I create my custom restricted characters or mapping? I have looked into apex_escape function, but didn't find a suitable use.

1 Answer 1

1

You state "Because of XSS i am using Apex own security option". Why is that ? What are you trying to avoid by doing this ? Changing the data while a user is typing it is going to be frustrating for the user. My advice would be to not modify the input but instead secure how the data is displayed. APEX gives a lot of options to do that.

If the data is used in a report the output can be html escaped using Security > Escape special characters attribute.

If the data is displayed in a page using the &P1_ITEM. notation then the output can be sanitized using the relevant output escaping depending on where it is used .

If you decide to go the other route and you do want to sanitize the input then it's a question of how the data will be used later on in the application. You could create an after submit computation on the page item using any of the available methods in the APEX_ESCAPE api depending on what the expected use of the data is.

Another option is, as you suggest, to create a custom block list. The implementation of the restricted characters functionality is a client side validation. That can be achieved with a dynamic action and some javascript code (up to you to write that). It can also be done server side with a normal validation like the one below.

  • Type: Function body returning Boolean
  • Function body:
DECLARE
    l_blacklist_chars apex_t_varchar2;
BEGIN
    apex_string.push(l_blacklist_chars,'&');
    apex_string.push(l_blacklist_chars,'<');
    apex_string.push(l_blacklist_chars,'>');
    FOR i IN 1 .. l_blacklist_chars.COUNT LOOP
        IF INSTR(:P312_CUSTOM_BLOCKLIST,l_blacklist_chars(i)) > 0 THEN
            RETURN false;
        END IF;
    END LOOP;
END;
  • Error message: The field contains forbidden characters
Sign up to request clarification or add additional context in comments.

1 Comment

I was told that due to the risk of XSS attacks, I should apply some restrictions to user input. Therefore, I used the 'Restricted Characters' feature. My requirements have since changed, and the user now needs to be able to include the ampersand character (&). My idea is to map & to &amp;. Thank you for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.