-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 Refactor fetchUserProfile to use spread operator #456
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,18 +239,7 @@ export async function fetchUserProfile( | |
| ]); | ||
|
|
||
| return { | ||
| login: profile.login, | ||
| avatar_url: profile.avatar_url, | ||
| name: profile.name, | ||
| bio: profile.bio, | ||
| company: profile.company, | ||
| location: profile.location, | ||
| blog: profile.blog, | ||
| twitter_username: profile.twitter_username, | ||
| created_at: profile.created_at, | ||
| followers: profile.followers, | ||
| following: profile.following, | ||
| public_repos: profile.public_repos, | ||
| ...profile, | ||
| orgs, | ||
| pinnedRepos, | ||
| }; | ||
|
Comment on lines
+242
to
245
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/lib/github.ts
Line: 242-245
Comment:
**スプレッド演算子によるランタイム余剰フィールドの流出**
`restGet` は `res.json() as Promise<T>` でキャストしているだけで、ランタイムでは GitHub API の `/users/:username` レスポンス全体(`id`、`node_id`、`email`、`html_url`、`public_gists`、`updated_at` など 30 以上のフィールド)が `profile` オブジェクトに含まれます。TypeScript の型はコンパイル時しか保証せず、`...profile` を展開すると意図しないフィールドがすべて返り値に含まれてしまいます。変更前のコードは明示的に 12 フィールドを列挙することで許可リスト(allowlist)として機能していましたが、スプレッドによりその保護が失われています。`email` フィールドが公開設定のユーザーであれば、クライアントに意図せず露出する可能性があります。
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
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.
Using the spread operator
...profilewill copy all properties from the actual runtimeprofileobject returned by the GitHub API (such asid,node_id,html_url,repos_url, etc.) into the returned object. Since this object is serialized and sent to the client in the/api/dashboard/summaryendpoint, this leaks unused fields and unnecessarily increases the network payload size. It is safer and more efficient to explicitly select only the required properties.