Skip to content

Commit

Permalink
Merge pull request #52 from Viasat/win-fix
Browse files Browse the repository at this point in the history
fix windows cookie parsing problem
  • Loading branch information
bcaselden-viasat committed May 15, 2024
2 parents a82d78b + 55897f7 commit 4e4047c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alohomora/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import sys

__version__ = '3.1.0'
__version__ = '3.1.1'
__author__ = 'Viasat'
__author_email__ = '[email protected]'
__license__ = '(c) 2022 Viasat, Inc. See the LICENSE file for more details.'
__license__ = '(c) 2024 Viasat, Inc. See the LICENSE file for more details.'
__url__ = 'https://github.com/Viasat/alohomora'
__description__ = 'Get AWS API keys for a SAML-federated identity'

Expand Down
10 changes: 10 additions & 0 deletions alohomora/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import time
import os
import base64
from datetime import datetime, timedelta
from http.cookiejar import LWPCookieJar

try:
Expand Down Expand Up @@ -806,6 +807,15 @@ def _make_request(self, url, func, data=None, headers=None, soup=True):
LOG.debug("Post cookie jar: %s", self.session.cookies)
LOG.debug("Request headers: %s", response.request.headers)
LOG.debug("Response headers: %s", response.headers)
# On Windows the python builtin cookiejar chokes on a returned timestamp
# in the DUO status cookie. It is set to expire far in the future in the
# year 9999. Windows can not parse this timestamp, so we overwite it with
# an expiration 30 days in the future so it is parsable in Windows.
future_ts = (datetime.now() + timedelta(days=30)).timestamp()
for cookie in self.session.cookies:
if cookie.expires and cookie.expires > future_ts:
LOG.debug(f"rewrite coookie expires from: {cookie.expires} to: {future_ts}")
cookie.expires = future_ts
self.session.cookies.save(ignore_discard=True, ignore_expires=True)
if soup:
the_soup = BeautifulSoup(response.text, 'html.parser')
Expand Down

0 comments on commit 4e4047c

Please sign in to comment.