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

Allow self.alt host for self-requests #3003

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

itowlson
Copy link
Collaborator

This is a proposal to address spinframework/spin-js-sdk#298.

The issue there is that JS guests use the inbuilt fetch function to make HTTP requests. If fetch sees a URL without a host, it helpfully prepends the host it thinks it's running on before letting Spin see it. So for a self-request such as fetch("/back"), Spin sees http://localhost:3000/back or whatever. Which is not on the allow list so gets the banhammer.

This PR reluctantly compromises with fetch by allowing self-requests via the pseudo-host self.alt. So if you do fetch("http://self.alt/back"), Spin will treat it as a self-request: it will validate permission using the self-request permission and route it as a self request.

The developer experience is, admittedly, not very lovely. But it hopefully gives JS folks an escape hatch.

Notes for reviewers:

  • Self-request permission is still given via allowed_outbound_hosts = ["http://self"], not http://self.alt. Should we allow self.alt as another way of expressing the same permission?
  • I implemented this only in wasi-http because that's what JS goes through. Should I implement it in spin-http too? It looked faffier there because of the way the types line up, but certainly do-able.

@karthik2804
Copy link
Contributor

@itowlson this overall looks good, an alternate suggestion that came up during the original PR adding this feature also seems to indicate that this will benefit go.
#1710 (comment)

Copy link
Contributor

@karthik2804 karthik2804 left a comment

Choose a reason for hiding this comment

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

I am okay with adding this to just the wasi-http.

Copy link
Member

@radu-matei radu-matei left a comment

Choose a reason for hiding this comment

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

Self-request permission is still given via allowed_outbound_hosts = ["http://self"], not http://self.alt/. Should we allow self.alt as another way of expressing the same permission?

Not a blocker; but allowing self.alt since it's what you use here makes sense to me.

I implemented this only in wasi-http because that's what JS goes through. Should I implement it in spin-http too? It looked faffier there because of the way the types line up, but certainly do-able.

This only being in WASI HTTP makes perfect sense to me.

LGTM-ing since this is a pretty big blocker for the JS SDK.

Thanks!

@lann
Copy link
Collaborator

lann commented Feb 17, 2025

nit: Commit message says spin.alt 🙂

@lann
Copy link
Collaborator

lann commented Feb 17, 2025

Self-request permission is still given via allowed_outbound_hosts = ["http://self"], not http://self.alt/. Should we allow self.alt as another way of expressing the same permission?

I would say yes, to reduce confusion.

@itowlson itowlson force-pushed the enable-js-fetch-self-requests branch 3 times, most recently from 12871e9 to f6a3786 Compare February 17, 2025 22:39
@itowlson
Copy link
Collaborator Author

Added bonus host. Note that both self and self.alt will be accepted for either relative or self.alt requests.

Fixed commit message - thanks for the spot @lann!

Copy link
Collaborator

@lann lann left a comment

Choose a reason for hiding this comment

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

If we want to get this through quickly that's fine with me, but we really should have test coverage for this.

@itowlson
Copy link
Collaborator Author

If we want to get this through quickly that's fine with me, but we really should have test coverage for this.

Yep, agree. Note we can't run tests at the moment because the runner got lost in the repo move, but worth having for when the lights come back on...

@itowlson itowlson force-pushed the enable-js-fetch-self-requests branch from f6a3786 to aa47c0d Compare February 17, 2025 23:32
@itowlson
Copy link
Collaborator Author

Added a test which Works On My Machine even if CI is packing a sad right now.

@itowlson itowlson changed the title Allow spin.alt host for self-requests Allow self.alt host for self-requests Feb 17, 2025
@itowlson itowlson merged commit 7b40001 into spinframework:main Feb 18, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants