-
Notifications
You must be signed in to change notification settings - Fork 42
[COOP-661] remove no media ncmec gate #866
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
Changes from all commits
86e4297
03e0da9
5b6c19d
0570010
44d9716
4be4523
230d9bb
4278016
a625c72
233f52c
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,4 +1,3 @@ | ||
| /* eslint-disable max-lines */ | ||
| import { ScalarTypes } from '@roostorg/coop-types'; | ||
| import { uid } from 'uid'; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| /* eslint-disable max-lines */ | ||
| import { uid } from 'uid'; | ||
| import { v1 as uuidv1 } from 'uuid'; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,7 @@ import { type JSONSchemaV4 } from '../../utils/json-schema-types.js'; | |
| import { type FixKyselyRowCorrelation } from '../../utils/kysely.js'; | ||
| import { logErrorJson } from '../../utils/logging.js'; | ||
| import { assertUnreachable, withRetries } from '../../utils/misc.js'; | ||
| import { | ||
| type CollapseCases, | ||
| type NonEmptyArray, | ||
| } from '../../utils/typescript-types.js'; | ||
| import { type CollapseCases } from '../../utils/typescript-types.js'; | ||
| import { rawItemSubmissionToItemSubmission } from '../itemProcessingService/makeItemSubmission.js'; | ||
| import { type RawItemData } from '../itemProcessingService/toNormalizedItemDataOrErrors.js'; | ||
| import { | ||
|
|
@@ -512,9 +509,7 @@ export function clampIncidentDateTimeToPast( | |
| ): { value: string; wasClamped: boolean } { | ||
| const maxCreatedAtMs = new Date(maxCreatedAt).getTime(); | ||
| if (Number.isNaN(maxCreatedAtMs)) { | ||
| throw new Error( | ||
| `Invalid media createdAt timestamp for incidentDateTime: ${maxCreatedAt}`, | ||
| ); | ||
| throw new Error(`Invalid timestamp for incidentDateTime: ${maxCreatedAt}`); | ||
| } | ||
| const ceilingMs = nowMs - 1000; | ||
| const wasClamped = maxCreatedAtMs > ceilingMs; | ||
|
|
@@ -525,6 +520,32 @@ export function clampIncidentDateTimeToPast( | |
| }; | ||
| } | ||
|
|
||
| // consolidate timestamp fetching and verification in one function for media and | ||
| // threads | ||
| export function latestEvidenceTimestamp( | ||
| media: readonly { createdAt: string }[], | ||
| threads: readonly { | ||
| reportedContent: readonly { sentAt: string | Date }[]; | ||
| }[], | ||
| ): string { | ||
| const rawTimestamps: (string | Date)[] = [ | ||
| ...media.map((m) => m.createdAt), | ||
| ...threads.flatMap((t) => t.reportedContent.map((c) => c.sentAt)), | ||
| ]; | ||
| if (rawTimestamps.length === 0) { | ||
| throw new Error('Report has neither media nor messages'); | ||
| } | ||
| // allow a lenient approach to timestamps. If none parse, throw an | ||
| // error and surface the bad data via the validation error path | ||
| const evidenceTimestampsMs = rawTimestamps | ||
|
Contributor
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. what's an example where an invalid date string might end up here? how might that happen? (i am wondering if this handling is necessary or if it's unnecessarily defensive).
Contributor
Author
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. That is a validation check for retries. Retires aren't validated at the GraphQL level, I don't believe. |
||
| .map((raw) => (raw instanceof Date ? raw.getTime() : Date.parse(raw))) | ||
| .filter((ms) => !Number.isNaN(ms)); | ||
| if (evidenceTimestampsMs.length === 0) { | ||
| throw new Error('Invalid timestamp for incidentDateTime'); | ||
| } | ||
| return new Date(Math.max(...evidenceTimestampsMs)).toISOString(); | ||
| } | ||
|
|
||
| /** Rebuild an ipCaptureEvent object with keys in NCMEC XSD `xs:sequence` | ||
| * order (ipAddress, eventName, dateTime, possibleProxy, port) so xml-js | ||
| * serialises the children in the order NCMEC's validator requires. Webhook | ||
|
|
@@ -1555,6 +1576,7 @@ export default class NcmecReporting { | |
| } | ||
|
|
||
| if ( | ||
| reportedMedia.length > 0 && | ||
| responseBody.media?.filter( | ||
| (it) => it.missing === false || it.missing === undefined, | ||
| ).length === 0 | ||
|
|
@@ -1801,22 +1823,10 @@ export default class NcmecReporting { | |
| ); | ||
| } | ||
|
|
||
| if (reportParams.media.length === 0) { | ||
| throw new Error('No media in report'); | ||
| } | ||
| const latestMedia = _.maxBy(reportParams.media, (m) => { | ||
| const ms = Date.parse(m.createdAt); | ||
| if (Number.isNaN(ms)) { | ||
| throw new Error( | ||
| `Invalid media createdAt timestamp for incidentDateTime: ${m.createdAt}`, | ||
| ); | ||
| } | ||
| return ms; | ||
| }); | ||
| if (latestMedia === undefined) { | ||
| throw new Error('No media in report'); | ||
| } | ||
| const maxCreatedAt = latestMedia.createdAt; | ||
| const maxCreatedAt = latestEvidenceTimestamp( | ||
| reportParams.media, | ||
| reportParams.threads, | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const { value: clampedIncidentDateTime, wasClamped } = | ||
| clampIncidentDateTimeToPast(maxCreatedAt); | ||
|
|
@@ -2039,8 +2049,7 @@ export default class NcmecReporting { | |
|
|
||
| user_item_type_id: reportParams.reportedUser.typeId, | ||
| reviewer_id: reportParams.reviewerId, | ||
| // Safe to cast as a non empty array because of the createdAt check above | ||
| reported_media: reportedMedia as NonEmptyArray<NcmecMediaReport>, | ||
| reported_media: reportedMedia, | ||
| report_xml: xml, | ||
| additional_files: additionalFiles, | ||
| reported_messages: threadCsvs, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.