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

fix: Use an HTTP 301 redirect for internal redirects initiated by LTI logins #422

Closed

Conversation

hectoras
Copy link
Contributor

@hectoras hectoras commented Aug 7, 2024

Associated Jira issue: SOLAR-668

When a user clicks on the link from Portal to go into TAO 3.x, Portal redirects the user to https://backoffice.host/taoLti/AuthoringTool/launch with an LTI payload with a short expiration time. That payload is expected to be used only once.

In turn, when this request hits TAO 3.x, the launch() action validates the payload and security constraints, starts a user session and forwards its processing to the run() method in the same controller ($this->forward()). When run() is called, it checks if the user session just created by launch() is valid, and then issues an HTTP redirect (redirect()).

This redirect happens to be sent to the client as a a generic HTTP 302 Found response, which is meant to indicate that the target resource resides temporarily under a different URI and, since the redirection might be altered on occasion, expects the browser to continue to use the target URI for future requests [ref]. That means the 302 redirect makes the browser to keep the intermediate URL returning the redirect itself as part of the "normal flow": The URL for the controller that validates the request coming from Portal is kept in the browser history, as it might be altered on occasion.

Changes in this PR make that intermediate jump from the authentication logic (launch()) into Authoring itself (run()) to be issued as an HTTP 301 Moved Permanently redirect instead, which makes any future references to the intermediate URL to use one of the enclosed URIs [ref]. That means the intermediate redirect is permanent, and the browser shall use the target URL for the redirect instead of the intermediate one. The net effect of this is that the intermediate URL (launch()) is not part of the "normal flow" anymore, so it is not kept in the browser history: Clicking the "back button" goes back to Portal.

There's also another intermediate request to the Auth server to get a token used for the LTI launch; however, that one is handled within the Javascript code and therefore it's not captured in the browser history.

Note the previous URL will be http://portal.host/content-bank, meaning clicking on the back button will bounce the user back to TAO 3.x. That is to be fixed at the Portal FE.

Related PR:

@hectoras hectoras changed the base branch from master to develop August 8, 2024 08:51
@hectoras hectoras marked this pull request as ready for review August 8, 2024 11:01
@hectoras hectoras removed the request for review from andreluizmachado August 8, 2024 11:17
$this->getLogger()->warning(
sprintf(
'Missing registration for current audience. Redirecting to the login page. Exception: %s',
$exception
)
);
$this->redirect(_url('login', 'Main', 'tao'));

$this->redirect(_url('login', 'Main', 'tao')); // throws
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 add a return here, does not make sense to redirect follow to an exception throw. It is really confusing reading the code.

Suggested change
$this->redirect(_url('login', 'Main', 'tao')); // throws
$this->redirect(_url('login', 'Main', 'tao'));
return;

Copy link

github-actions bot commented Aug 8, 2024

Version

Target Version 15.19.6
Last version 15.19.5

There are 0 BREAKING CHANGE, 0 feature, 1 fix

Copy link
Contributor

@gabrielfs7 gabrielfs7 left a comment

Choose a reason for hiding this comment

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

LGTM, code check only

To be validated by QA to be sure behavior works and it is backward compatible

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful

@hectoras
Copy link
Contributor Author

hectoras commented Aug 12, 2024

Actually, it seems that sticking to the default 302 redirect instead of a 301 is also working as expected once we initiate the page change using the new mechanism from https://github.com/oat-sa/tao-portal/pull/1091/files, closing this

@hectoras hectoras closed this Aug 12, 2024
@hectoras hectoras deleted the fix/SOLAR-668-use-http-301-for-internal-redirect branch August 12, 2024 14:17
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