Skip to content

Drop browser request headers from service HTTP calls - #323

Merged
tnkuehne merged 1 commit into
mainfrom
fix/service-http-origin
Nov 23, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
fix/service-http-origin

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

A consuming app's env.SERVICE.fetch() reaches the service app with the signed-in user as ctx.props.caller and with every header the consuming app set. Apps accept browser forms only when Origin is 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 Origin to the service's origin. It can then send that form as the user, for example level=none to turn off approval questions for that user's later changes, without the user seeing anything.

What changes

  • Service HTTP calls (AppService.fetch) drop Origin and Sec-Fetch-*, next to the x-auth-request-* headers they already drop. Only a browser sends these headers. RPC calls are unchanged.
  • The connect-apps guide says that service calls arrive without these headers, so an Origin check accepts only forms the user sent from the app's pages.

Browser requests through the app's URL are unchanged.

Testing

  • App service runtime tests (RUN_SERVICE_TESTS=1, workerd and celld): a consuming app sends Origin and Sec-Fetch-Site through a service fetch(). The service receives neither, and the verified caller is unchanged.
  • The new expectation fails without the change, with Origin and Sec-Fetch-Site arriving.
  • pnpm check

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Service HTTP calls now drop Origin and Sec-Fetch-* alongside the existing filtered headers.

  • Service calls no longer carry browser request 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]
Loading

Reviews (1) · Last reviewed commit: "Drop browser request headers from servic..." · Reviewed by Greptile

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.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 8a3eb84 Nov 23 2026, 12:22 AM

@tnkuehne
tnkuehne merged commit d5a5433 into main Nov 23, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the fix/service-http-origin branch November 23, 2026 08:29
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&amp;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&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F321&amp;utm_source=greptile_review&amp;utm_medium=github&amp;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 -->
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.

1 participant