Skip to content

Conversation

@NewtonDer
Copy link

Commit summary:

fix: missing Authorization header returns 400 Bad Request

Description of changes:

  • Catch KeyError and IndexError when building auth headers, and return a 400 Bad Request.
  • Upgrade to v0.3.7.

Why:

Currently, if an upstream request is missing an Authorization header, a Python stack trace is returned in the response body. This was flagged as a potential security vulnerability. Similar to the issue fixed in #26

We now catch KeyError and IndexError when building upstream request auth headers. We don't expect customers to malform a request, so we deliberately return a vague error message.

Verification:

  • Build a .whl with python -m build.
  • Verify it is commit b96eeb3
  • Install the .whl in SageMaker Studio.
  • Verify 0.3.7 is installed with pip list.
  • Make a network call to an AWS service using aws_jupyter_proxy, making sure that an Authorization header is missing.
  • Observe that a 400 Bad Request is returned.

@NewtonDer
Copy link
Author

@vietle-aws @danpilgrim-aws

@NewtonDer
Copy link
Author

@larrygao001 @declanvk please take a look

@vietle-aws
Copy link
Contributor

LGTM

@aws-khatria
Copy link
Contributor

I reviewed the previous PR associated here. It recommended logging the missing header in case of exception. Can you please incorporate the comments from previous PR?

auth_header_parts[1].split("=")[1].split("/")
)
except (KeyError, IndexError):
raise HTTPError(400, message=f"Bad Request")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "Bad Request" sufficient? Does security guideline allow you to put some specific message, like, "Malformed Authorization header"?


@pytest.mark.asyncio
@patch("os.getenv")
async def test_missing_authorization_header(mock_getenv, mock_session):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about a test case for malformed authorization header?

Copy link
Contributor

@aws-khatria aws-khatria left a comment

Choose a reason for hiding this comment

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

LGTM

@amvadhia amvadhia merged commit d13cca4 into aws:master Mar 17, 2023
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.

4 participants