Skip to content
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

remove domCoordinates #326

Merged
merged 2 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 8 additions & 10 deletions backend/gqlSchemas/authier.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ type WebInputGQL {
kind: WebInputType!
domPath: String!
domOrdinal: Int!
domCoordinates: JSON!
addedByUserId: String
addedByUser: UserGQL
UsageEvents: [SecretUsageEventGQL!]!
Expand All @@ -199,14 +198,6 @@ enum WebInputType {
CUSTOM
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON
@specifiedBy(
url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf"
)

type DecryptionChallengeGQL {
id: Int!
ipAddress: String!
Expand Down Expand Up @@ -326,6 +317,14 @@ type DecryptionChallengeForApproval {
deviceId: ID!
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON
@specifiedBy(
url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf"
)

type Mutation {
"""
you need to be authenticated to call this resolver
Expand Down Expand Up @@ -597,5 +596,4 @@ input WebInputElement {
domOrdinal: NonNegativeInt!
url: String!
kind: WebInputType!
domCoordinates: JSON!
}
2 changes: 0 additions & 2 deletions backend/models/WebInputElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ export class WebInputElement {
url: string
@Field(() => WebInputTypeGQL)
kind: WebInputTypeGQL
@Field(() => GraphQLJSON)
domCoordinates: ICoordinates
}
3 changes: 0 additions & 3 deletions backend/models/generated/WebInputGQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export class WebInputGQLScalars {
@Field(() => Int)
domOrdinal: number

@Field(() => GraphQLScalars.JSONResolver)
domCoordinates: Prisma.JsonValue

@Field(() => String, { nullable: true })
addedByUserId: string | null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `domCoordinates` on the `WebInput` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "WebInput" DROP COLUMN "domCoordinates";
1 change: 0 additions & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ model WebInput {
kind WebInputType
domPath String
domOrdinal Int @default(0)
domCoordinates Json
addedByUser User? @relation(fields: [addedByUserId], references: [id], onDelete: SetNull)
addedByUserId String? @db.Uuid
UsageEvents SecretUsageEvent[]
Expand Down
7 changes: 1 addition & 6 deletions backend/schemas/RootResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,7 @@ describe('RootResolver', () => {
url: 'https://google.com',
kind: WebInputTypeGQL.PASSWORD,
domOrdinal: 1,
domPath: 'body',

domCoordinates: {
x: 2.234,
y: 3.234
}
domPath: 'body'
}
],
fakeCtx
Expand Down
3 changes: 1 addition & 2 deletions backend/schemas/RootResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ export class RootResolver {
host: new URL(webInput.url).host,
domPath: webInput.domPath,
kind: webInput.kind,
addedByUserId: ctx.jwtPayload.userId,
domCoordinates: webInput.domCoordinates as any // TODO prisma types for JSON fields suck
addedByUserId: ctx.jwtPayload.userId
}
const input = await ctx.prisma.webInput.upsert({
create: forUpsert,
Expand Down
4 changes: 0 additions & 4 deletions backend/schemas/__snapshots__/RootResolver.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
exports[`RootResolver > addWebInputs > should add to the DB 1`] = `
{
"addedByUserId": "811354ee-2834-4321-8a9f-507771d96955",
"domCoordinates": {
"x": 2.234,
"y": 3.234,
},
"domOrdinal": 0,
"domPath": "body",
"host": "google.com",
Expand Down
11 changes: 8 additions & 3 deletions shared/generated/graphqlBaseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export type DeviceQuery = {
User: UserGql;
UserMaster?: Maybe<UserGql>;
createdAt: Scalars['DateTime'];
/** Get all secrets that were change since last device sync */
encryptedSecretsToSync: Array<EncryptedSecretQuery>;
firebaseToken: Scalars['String'];
firstIpAddress: Scalars['String'];
Expand Down Expand Up @@ -501,7 +502,8 @@ export type UserMutation = {
addDeviceSecretEncrypted: Scalars['String'];
addEncryptedSecrets: Array<EncryptedSecretQuery>;
autofill: Scalars['Boolean'];
changeMasterPassword: Scalars['PositiveInt'];
changeEmail: UserQuery;
changeMasterPassword: Scalars['Int'];
createCheckoutSession: Scalars['String'];
createPortalSession: Scalars['String'];
createSecretUsageEvent: SecretUsageEventGqlScalars;
Expand Down Expand Up @@ -541,6 +543,11 @@ export type UserMutationAddEncryptedSecretsArgs = {
};


export type UserMutationChangeEmailArgs = {
email: Scalars['EmailAddress'];
};


export type UserMutationChangeMasterPasswordArgs = {
input: ChangeMasterPasswordInput;
};
Expand Down Expand Up @@ -655,7 +662,6 @@ export type UserQuerySendAuthMessageArgs = {
};

export type WebInputElement = {
domCoordinates: Scalars['JSON'];
/** The index of the input element on the page (0-based). We are not able to always generate a css selector which matches only one element. Here the domOrdinal comes in and saves the day. */
domOrdinal: Scalars['NonNegativeInt'];
domPath: Scalars['String'];
Expand All @@ -669,7 +675,6 @@ export type WebInputGql = {
addedByUser?: Maybe<UserGql>;
addedByUserId?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
domCoordinates: Scalars['JSON'];
domOrdinal: Scalars['Int'];
domPath: Scalars['String'];
host: Scalars['String'];
Expand Down
1 change: 0 additions & 1 deletion web-extension/src/background/backgroundPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface ICapturedInput {
type: 'input' | 'submit' | 'keydown'
kind: WebInputType
inputted?: string | undefined
domCoordinates: Coord
}

export interface ILoginCredentialsFromContentScript {
Expand Down
4 changes: 1 addition & 3 deletions web-extension/src/background/backgroundSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const capturedInputSchema = z.object({
z.literal('keydown')
]),
kind: z.nativeEnum(WebInputType),
inputted: z.string().optional(),
domCoordinates: z.object({ x: z.number(), y: z.number() })
inputted: z.string().optional()
})

export const contentScriptContextSchema = z.object({
Expand Down Expand Up @@ -45,7 +44,6 @@ export const capturedEventsPayloadSchema = z.object({
})

export const webInputElementSchema = z.object({
domCoordinates: z.object({ x: z.number(), y: z.number() }),
domOrdinal: z.number(),
domPath: z.string(),
kind: z.nativeEnum(WebInputType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type WebInputsForHostQueryVariables = Types.Exact<{
}>;


export type WebInputsForHostQuery = { __typename?: 'Query', webInputs: Array<{ __typename?: 'WebInputGQL', id: number, host: string, url: string, domPath: string, domOrdinal: number, kind: Types.WebInputType, createdAt: string, domCoordinates: any }> };
export type WebInputsForHostQuery = { __typename?: 'Query', webInputs: Array<{ __typename?: 'WebInputGQL', id: number, host: string, url: string, domPath: string, domOrdinal: number, kind: Types.WebInputType, createdAt: string }> };


export const AddWebInputsDocument = gql`
Expand Down Expand Up @@ -61,7 +61,6 @@ export const WebInputsForHostDocument = gql`
domOrdinal
kind
createdAt
domCoordinates
}
}
`;
Expand Down
1 change: 0 additions & 1 deletion web-extension/src/background/chromeRuntimeListener.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ query webInputsForHost($host: String!) {
domOrdinal
kind
createdAt
domCoordinates
}
}
11 changes: 2 additions & 9 deletions web-extension/src/background/chromeRuntimeListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ if (!isRunningInBgPage) {
throw new Error('this file should only be imported in the background page')
}

interface Coord {
x: number
y: number
}
export interface ICapturedInput {
cssSelector: string
domOrdinal: number
type: 'input' | 'submit' | 'keydown'
kind: WebInputType
inputted?: string | undefined
domCoordinates: Coord
}

interface ILoginCredentialsFromContentScript {
Expand Down Expand Up @@ -122,8 +117,7 @@ const appRouter = tc.router({
domPath: captured.cssSelector,
kind: captured.kind,
url: inputsUrl,
domOrdinal: captured.domOrdinal,
domCoordinates: captured.domCoordinates
domOrdinal: captured.domOrdinal
}
})

Expand Down Expand Up @@ -153,8 +147,7 @@ const appRouter = tc.router({
domPath: captured.cssSelector,
kind: captured.kind,
url: inputsUrl,
domOrdinal: captured.domOrdinal,
domCoordinates: captured.domCoordinates
domOrdinal: captured.domOrdinal
}
})

Expand Down
6 changes: 1 addition & 5 deletions web-extension/src/content-script/DOMEventsRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ export class DOMEventsRecorder {
domOrdinal: getSelectorForElement(element).domOrdinal,
type,
kind: kind as WebInputType,
inputted,
domCoordinates: {
x: rect.x,
y: rect.y
}
inputted
}
}
)
Expand Down
15 changes: 3 additions & 12 deletions web-extension/src/content-script/autofill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type webInput = {
domPath: string
kind: WebInputType
createdAt: string
domCoordinates: Coords
}

export const autofillEventsDispatched = new Set()
Expand Down Expand Up @@ -235,13 +234,7 @@ export const autofill = (initState: IInitStateRes, autofillEnabled = false) => {
authenticator.generate(totpSecret.totp.secret)
)
}
//NOTE: We did not find element by DOM path, so find it by input coords
} else if (
webInputGql.domCoordinates.x === rect?.x &&
webInputGql.domCoordinates.y === rect?.y
) {
inputEl = document.elementFromPoint(rect?.x, rect?.y) as any
log('el', inputEl)
//NOTE: We did not find element by DOM path
}
})
.filter((el) => !!el)
Expand Down Expand Up @@ -418,8 +411,7 @@ export const autofill = (initState: IInitStateRes, autofillEnabled = false) => {
domPath: getSelectorForElement(input).css,
host: location.host,
url: location.href,
kind: WebInputType.PASSWORD,
domCoordinates: getElementCoordinates(input)
kind: WebInputType.PASSWORD
})

domRecorder.addInputEvent({
Expand All @@ -445,8 +437,7 @@ export const autofill = (initState: IInitStateRes, autofillEnabled = false) => {
domPath: getSelectorForElement(inputElsArray[j]).css,
host: location.host,
url: location.href,
kind: WebInputType.USERNAME,
domCoordinates: getElementCoordinates(input)
kind: WebInputType.USERNAME
})

domRecorder.addInputEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ export const PromptPasswordOption = (props: PromptPasswordOptionProps) => {
}

let el = document.querySelector(webInputs[0].domPath)
if (!el) {
el = document.elementFromPoint(
webInputs[0].domCoordinates.x,
webInputs[0].domCoordinates.y
)
log('el', el)
}
const [pos, setPos] = useState(el?.getBoundingClientRect())

let resizeTimer: string | number | NodeJS.Timeout | undefined
Expand Down
4 changes: 1 addition & 3 deletions web-extension/src/content-script/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export interface IInitStateRes {
domPath: string
kind: WebInputType
createdAt: string
domCoordinates: Coords
}>
saveLoginModalsState?:
| {
Expand Down Expand Up @@ -175,8 +174,7 @@ export async function initInputWatch() {
domPath: elementSelector.css,
domOrdinal: elementSelector.domOrdinal,
kind: WebInputType.TOTP,
url: location.href,
domCoordinates: getElementCoordinates(targetElement)
url: location.href
}
await trpc.addTOTPInput.mutate(webInput)
log(`TOTP WebInput added for selector "${elementSelector}"`)
Expand Down
2 changes: 0 additions & 2 deletions web-extension/src/content-script/renderLoginCredOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ILoginSecret } from '../util/useDeviceState'
import { h, render } from 'preact'
import { PromptPasswordOption } from './components/PromptPasswordOption'
import { WebInputType } from '../../../shared/generated/graphqlBaseTypes'
import { Coords } from './contentScript'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const nano = h
Expand All @@ -20,7 +19,6 @@ export type PromptPasswordOptionProps = {
domPath: string
kind: WebInputType
createdAt: string
domCoordinates: Coords
}>
}

Expand Down