This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
jsonrpsee: add host and origin filtering #9787
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
fix grumbles
- Loading branch information
commit fd3840dea6200aec6409eaf27c02cc49e40afcf2
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,14 +101,16 @@ pub fn start_http<M: Send + Sync + 'static>( | |
|
|
||
| let mut acl = AccessControlBuilder::new(); | ||
|
|
||
| log::info!("starting JSONRPC HTTP server: addr={}, cors={:?}", addr, cors); | ||
| log::info!("Starting JSONRPC HTTP server: addr={}, allowed origins={:?}", addr, cors); | ||
|
|
||
| if let Some(cors) = cors { | ||
| // Whitelist listening address. | ||
| let host = Host::parse(&format!("localhost:{}", addr.port())); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incredible ugly and annoying, we should fix this API. |
||
| acl = acl.allow_host(host); | ||
| let host = Host::parse(&format!("127.0.0.1:{}", addr.port())); | ||
| acl = acl.allow_host(host); | ||
|
|
||
| // Set allowed origins. | ||
| for origin in cors { | ||
| acl = acl.cors_allow_origin(origin.into()); | ||
| } | ||
|
|
@@ -147,14 +149,16 @@ pub fn start_ws<M: Send + Sync + 'static>( | |
| .max_request_body_size(max_request_body_size as u32) | ||
| .max_connections(max_connections as u64); | ||
|
|
||
| log::info!("starting JSONRPC WS server: addr={}, cors={:?}", addr, cors); | ||
| log::info!("Starting JSONRPC WS server: addr={}, allowed origins={:?}", addr, cors); | ||
|
|
||
| if let Some(cors) = cors { | ||
| // Whitelist listening address. | ||
| builder = builder.set_allowed_hosts([ | ||
| format!("localhost:{}", addr.port()), | ||
| format!("127.0.0.1:{}", addr.port()), | ||
| ])?; | ||
|
|
||
| // Set allowed origins. | ||
| builder = builder.set_allowed_origins(cors)?; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we put
localhost/127.0.0.1on the allowlist even ifcorseisNone?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All hosts/origins are enabled by default: https://github.com/paritytech/jsonrpsee/blob/master/http-server/src/access_control/mod.rs#L115
We should probably document it clearly in jsonrpsee I guess