109
Views
9
Comments
Exposed REST API URL should not accept special characters
Question

Hi,

I am exposing a REST web service and in which I have a URL parameter and which should not accept special characters. When there is a special character it should give "404 Not Found". 

URL : https://{servername}/test/{testid}

--> testid is the URL parameter

I tried using RegExSearch that didn't work for me. Please help!!

Thanks,

Shree

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

It is from your problem description unclear what you tried and what failed.

Maybe you can share your OML or error message that you got.

Did you use the OnBeforeRequest to implement your logic?

Regards,

Daniel

UserImage.jpg
Shreelakshmi N S

Please find the attachments. Below is the URL with special characters and the logic I used to restrict. I have used OnResponse as well but didn't work.. Its giving 500 error and error response in HTML. 

Test.PNG
2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi, 

It is not 100% to tell from the information you shared, but it looks like you validate the input in the method itself, and I believe you should do it in the OnBeforeRequest of the REST API. Also double check (with debugging) that your regex is correct.

Regards,

Daniel

2018-10-29 08-31-03
João Marques
 
MVP

Hi Shreelakshmi,


Have you tried using the built-in function EncodeUrl right before passing them to the REST API?


Kind Regards,
João

UserImage.jpg
Shreelakshmi N S

Hi João,


Could you please tell me, If I use EncodeURL how will I check whether in the URL there is a special character or not ?


Thanks,

Shree

2018-10-29 08-31-03
João Marques
 
MVP

Hi Shreelakshmi,


As you can see on the description of the function on the screenshot I shared and I'm sharing again below, the purpose of this function is to encode the special characters in a way that they are accepted in a URL.

You also have some examples of what this function does.




You just need to apply the EncodeUrl function when passing the parameter to the API, like in the example below:

 

UserImage.jpg
Shreelakshmi N S

The solution which I need is to not to accept special characters. When there is a special character in the URL it should give 404 Not Found Status. 

2018-10-29 08-31-03
João Marques
 
MVP

What is the rationale behind not accepting special characters?


In any case, you can use a function to remove the diacritics and compare the result to the original string. If they are the same, then there were no diacritics; otherwise they were.


You can remove the accents and diacritics of a string on client-side using Text Normalizer forge component or on server side using the Normalize String forge component.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.