fix: encrypt stored GitHub credentials (#797)

This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-09-08 13:04:28 +02:00
1 parent b070d7e281
commit 3fb376dd53
32 files changed
+1098 -188

No files matched your search

@@ -18,7 +18,7 @@ const AnonymizedGistSchema = new Schema({
conference: String,
source: {
gistId: String,
accessToken: String,
accessToken: { type: String, select: false },
},
options: {
terms: [String],
@@ -19,7 +19,7 @@ const AnonymizedPullRequestSchema = new Schema({
source: {
pullRequestId: Number,
repositoryFullName: String,
accessToken: String,
accessToken: { type: String, select: false },
},
options: {
terms: [String],
@@ -14,7 +14,7 @@ const AnonymizedRepositorySchema = new Schema({
anonymizeDate: Date,
lastView: Date,
pageView: Number,
accessToken: String,
accessToken: { type: String, select: false },
owner: {
type: Schema.Types.ObjectId,
ref: "user",
@@ -36,7 +36,7 @@ const AnonymizedRepositorySchema = new Schema({
commitDate: Date,
repositoryId: String,
repositoryName: String,
accessToken: String,
accessToken: { type: String, select: false },
},
truncatedFolders: {
type: [String],
@@ -0,0 +1,24 @@
import { model, Schema, Types } from "mongoose";
import { EncryptedToken } from "../../credential-crypto";
export interface ICredential {
ownerId: Types.ObjectId;
provider: string;
encryptedToken: EncryptedToken;
updatedAt: Date;
}
const envelope = new Schema({
version: { type: Number, required: true, enum: [1] },
keyId: { type: String, required: true },
nonce: { type: String, required: true },
ciphertext: { type: String, required: true },
tag: { type: String, required: true },
}, { _id: false });
const schema = new Schema<ICredential>({
ownerId: { type: Schema.Types.ObjectId, required: true, ref: "user" },
provider: { type: String, required: true, enum: ["github"] },
encryptedToken: { type: envelope, required: true, select: false },
updatedAt: { type: Date, required: true },
}, { collection: "credentials" });
schema.index({ ownerId: 1, provider: 1 }, { unique: true });
export default model<ICredential>("Credential", schema);
+1 -1
View File
@@ -2,7 +2,7 @@ import { Schema } from "mongoose";
const UserSchema = new Schema({
accessTokens: {
github: { type: String },
github: { type: String, select: false },
},
accessTokenDates: {
github: { type: Date },
+2 -1
View File
@@ -1,7 +1,8 @@
import { Document, Model } from "mongoose";
export interface IUser {
accessTokens: {
/** Legacy storage, read only when CREDENTIAL_LEGACY_READS is enabled. */
accessTokens?: {
github: string;
};
accessTokenDates?: {