Skip to main content

requests-credssp

Test workflow codecov PyPI version License

About this library

This package allows for HTTPS CredSSP authentication using the requests library. CredSSP is a Microsoft authentication that allows your credentials to be delegated to a server giving you double hop authentication.

Features

This library supports the following CredSSP features

  • Protocol version 2 to 6
  • Initial authentication with NTLM or Kerberos
  • Message encryption support using the wrap and unwrap functions

Requirements

The following Python libraries are required;

By default, this library can authenticate with a Windows host using NTLM messages, if Kerberos authentication is desired, please read the below.

Installation

To install requests-credssp, simply run

pip install requests-credssp

# to install the optional Kerberos functionality, run (see below)
pip install requests-credssp[kerberos]

Kerberos on Linux

To add support for Kerberos authentication on a non-Windows host, the Kerberos system headers must be installed and the python-gssapi library installed. To install the Kerberos system headers you can install the following packages;

# Via Yum (Centos RHEL)
yum -y install python-devel krb5-devel krb5-libs krb5-workstation

# Via Dnf (Fedora)
dnf -y install python-devel krb5-devel krb5-libs krb5-workstation

# Via Apt (Ubuntu)
apt-get -y install python-dev libkrb5-dev krb5-user

# Via Portage (Gentoo)
emerge -av app-crypt/mit-krb5
emerge -av dev-python/setuptools

# Via pkg (FreeBSD)
sudo pkg install security/krb5

# Via OpenCSW (Solaris)
pkgadd -d http://get.opencsw.org/now
/opt/csw/bin/pkgutil -U
/opt/csw/bin/pkgutil -y -i libkrb5_3

# Via Pacman (Arch Linux)
pacman -S krb5

Once installed, the Python Kerberos libraries can be installed with

pip install requests-credssp[kerberos]

Once installed, the file /etc/krb5.conf should be configured so it can talk with the Kerberos KDC.

To add proper SPNEGO support with python-gssapi, the gss-ntlmssp should also be installed which adds NTLM as a supported GSSAPI mechanism required for proper SPNEGO interoperability with Windows. This package can be installed with;

# Via Yum (Centos RHEL) - requires epel-release
yum -y install epel-release
yum -y install gssntlmssp

# Via Dnf (Fedora)
dnf -y install gssntlmssp

# Via Apt (Ubuntu)
apt-get -y install gss-ntlmssp

# Via Pacman (Arch Linux)
pacman -S gss-ntlmssp

Additional Info

The CredSSP protocol is quite complex and uses a lot of other protocols or standards to work properly. This unfortunately means some older hosts or settings are incompatible or require some workarounds to get working. Currently you can configure the following settings when initialising the CredSSP class;

  • auth_mechanism: The authentication mechanism to use initially, default is auto
  • disable_tlsv1_2: Whether to disable TLSv1.2 support and work with older protocols like TLSv1.0, default is False
  • minimum_version: The minimum CredSSP server version that is required by the client, default is 2
  • hostname_override: The hostname to use for the service principal name (HTTP/<hostname>) instead of the hostname in the URL, default is None

Authentication Mechanisms

Part of the CredSSP protocol is to authenticate the user's credentials using the SPNEGO protocol. The SPNEGO protocol is also called Negotiate and is able to negotiate a common protocol between the client and the server which can currently be either NTLM or Kerberos. Kerberos is a tricky protocol to have set up but should be used wherever it is possible as NTLM uses older standards that are considered broken from a security perspective.

Due to historical decisions and that Kerberos is not always available by default, the base install of requests-credssp will only work with NTLM. When the Kerberos packages are installed and configured, requests-credssp will automatically attempt to use Kerberos if possible but fall back to NTLM if it fails like it would with SPNEGO. If you wish to force either Kerberos or NTLM instead of relying on the SPNEGO mechanism, you can set auth_mechanism=<auth_mech> when creating HttpCredSSPAuth like so;

import requests
from requests_credssp import HttpCredSSPAuth

# use SPNEGO (default if omitted)
credssp_auth = HttpCredSSPAuth('domain\\user', 'password',
                               auth_mechanism='auto')

# only allow Kerberos
credssp_auth = HttpCredSSPAuth('user@REALM.COM', 'password',
                               auth_mechanism='kerberos')


# only allow NTLM
credssp_auth = HttpCredSSPAuth('domain\\user', 'password',
                               auth_mechanism='ntlm')


r = requests.get("https://server:5986/wsman", auth=credssp_auth)

TLS Protocol Versions

As CredSSP uses TLS to encrypt the tokens that are transferred between the client and the server, it is succeptible to differing implementations of SSL. By default, requests-credssp will work with server's that offer TLSv1.2 but older Windows hosts that do not support this newer protocol version will

TLSv1.2 was added in Windows Server 2012 and Windows 8 where older hosts need an optional update to be installed for it to work. If this update cannot be installed or you are willing to accept the risks of using the older TLS protocols, requests-credssp can be set to disable TLSv1.2 and work with older protocols like so;

import requests
from requests_credssp import HttpCredSSPAuth

credssp_auth = HttpCredSSPAuth("domain\\user", "password", disable_tlsv1_2=True)
r = requests.get("https://server:5986/wsman", auth=credssp_auth)

CredSSP Protocol Versions

Recently Microsoft has released a security update to CredSSP to mitigate CVE 2018-0886. The update added 2 new CredSSP protocol versions, 5 and 6 which changes the way the client and server authenticate each other. While these changes are transparent to someone who uses this library, it may be prudent to set the minimum version that this client would authenticate with. This means that any older server's who have not been patched for this vulnerability will be rejected.

To set a minimum protocol version that will only allow servers that have been patched for CVE 2018-0886, set minimum_version=5 when creating HttpCredSSPAuth like so;

import requests
from requests_credssp import HttpCredSSPAuth

credssp_auth = HttpCredSSPAuth('domain\\user', 'password', minimum_version=5)
r = requests.get("https://server:5986/wsman", auth=credssp_auth)

Message Encryption

You can use this library to encrypt and decrypt messages sent to and from the server. Message encryption is done over the TLS channel that was negotiated in the authentication stage. The below is an example of encrypting and decrypting messages, note this is only a basic example and not a working script and the actual implementation depends on the protocol that is reading the messages.

import requests
from requests_credssp import HttpCredSSPAuth

# build the auth request and sent an empty message to authenticate
hostname = "server"
session = requests.Session()
session.auth = HttpCredSSPAuth("domain\\user", "password")

request = requests.Request("POST", "https://%s:5986/wsman" % server, data=None)
prepared_request = self.session.prepare_request(request)
response = session.send(prepared_request)

context = session.auth.contexts[hostname]
# encrypt the message using the wrap command
message = b"hi server"
encrypted_message = context.wrap(message)

# send the encrypted message and get the encrypted response
request = requests.Request("POST", "https://server:5986/wsman", data=encrypted_message)
prepared_request = self.session.prepare_request(request)
response = session.send(prepared_request)

# decrypt the encrypted response from the server
encrypted_response = response.content
decrypted_response = context.unwrap(encrypted_response)

Logging

This library uses the standard Python logging facilities. Log messages are logged to the requests_credssp and requests_credssp.credssp named loggers.

If you are receiving any errors or wish to debug the CredSSP process you should enable DEBUG level logs. These logs show fine grain information such as the protocol and cipher negotiated and each CredSSP token used in the authentication process.

Development

Dependencies are managed with uv:

uv sync
uv run pytest

Run uv lock after changing the dependencies in pyproject.toml.

Releasing

  1. Set the version in pyproject.toml and push a matching v* tag.
  2. CI builds and tests the release and attaches it to a draft GitHub release.
  3. Publishing the draft release uploads it to PyPI.

Backlog

  • Add support for different credential types like smart card and redirected credentials

Metadata

Release files for requests-credssp 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for requests-credssp 2.1.0
File Size Uploaded Provenance Actions
requests_credssp-2.1.0.tar.gz 19.0 kB With provenance Details for requests_credssp-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for requests-credssp 2.1.0
File Interpreter ABI Platform Actions
requests_credssp-2.1.0-py3-none-any.whl Python 3 none any Details for requests_credssp-2.1.0-py3-none-any.whl

Total release size: 30.1 kB

Release files / requests_credssp-2.1.0.tar.gz

Download URL requests_credssp-2.1.0.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
61bdd1b3b46556b6fa46b4765f24b5e00e39597abfadc24ec26577a39098da1a
BLAKE2b-256 checksum
How to use checksums
2f7dbc821a46640122ce12fd92cc79c9d5f51f86b80267f348237116850a1b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / requests_credssp-2.1.0-py3-none-any.whl

Download URL requests_credssp-2.1.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d373e5b57e6dfd9e8669dd3249f3069619fa630270c16070136164decae08de1
BLAKE2b-256 checksum
How to use checksums
5b648ede573549456d7999183ebd158d5c2409719ce76aaab0220f88900f283f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for requests-credssp 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for requests_credssp-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page