Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using the spread operator ...profile will copy all properties from the actual runtime profile object returned by the GitHub API (such as id, 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/summary endpoint, this leaks unused fields and unnecessarily increases the network payload size. It is safer and more efficient to explicitly select only the required properties.

    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,

orgs,
pinnedRepos,
};
Comment on lines +242 to 245

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 スプレッド演算子によるランタイム余剰フィールドの流出

restGetres.json() as Promise<T> でキャストしているだけで、ランタイムでは GitHub API の /users/:username レスポンス全体(idnode_idemailhtml_urlpublic_gistsupdated_at など 30 以上のフィールド)が profile オブジェクトに含まれます。TypeScript の型はコンパイル時しか保証せず、...profile を展開すると意図しないフィールドがすべて返り値に含まれてしまいます。変更前のコードは明示的に 12 フィールドを列挙することで許可リスト(allowlist)として機能していましたが、スプレッドによりその保護が失われています。email フィールドが公開設定のユーザーであれば、クライアントに意図せず露出する可能性があります。

Prompt To Fix With AI
This 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.

Expand Down
Loading