Skip to content
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

cors: add a flag for cors #5671

Merged
merged 8 commits into from
Feb 21, 2020
Merged

cors: add a flag for cors #5671

merged 8 commits into from
Feb 21, 2020

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Feb 18, 2020

  • added a flag to the rest server that if you are fine with accepting all cors you can.

@ethanfrey

Signed-off-by: Marko Baricevic marbar3778@yahoo.com

Closes: #XXX

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

- added a flag to the rest server that if you are fine with accepting all cors you can.

let the user decide

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
@tac0turtle tac0turtle added REST T: Dev UX UX for SDK developers (i.e. how to call our code) labels Feb 18, 2020
@tac0turtle tac0turtle self-assigned this Feb 18, 2020
@tac0turtle tac0turtle marked this pull request as ready for review February 18, 2020 18:01
@okwme
Copy link
Contributor

okwme commented Feb 18, 2020

First off VERY glad to see CORS coming back as an option. This greatly improves the developer experience of working with browser clients that interact with the REST endpoint. This has traditionally been a hot topic because of the security considerations of allowing users to expose a REST endpoint unfettered. While I think it should be up to the developer using the SDK to make those decisions and precautions themselves, I wonder whether this feature should be considered as intended for production or testing use.

If just for testing then I think making it accept all CORS as it currently does makes sense, but maybe we should rename it something like unsafeCORS or testCORS to emphasize that.

If we are happy with the idea that this might be a production setting then maybe we should offer the flag to equal a string of comma separated values that can be parsed as follows:

CORS(AllowedOrigins([]string{}))

(usage seen here)

This would allow a user to pass "*" to accept CORS from all origins or a comma separated list of approved origins.

)

return err
},
}

cmd.Flags().Bool(FlagAllowCORS, false, "Allows CORS requests from all domains")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added in client/lcd.RegisterRestServerFlags()

Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm blocking this because I believe this requires discussion before we press ahead.
I acknowledge that this would make developers experience easier. I agree that especially while testing an app locally it's convenient to disable security features. Though IMHO it's our responsibility to make it as difficult as possible for developers to make dumb mistakes. I have few ideas on how to implement this without compromising on security (e.g. --cors flag may take effect on condition that a certain compilation flag is passed at build time + confirmation prompt when used). Let's discuss options, shall we? :)

client/flags/flags.go Outdated Show resolved Hide resolved
Co-Authored-By: Alessio Treglia <alessio@tendermint.com>
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress here 👍

client/lcd/root.go Show resolved Hide resolved
client/lcd/root.go Outdated Show resolved Hide resolved
client/lcd/root.go Outdated Show resolved Hide resolved
client/flags/flags.go Outdated Show resolved Hide resolved
client/lcd/root.go Outdated Show resolved Hide resolved
docs/interfaces/rest.md Outdated Show resolved Hide resolved
docs/interfaces/rest.md Outdated Show resolved Hide resolved
docs/interfaces/rest.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 21, 2020

Codecov Report

Merging #5671 into master will decrease coverage by 0.79%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #5671     +/-   ##
=========================================
- Coverage   37.76%   36.96%   -0.8%     
=========================================
  Files         328      328             
  Lines       30267    30915    +648     
=========================================
  Hits        11429    11429             
- Misses      17645    18293    +648     
  Partials     1193     1193
Impacted Files Coverage Δ
x/params/types/proposal/types.pb.go 1% <0%> (-0.1%) ⬇️
x/slashing/types/types.pb.go 0.8% <0%> (-0.03%) ⬇️
x/staking/types/types.pb.go 10.73% <0%> (-0.29%) ⬇️
x/bank/types/types.pb.go 0.69% <0%> (-0.09%) ⬇️
x/distribution/types/types.pb.go 0.63% <0%> (-0.09%) ⬇️
x/auth/types/types.pb.go 16.01% <0%> (-0.56%) ⬇️
types/types.pb.go 5.73% <0%> (-0.3%) ⬇️
x/supply/types/types.pb.go 0.99% <0%> (-0.06%) ⬇️

@tac0turtle tac0turtle added the R4R label Feb 21, 2020
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@@ -68,6 +69,11 @@ func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTi
),
)

var h http.Handler = rs.Mux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
var h http.Handler = rs.Mux
h := rs.Mux

@alexanderbez alexanderbez dismissed alessio’s stale review February 21, 2020 10:53

All changes requested have been addressed.

@alexanderbez alexanderbez merged commit e3dc0fd into master Feb 21, 2020
@alexanderbez alexanderbez deleted the marko/add_cors branch February 21, 2020 11:17
@ethanfrey
Copy link
Contributor

That was fast. Nice one, @marbar3778

This was referenced Feb 28, 2020
@alessio alessio mentioned this pull request Mar 3, 2020
4 tasks
ethanfrey pushed a commit to CosmWasm/cosmos-sdk that referenced this pull request Jul 27, 2020
alessio pushed a commit that referenced this pull request Jul 27, 2020
This adds the --unsafe-cors flag functionality.

From: #5671
Co-authored-by: Marko <marbar3778@yahoo.com>
Raumo0 pushed a commit to mapofzones/cosmos-sdk that referenced this pull request Feb 13, 2022
* v0.38.4-RC1

* add release date

* client/keys/parse: honor config changes (cosmos#6340)

`keys parse` uses the global configuration before
before client applications have had a chance to
apply their settings.

This change adds a `GetSealedConfig()` helper
that waits for the config to be sealed before
returning it.

Fixes: cosmos#5091
Origin: cosmos@4e328d7
Author: Adam Bozanich <adam.boz@gmail.com>
Reviewed-by: Alessio Treglia <alessio@tendermint.com>

* Merge PR cosmos#6505: Backport v0.38.5: IAVL Bump (RC) & Pruning Refactor

* Fix cl

* Fix cl

* Merge PR cosmos#6551: Ethanfrey/fix trace flag

* Merge PR cosmos#6552: Add sender info to bank transfer event

* Merge PR cosmos#6581: v0.38.5-RC1

* Add release date

* deps: bump IAVL to 0.14

* cl++

* Merge PR cosmos#6618: backport 0.39.0 (launchpad): cherry pick cosmos#5839

* launchpad: bump tendermint to v0.33.6 (cosmos#6673)

* launchpad: bump tendermint to v0.33.6

* cha-cha-cha

* fix types.ChainAnteDecorators() panic (cosmos#5742) (cosmos#6669)

ChainAnteDecorators() panics when no arguments are supplied.
This change its behaviour and the function now returns a nil
AnteHandler in case no AnteDecorator instances are supplied.

Closes: cosmos#5741

* launchpad: register MsgFundCommunityPool to distribution codec (cosmos#6675)

Closes: cosmos#6210

* client: backport IBC additions (cosmos#6682)

* launchpad: backport cliCtx.QueryABCI

* add prove flag

* Save account for multi sending (cosmos#6674)

Include changes from PR cosmos#6283

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>

* baseapp: fix sender events accumulation (cosmos#6683)

closes: cosmos#6306
original PR: cosmos#6307

* run go mod tidy

* add changelog line re: issue that was not included in v0.38.5

* Fix changelog

* add release notes

* update CODEOWNERS as per STABLE_RELEASES.md

Launchpad's Stable Release Managers team's current composition as
approved by @okwme (ICF):

* @alessio
* @clevinson
* @ethanfrey

* Add milestone's URL

* Revert "update CODEOWNERS as per STABLE_RELEASES.md"

This reverts commit f384592.

* fix typo

* add example patch

* launchpad: backport account sequence stuck (cosmos#6721)

Launchpad fix for cosmos#6287

* update release notes

* make explicit that the regression is fixed in 0.39

* update release notes

* Update CHANGELOG.md

* update release notes

@ethanfrey

* remove pruning info from changelog

They have been moved to NEWS.md

* Update NEWS.md

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Mege PR cosmos#6749: auth: remove custom JSON marshaling

* mv NEWS.md -> RELEASE_NOTES.md

Self-explanatory naming convention.

* Update changelog

* add reference to gaia software upgrade

* x/staking: add call to iterator Close() method (cosmos#6794)

Original pull request: cosmos#6791

* [ci] fix linter (cosmos#6795)

* Merge PR cosmos#6842: Remove custom acc JSON marshl

* Backport cosmos#5671: Add a Flag for CORS (cosmos#6853)

This adds the --unsafe-cors flag functionality.

From: cosmos#5671
Co-authored-by: Marko <marbar3778@yahoo.com>

* Merge PR cosmos#6855: Allow passing through Content-Type (needed for POST)

* Merge PR cosmos#6861: Revert "Backport 0.39.1: Remove Custom JSON Marshaling for Accounts"

* Merge PR cosmos#6869: Backport 0.39.1: Launchpad Migration cosmos#6829

* Update changelog and release notes

* Update x/auth/legacy/v0_39/types.go

* Update x/auth/legacy/v0_38/types.go

* Merge PR cosmos#6938: Fix v0.39 migrate test

* Merge PR cosmos#6937: Bump Tendermint to v0.33.7

* Update x/auth/legacy/v0_39/types.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* update RELEASE_NOTES.md

* update changelog

* test case with real genesis data (cosmos#6995)

* incorporate Ethan Frey's suggestion

* make format

* Update go mod

* Remove some ci files

* Modify data for test

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
Raumo0 pushed a commit to mapofzones/cosmos-sdk that referenced this pull request Feb 13, 2022
* v0.38.4-RC1

* add release date

* client/keys/parse: honor config changes (cosmos#6340)

`keys parse` uses the global configuration before
before client applications have had a chance to
apply their settings.

This change adds a `GetSealedConfig()` helper
that waits for the config to be sealed before
returning it.

Fixes: cosmos#5091
Origin: cosmos@4e328d7
Author: Adam Bozanich <adam.boz@gmail.com>
Reviewed-by: Alessio Treglia <alessio@tendermint.com>

* Merge PR cosmos#6505: Backport v0.38.5: IAVL Bump (RC) & Pruning Refactor

* Fix cl

* Fix cl

* Merge PR cosmos#6551: Ethanfrey/fix trace flag

* Merge PR cosmos#6552: Add sender info to bank transfer event

* Merge PR cosmos#6581: v0.38.5-RC1

* Add release date

* deps: bump IAVL to 0.14

* cl++

* Merge PR cosmos#6618: backport 0.39.0 (launchpad): cherry pick cosmos#5839

* launchpad: bump tendermint to v0.33.6 (cosmos#6673)

* launchpad: bump tendermint to v0.33.6

* cha-cha-cha

* fix types.ChainAnteDecorators() panic (cosmos#5742) (cosmos#6669)

ChainAnteDecorators() panics when no arguments are supplied.
This change its behaviour and the function now returns a nil
AnteHandler in case no AnteDecorator instances are supplied.

Closes: cosmos#5741

* launchpad: register MsgFundCommunityPool to distribution codec (cosmos#6675)

Closes: cosmos#6210

* client: backport IBC additions (cosmos#6682)

* launchpad: backport cliCtx.QueryABCI

* add prove flag

* Save account for multi sending (cosmos#6674)

Include changes from PR cosmos#6283

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>

* baseapp: fix sender events accumulation (cosmos#6683)

closes: cosmos#6306
original PR: cosmos#6307

* run go mod tidy

* add changelog line re: issue that was not included in v0.38.5

* Fix changelog

* add release notes

* update CODEOWNERS as per STABLE_RELEASES.md

Launchpad's Stable Release Managers team's current composition as
approved by @okwme (ICF):

* @alessio
* @clevinson
* @ethanfrey

* Add milestone's URL

* Revert "update CODEOWNERS as per STABLE_RELEASES.md"

This reverts commit f384592.

* fix typo

* add example patch

* launchpad: backport account sequence stuck (cosmos#6721)

Launchpad fix for cosmos#6287

* update release notes

* make explicit that the regression is fixed in 0.39

* update release notes

* Update CHANGELOG.md

* update release notes

@ethanfrey

* remove pruning info from changelog

They have been moved to NEWS.md

* Update NEWS.md

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Mege PR cosmos#6749: auth: remove custom JSON marshaling

* mv NEWS.md -> RELEASE_NOTES.md

Self-explanatory naming convention.

* Update changelog

* add reference to gaia software upgrade

* x/staking: add call to iterator Close() method (cosmos#6794)

Original pull request: cosmos#6791

* [ci] fix linter (cosmos#6795)

* Merge PR cosmos#6842: Remove custom acc JSON marshl

* Backport cosmos#5671: Add a Flag for CORS (cosmos#6853)

This adds the --unsafe-cors flag functionality.

From: cosmos#5671
Co-authored-by: Marko <marbar3778@yahoo.com>

* Merge PR cosmos#6855: Allow passing through Content-Type (needed for POST)

* Merge PR cosmos#6861: Revert "Backport 0.39.1: Remove Custom JSON Marshaling for Accounts"

* Merge PR cosmos#6869: Backport 0.39.1: Launchpad Migration cosmos#6829

* Update changelog and release notes

* Update x/auth/legacy/v0_39/types.go

* Update x/auth/legacy/v0_38/types.go

* Merge PR cosmos#6938: Fix v0.39 migrate test

* Merge PR cosmos#6937: Bump Tendermint to v0.33.7

* Update x/auth/legacy/v0_39/types.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* update RELEASE_NOTES.md

* update changelog

* test case with real genesis data (cosmos#6995)

* incorporate Ethan Frey's suggestion

* make format

* Update go mod

* Remove some ci files

* Modify data for test

* API server

* Port telemetry

* Initial metrics

* Fix measure

* Merge PR cosmos#6761: telemetry: use UTC() in wrappers

* Remove file

* Make format

* Revert changes to client

* Revert changes to client/lcd/root

* Revert renames in client

* Fix int64 panics

* Revert "Revert renames in client"

This reverts commit cc0a95d14c3212fa1c49f93789dd94e167427a57.

* Revert "Revert changes to client/lcd/root"

This reverts commit e3bb87bbacae13676c3a1f86f8d441d576b1f2ba.

* Revert "Revert changes to client"

This reverts commit 332cacba3242e503bcc4bffc3f6b25c1906efca4.

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Adam Bozanich <adam.boz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Dev UX UX for SDK developers (i.e. how to call our code)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants