Skip to content

Conversation

@skaerg
Copy link
Contributor

@skaerg skaerg commented Jul 3, 2025

https://issues.rudder.io/issues/27145

This bug seems to occur because of the Lift and ZIO environments interfere with each other - in particular, the calls to zio.runNow seem to reset the value Lift environment variables.
This kind of bug is sometimes resolved by removing calls to runNow that precede references to Lift parameters, but it did not work this time - these changes are still kept because they still eliminate potential errors of the same kind.
In the end, the fix in this case seems to require explicitly passing a context path argument in case the S.contextPath has been reset.

@skaerg skaerg requested a review from clarktsiory July 3, 2025 13:24
@skaerg skaerg self-assigned this Jul 3, 2025
@skaerg
Copy link
Contributor Author

skaerg commented Jul 4, 2025

Commit modified

@skaerg skaerg force-pushed the bug_27145/creating_global_parameter_with_change_validation_enabled_leads_to_404 branch from cdf500a to 9512453 Compare July 4, 2025 15:32
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

LGTM on the IOResult refactoring, only the link util require some change

Comment on lines 138 to 145
def redirectToChangeRequestLink(id: ChangeRequestId, contextPath: String = S.contextPath): JsCmd = {
if (S.contextPath == "") {
RedirectTo(s"${contextPath}${baseChangeRequestLink(id)}")
} else {
RedirectTo(baseChangeRequestLink(id))
}

}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why there is a check on the default value S.contextPath : when we pass an explicit contextPath then it means that we want to always use it, and not only when there is a issue leading to an empty one...
So it could be simplified to RedirectTo(changeRequestLink(id, contextPath))

And I'm not even sure that S.contextPath == "" is disallowed, in a server with only a single webapp

Copy link
Contributor Author

@skaerg skaerg Jul 7, 2025

Choose a reason for hiding this comment

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

alas, RedirectTo automatically adds the context path as a prefix when S.contextPath is set , i.e. calling RedirectTo(changeRequestLink(id)) when S.contextPath is set would return something that starts with rudder/rudder/...
I agree that this solution is not the most elegant ; could there be another way to do this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, to keep the API of the link utils look predictable, I suggest to redefine another RedirectTo that skips the check on the context path, since the issue is that the current one adds the context path wrt some logic, and because we don't want that logic when we pass an explicit contextPath.

It would then end up into :

  if (S.contextPath != contextPath) {
    RedirectToStrict(s"${contextPath}${baseChangeRequestLink(id)}")
  } else {
    RedirectTo(baseChangeRequestLink(id))
  }

if I'm not mistaken

@skaerg skaerg force-pushed the bug_27145/creating_global_parameter_with_change_validation_enabled_leads_to_404 branch from 9512453 to bb87d31 Compare July 7, 2025 15:42
@skaerg
Copy link
Contributor Author

skaerg commented Jul 7, 2025

Commit modified

Comment on lines 142 to 145
case class RedirectToFullPath(where: String) extends JsCmd {
override def toJsCmd: String = s"window.location = \"${where}\" ;"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if used in with other IDs which are mostly strings, this has some XSS vulnerability because the location is not escaped.
So it should keep the same security guards as in the Lift code with encJs

@skaerg
Copy link
Contributor Author

skaerg commented Jul 8, 2025

Commit modified

@skaerg skaerg force-pushed the bug_27145/creating_global_parameter_with_change_validation_enabled_leads_to_404 branch from bb87d31 to 132e291 Compare July 8, 2025 07:52
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

LGTM, this is likely to happen in other places due to progress in migrating away from Lift

@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge https://github.com/Normation/rudder/pull/6490
-- Your faithful QA
Kant merge: "Science is organized knowledge. Wisdom is organized life."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/103741/console)

@clarktsiory
Copy link
Contributor

OK, merging this PR

@clarktsiory clarktsiory merged commit ef86427 into Normation:branches/rudder/9.0 Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants