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

Custom cookie name breaks redis for session #978

Open
thekoma opened this issue Jan 7, 2021 · 47 comments
Open

Custom cookie name breaks redis for session #978

thekoma opened this issue Jan 7, 2021 · 47 comments

Comments

@thekoma
Copy link

thekoma commented Jan 7, 2021

Expected Behavior

Login succeed

Current Behavior

If you specify a custom cookie name while using redis to manage sessions we are unable to decrypt the cookie:

oauth2-proxy      | [2021/01/07 15:44:47] [stored_session.go:75] Error loading cookied session: failed to decode ticket, removing session
oauth2-proxy      | [2021/01/07 15:44:47] [stored_session.go:78] Error removing session: error decoding ticket to clear session: failed to decode ticket
oauth2-proxy      | [2021/01/07 15:44:47] [oauthproxy.go:506] Error clearing session cookie: error decoding ticket to clear session: failed to decode ticket
oauth2-proxy      | 172.18.0.10 - - [2021/01/07 15:44:47] sonarr.koma.link GET - "/oauth2/sign_in" HTTP/1.1 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.107 Safari/537.36" 500 394 0.000
oauth2-proxy      | [2021/01/07 15:44:47] [stored_session.go:75] Error loading cookied session: http: named cookie not present, removing session

Possible Solution

  • Ignore the cookie name parameter when session is managed by redis
  • Decrypt using the correct cookie name
@JoelSpeed
Copy link
Member

This definitely used to work as I've been using it in the past for production instances, could you confirm which version of the proxy you are using?

@JoelSpeed JoelSpeed added the bug label Jan 7, 2021
@thekoma
Copy link
Author

thekoma commented Jan 7, 2021

@JoelSpeed compiled the master a couple hour before filling the bug

@NickMeves
Copy link
Member

Hmmm - this cookie change just merged a few days ago: #970

Regression potentially?

If you built from commits before that PR merged, do you still get this bug?

@NickMeves
Copy link
Member

So based on your error message, you have a valid cookie at this point that passed signature validation. But the inner content isn't formatted correctly so decodeTicket fails:

func decodeTicket(encTicket string, cookieOpts *options.Cookie) (*ticket, error) {

Do you have a sample on what your cookie value looked like?

Ticket sessions have 2 parts in the cookie split by a . - the Ticket ID & the Ticket Secret. The Ticket ID is used as the key in your store to find the encrypted and encoded session object in your data store. The Ticket Secret is the decryption key (makes it so a compromised session store can't steal sessions, it has a per session secret that is stored with the uses in their cookies).

@NickMeves
Copy link
Member

oh I wonder... Does your custom name have a . in it?

@NickMeves
Copy link
Member

That would then make the encoded ticket value have more than 2 entries after a split on . and give that error message you saw. Since the Ticket ID includes the cookie name as a base (either for debugging help or to really ensure no conflicts in a shared redis DB even though 16 byte random keys shouldn't collide probabilistically -- I don't know the original design intent).

ticketID := fmt.Sprintf("%s-%s", cookieOpts.Name, hex.EncodeToString(rawID))

Would explain your error message from this:

ticketParts := strings.Split(encTicket, ".")
if len(ticketParts) != 2 {
	return nil, errors.New("failed to decode ticket")
}

@thekoma
Copy link
Author

thekoma commented Jan 11, 2021

yes it has

@NickMeves
Copy link
Member

Cool thanks - that's the issue. At the moment I recommend you just use a different character in your custom cookie name to get over this issue.

Long term, I've tagged this as a bug for us to fix the encoding scheme so it is aware of . in the cookie name. This change will need to be aware of legacy & new encoding schemes simultaneously so it isn't a breaking change for existing Redis users.

@thekoma
Copy link
Author

thekoma commented Jan 11, 2021

Cool! Thank you

@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Mar 13, 2021
@thekoma
Copy link
Author

thekoma commented Mar 15, 2021

This is still a bug @NickMeves ?

@JoelSpeed JoelSpeed removed the Stale label Mar 15, 2021
@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label May 15, 2021
@JoelSpeed JoelSpeed removed the Stale label May 16, 2021
@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Jul 16, 2021
@JoelSpeed JoelSpeed removed the Stale label Jul 16, 2021
@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Sep 15, 2021
@thekoma
Copy link
Author

thekoma commented Sep 15, 2021

Is this still interesting?

@JoelSpeed JoelSpeed removed the Stale label Sep 15, 2021
@JoelSpeed
Copy link
Member

Yeah we still need to get round to finding a fix for this 🙂

@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
@thekoma
Copy link
Author

thekoma commented Jul 18, 2023

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

. This issue gas a pr ti dolce the problema that is still there 3y layer.

Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Nov 17, 2023
@thekoma
Copy link
Author

thekoma commented Nov 17, 2023

/unstale

@tuunit
Copy link
Member

tuunit commented Nov 18, 2023

Hi @thekoma,

I've never looked into this issue before. I would like to give this a fresh look. Could you provide the following details:

Your configuration for oauth2-proxy and redis. Which version this occurs on and if you have tested it with the latest version?

@thekoma
Copy link
Author

thekoma commented Nov 18, 2023

I don't use oauth2proxy at the moment the issue is 3 years old 😅.
I can check for the old config maybe.

@thekoma
Copy link
Author

thekoma commented Nov 18, 2023

Just checked and the config is lost in time. If it's necessary to proceed I will need time to produce it again.

JoelSpeed added a commit that referenced this issue Nov 18, 2023
* Issue 978: Fix Custom cookie name breaks redis for session (see #978)

* Issue 978: Fix Custom cookie name breaks redis for session (see #978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
tuunit pushed a commit to tuunit/oauth2-proxy that referenced this issue Nov 20, 2023
…oxy#1949)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
tuunit pushed a commit to tuunit/oauth2-proxy that referenced this issue Nov 20, 2023
…oxy#1949)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
tuunit pushed a commit to tuunit/oauth2-proxy that referenced this issue Dec 17, 2023
…oxy#1949)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
tuunit pushed a commit to tuunit/oauth2-proxy that referenced this issue Dec 18, 2023
…oxy#1949)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Issue 978: Fix Custom cookie name breaks redis for session (see oauth2-proxy#978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
JoelSpeed added a commit that referenced this issue Dec 18, 2023
* Add GitHub groups (orgs/teams) support

* align code of getTeams with getOrgs to support Github Enterprise Server instances with different domain

* add documentation

* add missing import after rebase

* add nightly build and push (#2297)

* add nightly build and push

* add date based nightly build tags

* only keep single multiarch image build and push

* add changelog

* add images to internal docs static files

* add docu for nightly builds

* remove unnecessary spaces

* update nightly repository

* Issue 978: Fix Custom cookie name breaks redis for session (#1949)

* Issue 978: Fix Custom cookie name breaks redis for session (see #978)

* Issue 978: Fix Custom cookie name breaks redis for session (see #978)

* Update CHANGELOG.md

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Issue 978: Fix Custom cookie name breaks redis for session

* Update CHANGELOG.md

---------

Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Support http.AllowQuerySemicolons (#2248)

* Support http.AllowQuerySemicolons

* Docs

* Make it clear we are overriding the handler

* Update documentation for allow-query-semicolons

* Fix changelog format

* Fix formatting

---------

Co-authored-by: MickMake <github@mickmake.com>

* Add GitHub groups (orgs/teams) support

* align code of getTeams with getOrgs to support Github Enterprise Server instances with different domain

* add documentation

* fix changelog & documentation

* fix missing import

---------

Co-authored-by: Tobias Mayer <github@tobiasm.de>
Co-authored-by: Nuno Miguel Micaelo Borges <miguelborges99@gmail.com>
Co-authored-by: Nuno Borges <Nuno.Borges@ctw.bmwgroup.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
Co-authored-by: Tim White <tim.white@su.org.au>
Co-authored-by: MickMake <github@mickmake.com>
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Jan 25, 2024
@thekoma
Copy link
Author

thekoma commented Jan 25, 2024

/unstale

@github-actions github-actions bot removed the Stale label Jan 27, 2024
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Mar 29, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
@tuunit tuunit removed the Stale label Apr 5, 2024
@tuunit tuunit reopened this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants