[DEFECT] Secrets during automated workflow action not resolving as expected
Problem Statement
We have an issue when the SecretTool is invoked outside of a standard HTTP request context (such as during a scheduled job or an automated workflow action). In this scenario the system fails to correctly resolve secrets. This happens because the permission evaluation for accessing secrets defaults to an anonymous user when no user is found in the current HTTP request, even if a valid system user is present in the execution context.
Technical Root Cause
The issue is located in the canUserEvaluate method of SecretTool. The logic strictly relies on WebAPILocator.getUserWebAPI().getUser(this.request) to identify the performing user.
- HTTP Context: When triggered via a web request, the user is correctly retrieved from the request object.
- Job Context: When triggered via a background job (e.g., a scheduled publication),
this.requestdoes not contain a logged-in user, andgetUser()returns an anonymous user. - The Mismatch: Even though the background execution context often carries the "System User" within the Velocity
contextobject,SecretToolwas not looking there. Since the anonymous user typically lacks theSCRIPTING_DEVELOPERrole, the evaluation fails with aSecurityException, preventing the secret from being resolved.
Steps to Reproduce
- Ensure a System User exists in the instance.
- Create a secret in the Secrets App (e.g., Key:
mySecret, Value:secretValue). - Go to Workflows -> System Workflow and edit the Publish action.
- Add a Velocity Action Script sub-action that attempts to access the secret:
#set($val = $dotsecrets.get("mySecret")) $logger.info("Secret value: $val") - Create a new Content Type with a text field and a Date/Time field. Enable the System Indexed option for the Date/Time field.
- Edit the Content Type and set the newly created Date/Time field as the Publish Date field.
- Create a new Contentlet of this type. Set the Publish Date to a few minutes in the future.
- Click Publish. A notification should indicate the content is scheduled for future publication.
- Wait for the scheduled job to run.
- Actual Scenario: The content status changes to Published, but the secret is not resolved. Checking the logs reveals:
Failed to evaluate Scripting Role presence: External scripting is disabled in your dotcms instance. - Expected Scenario: The job should execute, the system user from the context should be recognized, and the secret should be resolved and logged correctly without security exceptions.
Acceptance Criteria
To resolve this issue, the following objective criteria must be met:
- [ ]
SecretToolmust attempt to retrieve the user from the Velocitycontextif the user retrieved from theHttpServletRequestis null or anonymous. - [ ] The fallback mechanism should specifically look for the
"user"key within the Velocity context. - [ ] If a valid user (e.g., System User) is found in the context, it must be used to validate the
SCRIPTING_DEVELOPERrole. - [ ] Existing behavior for standard HTTP requests must remain unchanged.
- [ ] Automated tasks (like scheduled publishing) utilizing
SecretToolmust be able to resolve secrets successfully.
dotCMS Version
main
Severity
Medium - Some functionality impacted
Links
PRs linked to this issue
- fix(Secrets): Added logic to search for user in context if not present in request during automated workflow action by @ihoffmann-dot
PRs linked to this issue
QA Failed The fix works partially. For secrets stored under the System Host, it works fine and the secret is retrieved as expected. However, for contentlets that belongs to a specific site, secrets stored for that specific host are not retrieved.
Steps to replicate the failed scenario:
- Create a new secret in the Dot Velocity Secrets app, and save the secret for a specific site different from the system host (for example use "default" site).
- Create a site field for the content type.
- Create a new contentlet and set the field site to point to the site that contains the stored secret(default site).
- Set the Publish Date for the new contentlet a few minutes in the future and save the content.
- Wait for the auto publish job to run.
- The secret stored for the site assigned to the contentlet wasn't retrieved as expected.
QA Passed It works as expected now: the secret is retrieved from the config for the site that the content belongs.