-
Notifications
You must be signed in to change notification settings - Fork 36
feat: make user's accessToken available for jobv4 #2761
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: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -12,6 +12,10 @@ export type JobDocument = JobClass & Document; | |
| timestamps: true, | ||
| toJSON: { | ||
| getters: true, | ||
| transform: (_doc: Document, ret: Record<string, unknown>) => { | ||
| delete ret.accessToken; | ||
| return ret; | ||
| }, | ||
| }, | ||
| }) | ||
| export class JobClass extends OwnableClass { | ||
|
|
@@ -106,6 +110,17 @@ export class JobClass extends OwnableClass { | |
| default: {}, | ||
| }) | ||
| jobResultObject: Record<string, unknown>; | ||
|
|
||
| /** | ||
| * JWT access token provided by the user at job creation time. | ||
| * Stored for reuse by actions performed within the job. | ||
| * Not exposed in API responses for security reasons. | ||
| */ | ||
| @Prop({ | ||
| type: String, | ||
| required: false, | ||
| }) | ||
| accessToken?: string; | ||
|
Comment on lines
+119
to
+123
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. 🚨 issue (security): Storing raw JWTs in the database may not be necessary and increases the blast radius of a DB compromise. Persisting the full access token means a DB leak exposes reusable credentials until expiry. If you only need it to call downstream services, consider storing a less-sensitive representation (e.g. minimal claims or a reference/ID) or shortening its lifetime. If the full token must be stored, consider additional at-rest protection for this field (e.g. encryption). |
||
| } | ||
| export const JobSchema = SchemaFactory.createForClass(JobClass); | ||
|
|
||
|
|
||
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.
🚨 suggestion (security): Current hiding of
accessTokenonly coverstoJSON; consider also protecting it at query/serialization level.This only protects API responses using
toJSON; the field is still included by default in queries and intoObject()results. IfaccessTokenis sensitive, also mark it as non-selectable (e.g.select: false) or use an equivalent mechanism so it can’t be exposed via other serialization paths that bypass this transform.Suggested implementation:
To fully implement the suggestion and protect
accessTokenat the query level, you should also mark theaccessTokenfield as non-selectable in its@Propdefinition. For example, if the field currently looks like:you should change it to:
or, if there are already options:
This ensures
accessTokenis excluded by default from query results and all serialization paths, while still allowing explicit inclusion via.select('+accessToken')when needed.