Repository navigation
Drop browser request headers from service HTTP calls - #323
Merged
Merged
Conversation
A consuming app's fetch() to a service app forwarded every header, including Origin and Fetch Metadata. Apps check Origin to accept forms only from their own pages, such as a template's approval level form. A consuming app acting for a signed-in user could set Origin to the service's origin and send that form itself, for example to turn off approval questions. Service HTTP calls now drop Origin and Sec-Fetch-* headers, which only a browser sends.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 8a3eb84 | Nov 23 2026, 12:22 AM |
tnkuehne
added a commit
that referenced
this pull request
Nov 23, 2026
## Why
The GitHub template offers three hand-written REST methods: list
repositories, list issues, read a file. Anything else, like opening
issues or pull requests, reviews, discussions or projects, needs a
template change. GitHub publishes its GraphQL schema, so the template
can offer the whole API as typed methods, the same way the Linear
template does.
## What changes
**GitHub template**
- **Methods:** 202 typed methods, 24 queries and 178 mutations, from
GitHub's public GraphQL schema. Most data is reached through
`repository`, `viewer`, `organization`, `node` and `search`.
- **Field selections:** work like in Linear, including `$args` and `$on`
for interfaces and unions. Text files are read through
`repository.object` with `$on: { Blob: { text: true } }`.
- **Not offered (98 operations):** listed in `scripts/operations.ts`
with a reason for each:
- enterprise administration;
- organization settings that need `admin:org` or `write:org`;
- Enterprise Importer migrations;
- GitHub Sponsors;
- check runs and check suites, which only GitHub Apps can create;
- package deletion.
Deprecated operations, such as classic Projects, are left out
automatically.
- **Approvals:** per-user approval level, like in Linear.
- `create` is used only for pure additions: issues, comments, branches,
reactions.
- `addPullRequestReview` is `update`: given an event such as `APPROVE`,
it submits the review at once.
- Anything that changes, merges, closes, restricts or deletes existing
data asks under the default level. For example: merging, branch
protection, rulesets, deployments, `updateRefs`.
- **Scopes:** `repo`, `workflow`, `project`, `read:org` and `user`.
- An account connected with fewer scopes gets `permission_required` from
every method and from `connectionStatus`, with a link to reconnect.
- The managed client requests the same scopes.
- **Errors:**
| GitHub answer | Result |
| --- | --- |
| GraphQL errors | `github_error` with GitHub's `type`, e.g. `NOT_FOUND`
|
| `RATE_LIMITED` errors, exhausted or secondary rate limits (403/429) |
`rate_limited`, with `retryAfter` from `Retry-After` or the limit's
reset time |
| 401 | `reconnect_required` |
| any other 403 | `access_denied` |
- **Large responses:** larger than 8 MiB give `too_large`, in GitHub and
Linear alike, instead of being read into memory.
- **Removed:** the REST methods and their helpers (`listRepositories`,
`listIssues`, `readFile`).
- Binary file contents and REST-only features such as releases or
Actions runs aren't available yet. They need an OpenAPI generator, which
a following PR adds.
- `template.md` describes scopes, selections, approvals, results and how
to regenerate.
**Generator and the other templates**
- **GraphQL request builder:** moves into the shared runtime. Each
template keeps its own error mapping: Linear reads `extensions`, GitHub
reads `type`.
- **Fragment fields:** fields inside `... on Variant` are aliased and
restored along the selection, because two variants may have a field of
one name with different types. A field selected both for every type and
in `$on` must pass the same `$args`. Selections may leave optional
values `undefined`.
- **JSON imports:** the generated file imports the JSON types that types
or method signatures use.
- **`Environment` import:** generated files import the template's
`Environment` as `TemplateEnvironment`, because GitHub has a type called
`Environment`. The generator stops when an API type would shadow another
import.
- **Enums:** keep deprecated values, because results can still carry
them. One GitHub enum consists only of deprecated values.
- **Comments:** irregular spaces in descriptions become plain spaces.
- **Failed responses without GraphQL errors:** in Linear and GitHub, a
4xx/5xx response whose JSON body has no GraphQL errors no longer counts
as an empty success. A 403 gives `access_denied`; other statuses fail.
## Approval level form
A consuming app could send the approval level form through
`env.GITHUB.fetch()` with a forged `Origin`. #323 fixes that in the
runtime for every template.
## Managed OAuth
A managed `github` client only grants the scopes its `scopes` setting
allows. Installations that offer managed OAuth for GitHub must add
`workflow`, `project`, `read:org` and `user` to that setting. Until they
do, starting a managed connection fails with "The requested scopes are
not allowed for this client". Installations with their own OAuth app
(`GITHUB_CLIENT_ID`/`GITHUB_CLIENT_SECRET`) aren't affected.
## Connection page
Connected state, with the same approval form as Linear and Gmail.
| Before | After |
| --- | --- |
| <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/37679177abe0c2fe4f0cffc3211659c7f836765f/github-before-1280.png"
width="400"> | <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/37679177abe0c2fe4f0cffc3211659c7f836765f/github-after-1280.png"
width="400"> |
| <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/37679177abe0c2fe4f0cffc3211659c7f836765f/github-before-390.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/2e857c8b70cfc0a62168609f2702355e/raw/37679177abe0c2fe4f0cffc3211659c7f836765f/github-after-390.png"
width="200"> |
Not shown: the disconnected and setup-required states. They only change
their description text.
## Testing
- `pnpm check`
- **Generator:** tests for type names that shadow imports and for the
`TemplateEnvironment` alias.
- **Request builder against GitHub's schema:** variables, interfaces,
unions, schema mismatches.
- **GitHub template against a mocked GitHub:**
- typed requests;
- approvals for every level;
- missing scopes;
- GraphQL errors and rate limits;
- revoked tokens;
- expiring and non-expiring tokens;
- callback checks.
- **Type tests:** selections narrow results, `$on` narrows by
`__typename`, and the README example compiles.
- **Managed OAuth tests (app runtime and control plane):** now run
against the GraphQL template.
- Regenerating Linear, GitHub and Gmail from saved sources reproduces
the committed files.
- Not tested against a live GitHub account.
<!-- greptile_comment -->
<!-- greptile_summary -->
<h2><a
href="https://app.greptile.com/api/retrigger?id=116054566&sig=68923c46e14ed6b1fc8a4291fc034ff38749e861193a1456d51ada1bde6b720f"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F321&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5 <sup><img alt="Tier:
plus" title="Review tier: plus"
src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-plus.svg?v=3"
height="12"></sup></h2>
<!-- greptile-impact-verdict --> No new blocking issue was found in this
PR.
<details open><summary><h3>Summary</h3></summary>
Replaces GitHub’s three REST methods with 202 generated, typed GraphQL
methods.
- GitHub calls now use a generated, typed GraphQL API.
- GraphQL selections now handle arguments and type-specific fields.
- GitHub mutation calls now follow each user's approval setting.
- GitHub calls now check required scopes and return clear GraphQL
results.
- Generated templates now keep their API types separate from imported
types.
</details>
<details open><summary><h3>Diagram</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Typed method and field selection] --> B[Build GraphQL request]
B --> C{Mutation needs approval?}
C -->|Yes| D[Ask the current user]
D -->|Accepted| E[Check connection and scopes]
C -->|No| E
E --> F[Call GitHub]
F --> G[Limit response size and read errors]
G --> H[Restore selected field names]
H --> I[Return typed result]
```
</details>
<!-- greptile_confidence_score:5 -->
<sub>Reviews (10) · Last reviewed commit: ["Compare fragment arguments
regardless
of..."](55f76aa)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>
<!-- /greptile_comment -->
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
A consuming app's
env.SERVICE.fetch()reaches the service app with the signed-in user asctx.props.callerand with every header the consuming app set. Apps accept browser forms only whenOriginis their own origin. The Linear template uses this for its approval level form on/approval-level, and the other templates for connect and disconnect.A consuming app can set
Originto the service's origin. It can then send that form as the user, for examplelevel=noneto turn off approval questions for that user's later changes, without the user seeing anything.What changes
AppService.fetch) dropOriginandSec-Fetch-*, next to thex-auth-request-*headers they already drop. Only a browser sends these headers. RPC calls are unchanged.Origincheck accepts only forms the user sent from the app's pages.Browser requests through the app's URL are unchanged.
Testing
RUN_SERVICE_TESTS=1, workerd and celld): a consuming app sendsOriginandSec-Fetch-Sitethrough a servicefetch(). The service receives neither, and the verified caller is unchanged.OriginandSec-Fetch-Sitearriving.pnpm check

Confidence Score: 5/5
The PR appears safe to merge.Summary
Service HTTP calls now drop
OriginandSec-Fetch-*alongside the existing filtered headers.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Calling app] --> B[AppService.fetch] B --> C[Remove browser and claimed identity headers] C --> D[Service receives verified caller] E[Browser request] --> F[App HTTP handler]Reviews (1) · Last reviewed commit: "Drop browser request headers from servic..." · Reviewed by Greptile