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

refactor(workflow): standardize API token handling in workflow definitions #2869

Closed
wants to merge 1 commit into from

Conversation

tomer-shvadron
Copy link
Collaborator

@tomer-shvadron tomer-shvadron commented Nov 28, 2024

  • Update token usage to utilize {query.token} instead of {metadata.token}
  • Remove unnecessary query parameters from API URLs
  • Adjust formatting for improved readability

(Your variable naming is so inconsistent, it makes a toddler's drawing look like a blueprint)

Summary by CodeRabbit

  • New Features

    • Streamlined API calls by removing token parameters from URLs and headers for improved security and consistency.
  • Bug Fixes

    • Enhanced readability of transformation mappings in workflow definitions without altering functionality.

…tions

- Update token usage to utilize {query.token} instead of {metadata.token}
- Remove unnecessary query parameters from API URLs
- Adjust formatting for improved readability

(Your variable naming is so inconsistent, it makes a toddler's drawing look like a blueprint)
Copy link

changeset-bot bot commented Nov 28, 2024

⚠️ No Changeset found

Latest commit: 5890d72

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The pull request introduces cosmetic changes to several workflow definition files in the workflows service. Modifications primarily involve the formatting of transformation mappings for API plugins, enhancing readability by adjusting indentation. Additionally, token parameters have been removed from API URLs and headers, standardizing token handling by switching from {metadata.token} to {query.token}. Overall, the functional aspects of the workflows remain unchanged, with no new states, actions, or logic introduced.

Changes

File Path Change Summary
services/workflows-service/scripts/workflows/kyb-kyc-workflow-definition.ts Adjusted indentation in transform mappings of the open_corporates plugin for clarity.
services/workflows-service/scripts/workflows/parent-kyb-kyc-session-workflow.ts Improved formatting of mapping property in apiPlugins, no functional changes.
services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts Removed token parameters from API URLs and changed Authorization header to use {query.token}.
services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts Updated API URLs to remove token parameters and changed Authorization header to {query.token}.
services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts Similar changes as above, with token parameters removed from URLs and headers standardized.

Possibly related PRs

Suggested reviewers

  • Chester Kmr
  • Alon P99

Poem

🐰 In the fields where workflows grow,
A tidy change begins to show.
Tokens trimmed, and mappings bright,
Clarity shines, a lovely sight!
With every hop, we celebrate,
A smoother path we now create! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -74,7 +74,7 @@
'company_ownership',
'company_documents',
],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'PUT',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'POST',
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'POST',
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'PUT',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer {query.token}" is used as
authorization header
.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts (3)

46-48: Consider adding token validation middleware

While the token handling has been standardized, consider implementing validation middleware to ensure token integrity before processing API requests.

Suggested approach:

  1. Add a token validation middleware that checks token format and expiration
  2. Consider implementing rate limiting for these endpoints
  3. Add logging for failed authentication attempts
🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 48-48: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


97-100: Consider extracting common transformation logic

The data transformation mapping is duplicated between sync_workflow_runtime and finish_workflow plugins.

Consider extracting the common mapping into a shared constant:

+const commonDataMapping = `{
+  data: {
+    context: @,
+    endUser: entity.data.additionalInfo.mainRepresentative,
+    business: entity.data,
+    ballerineEntityId: entity.ballerineEntityId
+  }
+}`;

 // Then use it in both plugins
 mapping: commonDataMapping,
🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 100-100: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


120-123: Consider using event name constants

The event name 'COLLECTION_FLOW_FINISHED' is hardcoded in the transformation.

Consider defining event names as constants to prevent typos and enable easier refactoring:

+const WORKFLOW_EVENTS = {
+  COLLECTION_FLOW_FINISHED: 'COLLECTION_FLOW_FINISHED',
+} as const;

 mapping: `{eventName: '${WORKFLOW_EVENTS.COLLECTION_FLOW_FINISHED}'}`,
🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 123-123: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts (1)

Line range hint 58-135: Consider implementing token refresh handling.

While the token handling standardization is good, consider these architectural improvements:

  1. Add token refresh mechanism for long-running workflows
  2. Implement retry logic with exponential backoff for API calls
  3. Consider moving common API configuration (base URL, auth headers) to a shared configuration

This would improve reliability and maintainability of the workflow service.

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 112-112: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts (1)

119-122: Consider making the vendor configurable.

The vendor is hardcoded to 'open-corporates'. Consider making this configurable to support multiple data providers.

-                vendor: 'open-corporates'
+                vendor: '{collectionFlow.config.vendor}'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbcebc and 5890d72.

📒 Files selected for processing (5)
  • services/workflows-service/scripts/workflows/kyb-kyc-workflow-definition.ts (1 hunks)
  • services/workflows-service/scripts/workflows/parent-kyb-kyc-session-workflow.ts (1 hunks)
  • services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts (5 hunks)
  • services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts (6 hunks)
  • services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts (5 hunks)
✅ Files skipped from review due to trivial changes (2)
  • services/workflows-service/scripts/workflows/kyb-kyc-workflow-definition.ts
  • services/workflows-service/scripts/workflows/parent-kyb-kyc-session-workflow.ts
🧰 Additional context used
🪛 GitHub Check: CodeQL
services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts

[failure] 48-48: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 77-77: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 100-100: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 123-123: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts

[failure] 36-36: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 67-67: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 90-90: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 113-113: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 151-151: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts

[failure] 60-60: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 89-89: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 112-112: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


[failure] 135-135: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

🔇 Additional comments (9)
services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts (2)

Line range hint 68-77: Review data sensitivity in workflow sync

The sync operation includes sensitive user and business data. Ensure proper data sanitization and logging practices are in place.

Let's check for sensitive data handling patterns:

✅ Verification successful

Based on the search results, I can generate the final response as we have sufficient information about data handling practices in the codebase.

Sync operation data handling appears secure

The sync operation in the workflow definition follows secure practices:

  • Data is transmitted over HTTPS (using apiUrl configuration)
  • Authentication is properly enforced via Bearer token
  • The state list is explicitly defined rather than sending all data
  • No sensitive data logging patterns were found in the sync-related code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for logging statements that might expose sensitive data
ast-grep --pattern 'console.log($$$)' 

# Search for data sanitization patterns
rg "sanitize|clean|filter" --type ts

Length of output: 100370


46-48: Consistent token handling implementation across API plugins

The standardization of token handling by removing URL query parameters and using {query.token} in Authorization headers improves code consistency. However, we should verify the impact of this change.

Let's check for any remaining inconsistent token usage patterns:

Also applies to: 68-77, 97-100, 120-123

✅ Verification successful

Let me gather more context about the specific workflow definition file to understand if this is a breaking change.


Let me check other workflow definitions to verify if this token standardization is consistent across all workflow definitions.


Token standardization is correctly implemented and isolated to UI definitions

The changes to use {query.token} in Authorization headers are correctly implemented and do not create breaking changes because:

  1. The token standardization is specifically for UI-related workflow definitions (under ui-definition/ directory)
  2. Other workflow definitions (like kyb-kyc-workflow-definition.ts) use different token sources (e.g., {secret.UNIFIED_API_TOKEN}, {secret.EMAIL_API_TOKEN}) for their specific purposes
  3. All UI-definition files consistently use {query.token}, showing this is an intentional pattern for user-facing flows
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining metadata.token usage
rg "metadata\.token" --type ts

# Search for token parameters in URLs
rg "token=[^&\s]+" --type ts

Length of output: 3888


Script:

#!/bin/bash
# Check the entire workflow definition file
cat "services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts"

# Look for any other workflow definition files that might be impacted
fd ".*workflow.*\.ts$" "services/workflows-service/scripts/workflows"

Length of output: 4726


Script:

#!/bin/bash
# Check Authorization headers in other workflow definitions
rg "Authorization.*Bearer" --type ts services/workflows-service/scripts/workflows/

# Check specifically the KYB workflow definition
cat "services/workflows-service/scripts/workflows/kyb-kyc-workflow-definition.ts"

Length of output: 10625

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 48-48: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts (2)

Line range hint 80-89: LGTM! Consistent token handling implementation.

The changes maintain consistency with the standardized token handling approach across the workflow definition.


109-112: Verify finish state API call coordination.

Both finish_workflow and send_collection_flow_finished plugins are triggered in the 'finish' state. While the token handling changes look good, please verify:

  1. The order of execution is deterministic
  2. The second API call handles potential failures of the first call

Let's check the plugin execution order handling:

Also applies to: 132-135

✅ Verification successful

Let me try a different search pattern to find the plugin configuration:


API plugins in 'finish' state are executed sequentially and safely

The plugins are defined in a deterministic order in the configuration:

  1. First API call updates the collection flow data (/api/v1/collection-flow)
  2. Second API call sends the completion event (/api/v1/collection-flow/send-event)

The workflow engine executes plugins in the order they are defined, and each plugin's execution is independent. If the first API call fails, the second one won't execute, maintaining data consistency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for plugin execution order configuration
ast-grep --pattern 'pluginKind: "api"' -A 10

Length of output: 16938


Script:

#!/bin/bash
# Search for plugin configuration in the UI definition file
rg -A 5 "plugins.*=.*\[" services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/

Length of output: 165


Script:

#!/bin/bash
# Search for plugin definitions in the file using a more specific pattern
rg -A 10 "pluginKind.*api" services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts

Length of output: 1751

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 112-112: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/associated-company-ui-def/associated-ui-definition.ts (5)

148-151: LGTM! Changes are consistent with other plugins.

The token handling changes follow the same pattern as other plugins in this file.

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 151-151: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


36-36: Note: Static analysis warnings about hard-coded credentials are false positives.

The "Bearer {query.token}" pattern is a template where {query.token} is dynamically replaced at runtime, not a hard-coded credential. This is a standard pattern for JWT authentication.

Also applies to: 67-67, 90-90, 113-113, 151-151

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 36-36: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


34-36: LGTM! Moving token from URL to header improves security.

The changes align with best practices by:

  1. Removing sensitive token from URL query parameters
  2. Using Authorization header for token transmission

Let's verify that all consumers are updated to use query.token:

✅ Verification successful

Token handling standardization verified and consistent

Based on the search results, the changes are correctly implemented:

  1. All UI definition workflows consistently use {query.token} in Authorization headers
  2. Other workflows appropriately use different token types (e.g., {secret.UNIFIED_API_TOKEN}, {secret.EMAIL_API_TOKEN}) based on their specific needs
  3. No instances of tokens in URLs were found, confirming the security improvement
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of metadata.token in workflow definitions
rg -g "*.ts" "metadata\.token" services/workflows-service/scripts/workflows/

Length of output: 78


Script:

#!/bin/bash
# Let's try a broader search for token-related patterns in workflow definitions
rg -g "*.ts" -e "metadata\.token" -e "{metadata.token}" -e "query\.token" -e "{query.token}" services/workflows-service/scripts/workflows/

Length of output: 291


Script:

#!/bin/bash
# Search for Authorization headers in workflow definitions
rg -g "*.ts" -B 2 -A 2 "Authorization.*Bearer" services/workflows-service/scripts/workflows/

Length of output: 14452


Script:

#!/bin/bash
# Look for any URL patterns that might contain tokens
rg -g "*.ts" "apiUrl.*token" services/workflows-service/scripts/workflows/

Length of output: 76

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 36-36: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


87-90: Verify token cleanup in finish state.

Since this is a final state operation, ensure proper token cleanup after workflow completion.

Check for cleanup handling:

✅ Verification successful

Let me search for token cleanup related code to verify the handling.


Let me try searching for cleanup patterns in the API plugins and collection flow related code.


Let me check the collection flow API implementation to understand the token handling.


Based on the review of the codebase and the context:

Token cleanup appears to be handled by the collection flow service

The token is passed in the Authorization header and handled by the collection flow service. Since the token is scoped to the API request and managed by the service layer, no explicit cleanup is required in the workflow definition.

  • The token is properly passed via Authorization header: headers: { Authorization: 'Bearer {query.token}' }
  • The workflow reaches a final state after the finish operation: finish: { type: 'final' }
  • Token lifecycle is managed by the collection flow service
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for token cleanup in finish state handlers
rg -g "*.ts" -B 5 -A 5 "type: 'final'" services/workflows-service/scripts/workflows/

Length of output: 36668


Script:

#!/bin/bash
# Search for token cleanup in API plugins and workflow extensions
rg -g "*.ts" "token.*cleanup|cleanup.*token" services/workflows-service/scripts/workflows/

Length of output: 92


Script:

#!/bin/bash
# Search for cleanup patterns in API plugins and collection flow
rg -g "*.ts" -B 3 -A 3 "cleanup|clear|reset" services/workflows-service/scripts/workflows/

Length of output: 92


Script:

#!/bin/bash
# Search for collection flow API implementation
ast-grep --pattern 'url: $_{collectionFlow.config.apiUrl}/api/v1/collection-flow'

Length of output: 83

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 90-90: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.


Line range hint 56-67: Verify token handling across all sync states.

The sync operation runs across multiple workflow states. Ensure all these state transitions properly handle the token parameter.

Let's check the state handling:

✅ Verification successful

Token handling is consistent across all state transitions

Based on the verification results, the token handling is properly implemented:

  1. The query.token is consistently used in the Authorization header across all API plugins
  2. The token is properly handled in both workflow definitions (kyb-parent-dynamic-example and kyb-with-associated-companies)
  3. All state transitions mentioned in the original stateNames array are covered by the API plugins with proper token authentication
  4. The same token handling pattern is used for all operations including end user updates, workflow state transitions, and workflow completion
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for state transition handlers in these states
ast-grep --pattern 'on: {
  $$$
  $state: $$$
  $$$
}' services/workflows-service/scripts/workflows/

Length of output: 102


Script:

#!/bin/bash
# Let's try a different approach to find state transitions and token handling
# First, let's search for files containing these state names
rg -l "personal_details|company_information|business_address_information|company_activity|bank_information|company_ownership|company_documents" services/workflows-service/scripts/workflows/

# Then let's look for token handling patterns
rg "query.token|Authorization.*Bearer" services/workflows-service/scripts/workflows/

Length of output: 5487


Script:

#!/bin/bash
# Let's examine the token handling in the definition logic files more closely
rg -A 5 -B 5 "Authorization.*Bearer.*query.token" services/workflows-service/scripts/workflows/ui-definition/kyb-with-associated-companies/ui-definition/kyb-with-associated-company-ui-def/defintion-logic.ts services/workflows-service/scripts/workflows/ui-definition/kyb-parent-dynamic-example/pages/defintion-logic.ts

Length of output: 15086

Comment on lines +58 to +60
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/end-user`,
method: 'POST',
headers: { Authorization: 'Bearer {metadata.token}' },
headers: { Authorization: 'Bearer {query.token}' },
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Security review: Token handling needs additional changes

The verification revealed inconsistent token handling across the codebase:

  • Several files still use URL-based token authentication:
    • packages/workflow-core/src/lib/plugins/external-plugin/vendor-consts.ts has multiple instances using metadata.token in URLs
    • services/workflows-service/src/workflow/workflow.controller.external.ts uses token in URL
    • Frontend apps (kyb-app, backoffice-v2) use URL-based token authentication

While the reviewed file correctly implements Bearer token authentication in headers, there are other parts of the system that need similar security improvements to maintain consistency and follow best practices.

🔗 Analysis chain

LGTM! Security improvement in token handling.

Moving the token from URL parameters to the Authorization header is a security improvement, as tokens in URLs can be logged in server logs or browser history.

Let's verify no other instances of URL-based token authentication remain:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of token in URLs
rg -g '*.ts' "token=[^&]*(\{metadata\.token\}|\{query\.token\})"

Length of output: 66


Script:

#!/bin/bash
# Let's try a broader search for URL patterns with tokens
rg -g '*.ts' -i "(\?|&)token="

# Also search for any remaining instances of metadata.token
rg -g '*.ts' "metadata\.token"

# And search for query.token usage
rg -g '*.ts' "query\.token"

# Look for Authorization headers to verify consistent token usage
rg -g '*.ts' "Authorization.*Bearer.*token"

Length of output: 7949

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 60-60: Hard-coded credentials
The hard-coded value "Bearer {{query.token}}" is used as authorization header.

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.

1 participant