-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix several findings #263
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
Merged
Merged
Fix several findings #263
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
910dd9d
Harden identity sync assertions
admdly e6aceb8
Add durable claim verification budgets
admdly 0442045
Add GitHub request budget for previews
admdly 1ac9a4b
Normalize central alerts pagination and cache
admdly c0e79ce
Rate-limit developer profile writes
admdly 45b20a6
Cache public GETs despite auth headers
admdly d8d91ff
Tighten auth and user input checks
admdly daf01ee
Merge branch 'main' into fix/several
admdly fcee973
Address cubic review findings on fix/several
admdly 0449150
Declare 400 response on PUT /users/me/identity
admdly 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
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
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { DurableObject } from "cloudflare:workers"; | ||
|
|
||
| // One singleton for all preview traffic, independent of URL, client and colo. | ||
| // Token buckets permit 60 calls in a burst, then 1000/hour globally and | ||
| // 120/hour per client. Every upstream call (not just each lookup) costs one. | ||
| export class PreviewGitHubBudget extends DurableObject<CloudflareBindings> { | ||
| constructor(ctx: DurableObjectState, env: CloudflareBindings) { | ||
| super(ctx, env); | ||
| this.ctx.storage.sql.exec(`CREATE TABLE IF NOT EXISTS buckets ( | ||
| key TEXT PRIMARY KEY, tokens REAL NOT NULL, updated_at INTEGER NOT NULL | ||
| )`); | ||
| } | ||
|
|
||
| reserve(client: string): boolean { | ||
| const now = Date.now(); | ||
| return this.ctx.storage.transactionSync(() => { | ||
| // A client bucket is full after 30 minutes; discard only older state. | ||
| this.ctx.storage.sql.exec( | ||
| "DELETE FROM buckets WHERE key != 'global' AND updated_at < ?", | ||
| now - 1800000 | ||
| ); | ||
| const buckets = [ | ||
| { key: "global", rate: 1000 / 3600000 }, | ||
| { key: `client:${client}`, rate: 120 / 3600000 } | ||
| ].map(({ key, rate }) => { | ||
| const row = this.ctx.storage.sql | ||
| .exec<{ tokens: number; updated_at: number }>( | ||
| "SELECT tokens, updated_at FROM buckets WHERE key = ?", | ||
| key | ||
| ) | ||
| .toArray()[0]; | ||
| const tokens = row | ||
| ? Math.min(60, row.tokens + Math.max(0, now - row.updated_at) * rate) | ||
| : 60; | ||
| return { key, tokens }; | ||
| }); | ||
| if (buckets.some(({ tokens }) => tokens < 1)) return false; | ||
| for (const { key, tokens } of buckets) { | ||
| this.ctx.storage.sql.exec( | ||
| "INSERT OR REPLACE INTO buckets (key, tokens, updated_at) VALUES (?, ?, ?)", | ||
| key, | ||
| tokens - 1, | ||
| now | ||
| ); | ||
| } | ||
| return true; | ||
| }); | ||
| } | ||
| } |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.