gateway icon indicating copy to clipboard operation
gateway copied to clipboard

feat(translator): add regex origins for CORS

Open Demacr opened this issue 1 year ago • 6 comments

What this PR does / why we need it:

I've added new field to CORS struct to get ability set flexible regexes to CORSes, because current situation allow only prefix wildcard. So in case of:

      - "tld\\.domain(?:\\..*)?"
      - ".*:\\/\\/localhost(?:\\:\\d+)?"
      - "http:\\/\\/((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}:30\\d\\d"
      - null

like mobile app origins or when there is no origing (null) it is impossible to set CORS. Second point why I did new field is to have back compatibility with existent configuration.

Demacr avatar Jul 22 '24 10:07 Demacr

like mobile app origins or when there is no origing (null) it is impossible to set CORS.

@Demacr Thanks for the PR. Could you please provide more details on this? It would be helpful if you could include a real-world example where wildcard match isn't sufficient, but regex works. Thanks.

zhaohuabing avatar Jul 22 '24 12:07 zhaohuabing

@zhaohuabing I've mentioned rules, which cannot be matched by prefixed wildcard, in the PR message:

  • 1st is our origin from mobile applications, it should have suffixed wildcard
  • 2nd could be replaced by Origin struct validated regex
  • 3rd one is really rare, but impossible to change by regex which can pass Origin struct validator
  • 4th null origin uses our custom Figma's plugin, which call our API with such origin.

Finally, looks like it's possible to add just suffixed wildcard and to add posibility make schemaless origin. Excepting IPs.

Demacr avatar Jul 22 '24 13:07 Demacr

@zhaohuabing I've mentioned rules, which cannot be matched by prefixed wildcard, in the PR message:

  • 1st is our origin from mobile applications, it should have suffixed wildcard
  • 2nd could be replaced by Origin struct validated regex
  • 3rd one is really rare, but impossible to change by regex which can pass Origin struct validator
  • 4th null origin uses our custom Figma's plugin, which call our API with such origin.

Finally, looks like it's possible to add just suffixed wildcard and to add posibility make schemaless origin. Excepting IPs.

Thanks! I think this request is fair enough. LGTM, and defer to other @envoyproxy/gateway-maintainers for any suggestions on the API change.

zhaohuabing avatar Jul 22 '24 14:07 zhaohuabing

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 67.39%. Comparing base (0b52320) to head (362fc7e). Report is 1084 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3928      +/-   ##
==========================================
- Coverage   67.42%   67.39%   -0.03%     
==========================================
  Files         183      183              
  Lines       22443    22447       +4     
==========================================
- Hits        15133    15129       -4     
- Misses       6224     6228       +4     
- Partials     1086     1090       +4     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jul 22 '24 14:07 codecov[bot]

hey @Demacr still plan on working on this one ?

arkodg avatar Aug 26 '24 22:08 arkodg

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

github-actions[bot] avatar Oct 12 '24 00:10 github-actions[bot]

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

github-actions[bot] avatar Nov 11 '24 08:11 github-actions[bot]

closing this PR since its become inactive, feel free to reopen if you're still working on it

arkodg avatar May 23 '25 02:05 arkodg