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 infinite redirect by clean up expired session #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

galupa
Copy link

@galupa galupa commented Jul 5, 2021

Hi,

This should fix infinite redirect problem when session lifetime is set up on Redmine.
From what I see the problem is after the session is expired, Redmine will redirect to login page because it detects the session is expired and on the login page it also check whether the client have any session and check if the session is expired or not, if it is it will redirect to login page and it will repeat it infinitely.
By default Redmine is clean up session if there any changes on user, in this case when the session is expired, Redmine should set the user as null which will reset the session, however since this plugin overwrite the logged_user, it does not clean up the session, that is why the expired user session will keep lingering and it cause the redirection.

What I do in this PR is just clean up the session when Redmine detect the session is expired (it will call require_login) and also call the default logged_user if the logged user is not ioc user. The second one is not mandatory but it can be a good guard if the system allow both oic user and Redmine internal user.

Please check it.

Best Regards,
Rangga

@iWangJiaxiang
Copy link

Hope this would be merged ASAP

@eni23
Copy link

eni23 commented Oct 12, 2021

Any updates? Wold be really really nice if this will be merged

@electrical
Copy link

I've implemented this but still hit the same infinite redirect :-(
Unsure how to debug it further

@galupa
Copy link
Author

galupa commented Mar 11, 2022

I've implemented this but still hit the same infinite redirect :-( Unsure how to debug it further

Have you clean up the browser cache when testing this? It is possible some cookies / session from previous version is still stored on the browser.

@electrical
Copy link

Not sure if my users did that. Will check with them.

@ataraxus
Copy link
Contributor

this hits me also all the time... will try this too and report back if it works

@ataraxus
Copy link
Contributor

ataraxus commented Jun 7, 2022

Hey Guys, after having used this a couple of months in production, have to say it doesnt solve the issue :(
Still getting infinite redirect after expired session.

@galupa
Copy link
Author

galupa commented Jun 10, 2022

Hi @ataraxus ,

Thank you for checking, is it possible for you to provide some logs? We have use the patch for about a year now and we have not got any issue, but if you can provide some logs that will be great, I can do some checks.

Best Regards,

@electrical
Copy link

I've been running into the same issues like @ataraxus
Next time it happens will try to grab as much info as possible.

@electrical
Copy link

What I've found so far:

A user gets redirected to our OpenID server due to Filter chain halted as :session_expiration rendered or redirected
A new entry gets created in the oic_sessions table.
This entry contains state,nonce, created_at and updated_at information but everything else is empty.
The OpenID server wants to redirect the user back to Redmine because the user has a valid session with the OpenID server.
And it starts all over again.

Wed, Jun 15 2022 10:01:58 am | Redirected to https://redmine.corp.com/oic/login
Wed, Jun 15 2022 10:01:58 am | Filter chain halted as :session_expiration rendered or redirected
Wed, Jun 15 2022 10:01:58 am | Completed 302 Found in 7ms (ActiveRecord: 2.1ms)
Wed, Jun 15 2022 10:01:58 am | Redirected to https://auth.corp.com/auth/realms/corp/protocol/openid-connect/auth?client_id=redmine&nonce=4476da00-8da6-4d5d-be00-f89d06514ed8&redirect_uri=https%3A%2F%2Fredmine.corp.com%2Foic%2Flocal_login&response_type=code&scope=openid+profile&state=c6f5f45f-1e89-42b5-b835-096d2a932580
Wed, Jun 15 2022 10:01:58 am | Completed 302 Found in 95ms (ActiveRecord: 90.0ms)
Wed, Jun 15 2022 10:01:59 am | Started GET "/oic/login" for 127.0.0.1 at 2022-06-15 09:01:58 +0000
Wed, Jun 15 2022 10:01:59 am | Processing by AccountController#oic_login as HTML
Wed, Jun 15 2022 10:01:59 am | Redirected to https://redmine.corp.com/oic/login


@galupa
Copy link
Author

galupa commented Jun 15, 2022

Hi @electrical ,

Thank you for the logs, can I also know your plugin config also? I just want to know if login_selector is on or off.

Cheers

@electrical
Copy link

@galupa config:

--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
enabled: 'false'
client_id: redmine
openid_connect_server_url: https://auth.corp.com/auth/realms/corp
client_secret: xxxxxxxxxxxxxxxxxxxxxxx
scopes: openid,profile
group: Users
admin_group: RedmineAdmin
dynamic_config_expiry: ''
create_user_if_not_exists: 'true'

Interestingly enough the plugin saves things in a weird way. 'false' is still true :)

@electrical
Copy link

@galupa do you have any ideas on this? Thanks!

@galupa
Copy link
Author

galupa commented Jul 5, 2022

Hi,

Apologies, I have been busy lately, but I think I know what the problem is, I will take a look at it some times this week and will update.

Cheers

@electrical
Copy link

Wonderful. thank you!

fix logic to allow not using login selector
@galupa galupa force-pushed the fix_infinite_redirect branch from fbb856f to 3de60b2 Compare July 7, 2022 22:54
@galupa
Copy link
Author

galupa commented Jul 7, 2022

Hi @electrical ,

I have made some changes, looks like the previous code is working because we are enabling the login selector, and my previous fix is fail if the login selector is disabled.
I have made some adjustment so that the fix will work on both scenario.

I have do some testing and it should work now but please check it if you have some time, and let me know if the problem still happening.

Best Regards,
Rangga

Copy link
Contributor

@ataraxus ataraxus left a comment

Choose a reason for hiding this comment

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

LGTM

@guoanhao
Copy link

Thank you. Which version of redmine is applicable

@galupa
Copy link
Author

galupa commented Jan 27, 2023

I am using version 4.1.x at the moment, I think it should be still compatible on version 4.2.x but I have not properly tested it against it.
And most likely will not working on version 5 because of Zeitwerk replacing classic autoloader on rails 6.

@galupa
Copy link
Author

galupa commented Jan 28, 2023

Actually there is already a PR for Redmine 5 so it should work on Redmine 5 now.

@galupa
Copy link
Author

galupa commented Jan 28, 2023

Hi All, does anyone knows who can Merge this PR?

@guoanhao
Copy link

I am using version 4.1.x at the moment, I think it should be still compatible on version 4.2.x but I have not properly tested it against it. And most likely will not working on version 5 because of Zeitwerk replacing classic autoloader on rails 6.

thank you,My report is wrong,Have you ever met

image

image

@galupa
Copy link
Author

galupa commented Jan 30, 2023

I am using version 4.1.x at the moment, I think it should be still compatible on version 4.2.x but I have not properly tested it against it. And most likely will not working on version 5 because of Zeitwerk replacing classic autoloader on rails 6.

thank you,My report is wrong,Have you ever met

image

image

Have you tried check the Create user if not exists option?
Btw, if you have a question not related to PR maybe better create an issue instead so that the others does not get notification for non related question.
I am happy to answer another question in issues in my fork, so feel free to do that.

Cheers

@guoanhao
Copy link

I am using version 4.1.x at the moment, I think it should be still compatible on version 4.2.x but I have not properly tested it against it. And most likely will not working on version 5 because of Zeitwerk replacing classic autoloader on rails 6.

thank you,My report is wrong,Have you ever met
image
image

Have you tried check the Create user if not exists option? Btw, if you have a question not related to PR maybe better create an issue instead so that the others does not get notification for non related question. I am happy to answer another question in issues in my fork, so feel free to do that.

Cheers

thank you,i Created a new issue:#77

@ndkhaivn
Copy link

Hi, is there anything blocking this from merging?

@ericbrun-73
Copy link

Hi,
We have this problem (Too many redirect) on our Redmine 5.0.5.
I patched the Open ID Connect plugin with the correction.
We testing now ....

I hope that fix our Redmine access ....
We will see ....

@mattock
Copy link

mattock commented Oct 5, 2023

We seems to have the same redirect loop issue, but it is not triggered by session expiration:

Filter chain halted as :check_if_login_required rendered or redirected

In our case session expiration was not enabled, so something else is triggering this.

@luizjr
Copy link

luizjr commented Oct 23, 2023

@galupa , I tested the code and it worked as expected. I still don't know why not to do the merge

@deather
Copy link

deather commented Jan 31, 2024

Hi, Same problem here.

I apply the patch on a browser that is encountered the problem. After applying everithing is working like a charm.

Thank you @galupa

@mattock
Copy link

mattock commented Apr 8, 2024

We seems to have the same redirect loop issue, but it is not triggered by session expiration:

Filter chain halted as :check_if_login_required rendered or redirected

In our case session expiration was not enabled, so something else is triggering this.

We applied this PR and the problem is gone. We know that with some browsers and/or operating systems the problem does not manifest itself much. For example, MacOS with Safari (I believe) is not affected as much as Fedora Linux 38 with Firefox.

In any case this PR solves a genuine issue that affects many. So far I have not seen any issues with this fix.

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.