Skip to content

Comments

feat: add endpoint to report false Blockaid scan results (COR-636)#2815

Merged
Fbartoli merged 7 commits intomainfrom
feature/cor-636-report-false-blockaid-result
Dec 3, 2025
Merged

feat: add endpoint to report false Blockaid scan results (COR-636)#2815
Fbartoli merged 7 commits intomainfrom
feature/cor-636-report-false-blockaid-result

Conversation

@Fbartoli
Copy link
Collaborator

@Fbartoli Fbartoli commented Dec 1, 2025

  • Add POST /v1/chains/:chainId/security/:safeAddress/report-false-result endpoint
  • Support reporting FALSE_POSITIVE and FALSE_NEGATIVE scan results
  • Use request_id from original scan response to identify the transaction
  • Add reportTransaction method to BlockaidApi and ThreatAnalysisService
  • Handle errors gracefully with logging and success: false response
  • Add chain ID to Blockaid chain name mapping (for future use)
  • Add comprehensive unit tests
  • Add reading the request id from the header

@Fbartoli Fbartoli self-assigned this Dec 1, 2025
@Fbartoli Fbartoli requested a review from a team as a code owner December 1, 2025 11:41
@Fbartoli Fbartoli force-pushed the feature/cor-636-report-false-blockaid-result branch from 713ddce to a38b991 Compare December 1, 2025 11:44
@Fbartoli Fbartoli marked this pull request as draft December 1, 2025 11:55
@Fbartoli Fbartoli marked this pull request as ready for review December 1, 2025 13:36
* Extended TransactionScanResponse that includes the request_id from x-request-id header.
*/
export type TransactionScanResponseWithRequestId = TransactionScanResponse & {
request_id: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it string | undefined unless we explicitly need to send null to Blockaid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, not necessary to send null

/**
* Extended TransactionScanResponse that includes the request_id from x-request-id header.
*/
export type TransactionScanResponseWithRequestId = TransactionScanResponse & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since it's in the interface file I would make it an interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would make sense to extract it to a separate entity or types file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


describe('reportFalseResult', () => {
const mockReportRequest = {
event: 'FALSE_POSITIVE' as const,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove as const from all the parameters here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


expect(result).toEqual({ success: false });
expect(mockLoggingService.error).toHaveBeenCalledWith(
`Failed to report false result for request_id ${mockReportRequest.request_id}: Blockaid API error`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: What if there’s an error on our end that prevents us from calling the Blockaid endpoint? In that case, the error message wouldn’t be entirely accurate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error message updated

);
});

it('should handle null request_id from header', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request_id is not null here it's undefined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@LucieFaire LucieFaire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! Some small comments

/**
* Extended TransactionScanResponse that includes the request_id from x-request-id header.
*/
export type TransactionScanResponseWithRequestId = TransactionScanResponse & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would make sense to extract it to a separate entity or types file?

SafeFB and others added 7 commits December 3, 2025 15:34
- Add POST /v1/chains/:chainId/security/:safeAddress/report-false-result endpoint
- Support reporting FALSE_POSITIVE and FALSE_NEGATIVE scan results
- Use request_id from original scan response to identify the transaction
- Add reportTransaction method to BlockaidApi and ThreatAnalysisService
- Handle errors gracefully with logging and success: false response
- Add chain ID to Blockaid chain name mapping (for future use)
- Add comprehensive unit tests
- Extract request_id from x-request-id header in Blockaid API response
- Extend TransactionScanResponse with request_id field
- Include request_id in ThreatAnalysisResponse for reporting false positives
- Refactor ReportEvent to follow ContractStatus pattern with const array
- Add comprehensive documentation for enum types and DTOs
- Explain 1000 char limit is CGW-imposed safeguard
- Remove underscore prefixes from controller params
- Add comment explaining params are for URL validation
…reatAnalysis services

- Change request_id type from string | null to string | undefined in various services and DTOs.
- Update logging messages to use 'warn' instead of 'error' for reporting failures in SafeShieldService.
- Adjust unit tests to reflect changes in request_id handling and logging behavior.
- Ensure consistency in request_id usage across the threat analysis module.
…ndefined request_id

- Modify the mock response in the ThreatAnalysisService unit tests to set request_id as undefined instead of null, ensuring consistency with recent refactoring changes in request_id handling.
- Change the event parameter type in reportTransaction method across ThreatAnalysisService, IBlockaidApi, and BlockaidApi from string literals to ReportEvent type for improved type safety and consistency.
- Add BLOCKAID_REQUEST_ID_HEADER constant for better readability and maintainability in Blockaid API service.
@Fbartoli Fbartoli force-pushed the feature/cor-636-report-false-blockaid-result branch from a1ec9b0 to ea89619 Compare December 3, 2025 14:35
@Fbartoli Fbartoli disabled auto-merge December 3, 2025 14:37
@Fbartoli Fbartoli enabled auto-merge (squash) December 3, 2025 14:37
@Fbartoli Fbartoli merged commit 55573d1 into main Dec 3, 2025
14 of 16 checks passed
@Fbartoli Fbartoli deleted the feature/cor-636-report-false-blockaid-result branch December 3, 2025 14:42
PooyaRaki pushed a commit that referenced this pull request Dec 9, 2025
…2815)

* feat: add endpoint to report false Blockaid scan results (COR-636)

- Add POST /v1/chains/:chainId/security/:safeAddress/report-false-result endpoint
- Support reporting FALSE_POSITIVE and FALSE_NEGATIVE scan results
- Use request_id from original scan response to identify the transaction
- Add reportTransaction method to BlockaidApi and ThreatAnalysisService
- Handle errors gracefully with logging and success: false response
- Add chain ID to Blockaid chain name mapping (for future use)
- Add comprehensive unit tests

* feat: add request_id to threat analysis response

- Extract request_id from x-request-id header in Blockaid API response
- Extend TransactionScanResponse with request_id field
- Include request_id in ThreatAnalysisResponse for reporting false positives

* refactor: address PR review comments for COR-636

- Refactor ReportEvent to follow ContractStatus pattern with const array
- Add comprehensive documentation for enum types and DTOs
- Explain 1000 char limit is CGW-imposed safeguard
- Remove underscore prefixes from controller params
- Add comment explaining params are for URL validation

* refactor: update request_id handling and logging in SafeShield and ThreatAnalysis services

- Change request_id type from string | null to string | undefined in various services and DTOs.
- Update logging messages to use 'warn' instead of 'error' for reporting failures in SafeShieldService.
- Adjust unit tests to reflect changes in request_id handling and logging behavior.
- Ensure consistency in request_id usage across the threat analysis module.

* test: update mock response in ThreatAnalysisService tests to handle undefined request_id

- Modify the mock response in the ThreatAnalysisService unit tests to set request_id as undefined instead of null, ensuring consistency with recent refactoring changes in request_id handling.

* refactor: update reportTransaction method to use ReportEvent type

- Change the event parameter type in reportTransaction method across ThreatAnalysisService, IBlockaidApi, and BlockaidApi from string literals to ReportEvent type for improved type safety and consistency.
- Add BLOCKAID_REQUEST_ID_HEADER constant for better readability and maintainability in Blockaid API service.

* chore: trigger CI

---------

Co-authored-by: SafeFB <fb@SafeFBs-MBP.fritz.box>
Co-authored-by: SafeFB <fb@SafeFBs-MacBook-Pro.fritz.box>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants