- 
                Notifications
    You must be signed in to change notification settings 
- Fork 65
chore: fix incorrect URL path resolution #777
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
base: master
Are you sure you want to change the base?
Conversation
| @mdqst is attempting to deploy a commit to the distributed-crafts Team on Vercel. A member of the Team first needs to authorize it. | 
| Summary of ChangesHello @mdqst, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where certain API endpoint paths were being incorrectly resolved by the  Highlights
 Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either  
 Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a  Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
 | 
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.
Code Review
This pull request aims to fix an issue with URL path resolution. However, the current approach of adding a leading slash to paths creates a critical issue: it breaks support for Esplora instances hosted under a path prefix (e.g., behind a reverse proxy). The change makes all API paths absolute to the host, ignoring any path in the base URL.
I've left a detailed comment on the first occurrence of this pattern, explaining the problem and suggesting a more robust solution. The recommended approach is to enforce a trailing slash on the base URL within the client's constructor and consistently use relative paths (without a leading slash) for all API calls. This will ensure correct behavior for all valid base URL configurations.
| pub async fn get_merkleblock_proof(&self, txid: &Txid) -> Result<MerkleBlock> { | ||
| Ok(consensus::deserialize(&Vec::<u8>::from_hex( | ||
| &self.get(&format!("tx/{txid}/merkleblock-proof")).await?, | ||
| &self.get(&format!("/tx/{txid}/merkleblock-proof")).await?, | 
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.
This change introduces a significant issue for users who run Esplora behind a reverse proxy with a path prefix.
By adding a leading slash, you are making the path an "absolute-path reference". According to the url::Url::join documentation, this resolves the path from the origin of the base URL, ignoring any path component in the base URL.
For example, if a user configures the client with a base URL like https://example.com/esplora/ (note the trailing slash, which is correct for path prefixes), the behavior changes as follows:
- Before (correct): url.join("tx/...")would result inhttps://example.com/esplora/tx/....
- After (incorrect): url.join("/tx/...")would result inhttps://example.com/tx/....
The issue described in the pull request description ("the last segment of the base URL was being replaced") happens when the base URL has a path but lacks a trailing slash (e.g., https://example.com/esplora). The correct way to handle this is not to make all paths absolute, but to ensure the base URL is correctly formed.
I recommend a more robust solution:
- Revert this change and all similar changes in this PR.
- In EsploraClient::new_with_url, ensure that the parsedUrlalways has a path ending with a trailing slash. This makes path joining predictable. You could do something like this:pub fn new_with_url(esplora_url: String) -> Result<Self> { let mut url = esplora_url.parse::<Url>()?; if !url.path().ends_with('/') { url.path_segments_mut() .map_err(|_| eyre::eyre!("URL cannot be a base"))? .push(""); } Ok(Self { url, cli: Client::new() }) } 
- Audit all other API calls in this file and ensure they all use relative paths (no leading slash) for consistency. For example, get_tx_hexandget_tx_infocurrently use absolute paths and should be changed.
This approach will correctly handle all base URL configurations, including those with path prefixes.
| &self.get(&format!("/tx/{txid}/merkleblock-proof")).await?, | |
| &self.get(&format!("tx/{txid}/merkleblock-proof")).await?, | 
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.
@mdqst please check this comment
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.
sry, my bad. closed.
some API paths like
tx/...,block-height/..., andscripthash/...were being joined without a leading/.since
Url::joininterprets them as relative, the last segment of the base URL was being replaced instead of appended.