Skip to content

Conversation

bdoubrovine
Copy link

@bdoubrovine bdoubrovine commented Jun 7, 2025

This pull request introduces enhancements to the getEnvironmentExtraVars method in services/tasks/LocalJob.go to improve the handling of secret variables. The most important change involves merging secret variables into the existing environment variables while ensuring the secret is reset after processing.

Enhancements to secret variable handling:

  • Added a new map, extraSecretVars, to handle secret variables separately and parse them from the t.Secret JSON string. If parsing fails, the method returns an error.
  • Reset the t.Secret field to an empty JSON object ("{}") after processing to ensure that secrets are not retained in memory.
  • Merged the parsed extraSecretVars into the extraVars map using maps.Copy, consolidating all variables into a single map for further use.

#2322 and #2287

@bdoubrovine bdoubrovine changed the title fix: add secret survey variable on opentofu task issue #2554 fix: add secret survey variable on opentofu task issue #2322 Jun 8, 2025
@fiftin fiftin requested a review from Copilot July 31, 2025 12:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances secret variable handling in the getEnvironmentExtraVars method by adding support for parsing and merging secret variables from a separate JSON field while ensuring secrets are cleared from memory after processing.

  • Added parsing of secret variables from t.Secret JSON field with error handling
  • Implemented automatic clearing of the t.Secret field after processing to prevent secret retention
  • Merged secret variables with existing environment variables using maps.Copy

if err != nil {
return
}
}
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

Setting t.Secret = "{}" may not be sufficient to clear sensitive data from memory. The original string containing secrets may still exist in memory. Consider using a more secure approach like overwriting the memory or ensuring the original secret data is properly cleared.

Suggested change
}
}
// Securely clear the sensitive data in t.Secret
if len(t.Secret) > 0 {
secretBytes := []byte(t.Secret)
for i := range secretBytes {
secretBytes[i] = 0
}
}

Copilot uses AI. Check for mistakes.

}
t.Secret = "{}"

maps.Copy(extraVars, extraSecretVars)
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

Secret variables are being copied into extraVars which may be used elsewhere in the application. Consider whether these secret values should be masked or handled with additional security measures when stored in the shared extraVars map.

Suggested change
maps.Copy(extraVars, extraSecretVars)
for key, value := range extraSecretVars {
extraVars[key] = maskSensitiveValue(value)
}

Copilot uses AI. Check for mistakes.

Comment on lines +79 to +82
err = json.Unmarshal([]byte(t.Secret), &extraSecretVars)
if err != nil {
return
}
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

The condition t.Secret != "" may not handle the case where t.Secret is "{}" (empty JSON object). Consider checking for both empty string and empty JSON object, or use a more robust validation method.

Suggested change
err = json.Unmarshal([]byte(t.Secret), &extraSecretVars)
if err != nil {
return
}
var tempSecretVars map[string]any
err = json.Unmarshal([]byte(t.Secret), &tempSecretVars)
if err != nil {
return
}
if len(tempSecretVars) > 0 {
extraSecretVars = tempSecretVars
}

Copilot uses AI. Check for mistakes.

@fiftin
Copy link
Collaborator

fiftin commented Jul 31, 2025

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


Bugbot free trial expires on August 10, 2025
Learn more in the Cursor dashboard.

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.

2 participants