content-manager-sdk / Community

Content Manager SDK Samples
http://hprm.info
The Unlicense
50 stars 37 forks source link

Added where LINQ clause to filter out empty strings from originConfigs. #14

Open Jake-Thomas-Hall opened 4 years ago

Jake-Thomas-Hall commented 4 years ago

Hey there,

I set out to use this CORS module for the Content Manager Service API but found that there was a problem with it.

In the readme it states that:

if you do not set 'allowedOrigins' in app settings than all domains will be allowed to use CORS (Access-Control-Allow-Origin = "*")

However, the if statement that allows this logic did not work because there was always at least one string in the origins array (an empty one, if 'allowedOrigins' is not set).

Therefore, I've added a Where LINQ clause that ensures that no empty strings end up in this array, meaning that the if statement is hit and it does apply the default behaviour of allowing all origins.

I have tested this all with Content manager 9.3. CORS requests from any domain are now able to succeed when 'allowedOrigins' is not set or has an empty value, and specific domains can still be allowed as well if that is what is required.

Jake-Thomas-Hall commented 3 years ago

Hey @dchurchland is there any chance this PR can be merged? If not, I will close/abandon the PR as I really don't want to leave this lingering around if it'll never get merged.