Skip to content

Allow CORS to be configured for gRPC Web #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2023
Merged

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Apr 4, 2023

Motivation:

The WebCORS handler unconditionally sets "Access-Control-Allow-Origin" to "*" in response headers regardless of whether the request is a CORS request or whether the client sends credentials. Moreover we don't expose any knobs to control how CORS is configured.

Modifications:

  • Add CORS configuration to the server and server builder
  • Let the allowed origins be '.any' (i.e. '*") or '.only' (limited to the provided origins)
  • Let the user configure what headers are permitted in responses.
  • Let the user configure whether credentialed requests are accepted.

Result:

More control over CORS

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Apr 4, 2023
Motivation:

The WebCORS handler unconditionally sets "Access-Control-Allow-Origin"
to "*" in response headers regardless of whether the request is a CORS
request or whether the client sends credentials. Moreover we don't
expose any knobs to control how CORS is configured.

Modifications:

- Add CORS configuration to the server and server builder
- Let the allowed origins be '.any' (i.e. '*") or '.only' (limited to
  the provided origins)
- Let the user configure what headers are permitted in responses.
- Let the user configure whether credentialed requests are accepted.

Result:

More control over CORS
@glbrntt glbrntt enabled auto-merge (squash) April 5, 2023 12:18
@glbrntt glbrntt merged commit 4fd5a10 into grpc:main Apr 5, 2023
@glbrntt glbrntt deleted the gb-cors branch April 6, 2023 09:54
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request May 2, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request May 2, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request May 3, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
glbrntt added a commit that referenced this pull request May 9, 2023
Motivation:

We added some level of CORS configuration support in #1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

The WebCORS handler unconditionally sets "Access-Control-Allow-Origin"
to "*" in response headers regardless of whether the request is a CORS
request or whether the client sends credentials. Moreover we don't
expose any knobs to control how CORS is configured.

Modifications:

- Add CORS configuration to the server and server builder
- Let the allowed origins be '.any' (i.e. '*") or '.only' (limited to
  the provided origins)
- Let the user configure what headers are permitted in responses.
- Let the user configure whether credentialed requests are accepted.

Result:

More control over CORS

Co-authored-by: Cory Benfield <[email protected]>
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

The WebCORS handler unconditionally sets "Access-Control-Allow-Origin"
to "*" in response headers regardless of whether the request is a CORS
request or whether the client sends credentials. Moreover we don't
expose any knobs to control how CORS is configured.

Modifications:

- Add CORS configuration to the server and server builder
- Let the allowed origins be '.any' (i.e. '*") or '.only' (limited to
  the provided origins)
- Let the user configure what headers are permitted in responses.
- Let the user configure whether credentialed requests are accepted.

Result:

More control over CORS

Co-authored-by: Cory Benfield <[email protected]>
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants