-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: Add creator_id into CreateFlow mutation #826
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,7 @@ | ||||||||||||||||||||||
import jwtDecode from "jwt-decode"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import { getCookie } from "./lib/cookie"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
export function removeAt<T>(index: number, arr: Array<T>): Array<T> { | ||||||||||||||||||||||
return arr.filter((_item, i) => { | ||||||||||||||||||||||
return i !== index; | ||||||||||||||||||||||
|
@@ -52,3 +56,12 @@ export function slugify(name: string): string { | |||||||||||||||||||||
.replace(/[\s_-]+/g, "-") // swap any length of whitespace, underscore, hyphen characters with a single - | ||||||||||||||||||||||
.replace(/^-+|-+$/g, ""); // remove leading, trailing - | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
export function getLoggedInUserId(): number | undefined { | ||||||||||||||||||||||
const jwt = getCookie("jwt"); | ||||||||||||||||||||||
if (!jwt) return; | ||||||||||||||||||||||
const userId = Number( | ||||||||||||||||||||||
(jwtDecode(jwt) as any)["https://hasura.io/jwt/claims"]["x-hasura-user-id"] | ||||||||||||||||||||||
); | ||||||||||||||||||||||
return userId; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
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. do you think it's worth refactoring this block to use the same bit of code? planx-new/editor.planx.uk/src/index.tsx Lines 34 to 43 in 67bb8b5
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. Good catch - looking at this lead me to have a bit of a rethink, see comment below. |
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.
I think there might be a bit of a security issue here that could get flagged by a security audit in future. It might be that we can ignore it for the time being though*
The issue is - a user could potentially set any
creator_id
they wanted with some sneaky frontend code tweaking, or by looking at the network request and then replaying it with a differentcreator_id
of their choosing.The way around it would be to extract the
x-hasura-user-id
from the JWT in hasura itself, so in the hasura console, you'd setcreator_id
to have the default value ofx-hasura-user-id
and have permissions so thatcreator_id
can't be overridden.https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/default-values/column-presets.html#step-1-configure-a-column-preset
e.g.
Doing that should mean that it's impossible for someone to spoof the
creator_id
.* However, IIRC we've all got full admin permissions right now anyway, which is why I think we might have bigger problems than this if we had an audit soon. Hmm 🤔
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.
That's very helpful feedback thanks - I'll take a crack at this approach.