Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion descope/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
DEFAULT_BASE_URL = DEFAULT_URL_PREFIX + "." + DEFAULT_DOMAIN # pragma: no cover
DEFAULT_TIMEOUT_SECONDS = 60

PHONE_REGEX = r"""^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\/]?){0,})(?:[\-\.\ \\/]?(?:#|ext\.?|extension|x)[\-\.\ \\/]?(\d+))?$"""
# Simple phone validation to prevent ReDoS (catastrophic backtracking)
# Optional leading +, then digits, spaces, hyphens, parentheses, dots, # for extension
# Requires at least 4 consecutive digits, length 7-25, at most one leading +
PHONE_REGEX = r"""^(?=.*\d{4,})\+?[\d\s\-\(\)\.#xX]{6,24}$"""
Copy link
Member

Choose a reason for hiding this comment

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

@omercnet can't this break compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's more relaxed regex but still works, tests validate it


SESSION_COOKIE_NAME = "DS"
REFRESH_SESSION_COOKIE_NAME = "DSR"
Expand Down
12 changes: 12 additions & 0 deletions descope/descope_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import warnings
from typing import Iterable

import requests
Expand Down Expand Up @@ -50,6 +51,17 @@
),
)

# Warn about TLS verification bypass
if skip_verify:
warnings.warn(

Check warning on line 56 in descope/descope_client.py

View workflow job for this annotation

GitHub Actions / Coverage

This line has no coverage
"⚠️ SECURITY WARNING: TLS certificate verification is DISABLED (skip_verify=True). "
"This makes your application vulnerable to man-in-the-middle attacks. "
"ONLY use this for local development with self-signed certificates. "
"NEVER use skip_verify=True in production environments.",
category=UserWarning,
stacklevel=2,
)

# Auth Initialization
auth_http_client = HTTPClient(
project_id=project_id,
Expand Down
2 changes: 1 addition & 1 deletion descope/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_cookie_on_response(response: Response, token: dict, cookie_data: dict):
expires=cookie_data.get("exp", expire_time),
path=cookie_data.get("path", "/"),
domain=cookie_domain,
secure=False, # True
secure=True, # Cookies must be sent over HTTPS only
Copy link
Member

Choose a reason for hiding this comment

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

@omercnet can't this break compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe only for local development, not prod

httponly=True,
samesite="Strict", # "Strict", "Lax", "None"
)
Expand Down
12 changes: 12 additions & 0 deletions descope/jwt_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import Callable, Iterable, Optional

import jwt
Expand Down Expand Up @@ -71,9 +72,20 @@ def decode_token_unverified(
) -> dict:
"""Decode a JWT without verifying signature (used when no validator is provided).

WARNING: This function does NOT verify JWT signatures and should NEVER be used
for authentication or authorization decisions. It is only intended for testing
or scenarios where token validation happens elsewhere.

Audience verification is disabled by default since no key is provided.
Returns an empty dict if decoding fails.
"""
warnings.warn(
"decode_token_unverified() does not verify JWT signatures. "
"Do not use this for authentication or authorization. "
"Use proper token validation with signature verification instead.",
UserWarning,
stacklevel=2,
)
try:
return jwt.decode(
token, options={"verify_signature": False, "verify_aud": False}
Expand Down
4 changes: 3 additions & 1 deletion samples/otp_web_sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

PROJECT_ID = ""

# init the DescopeClient
# SECURITY WARNING: skip_verify=True disables TLS certificate verification
# ONLY use this for local development with self-signed certificates
# NEVER use skip_verify=True in production - remove this parameter for production
descope_client = DescopeClient(PROJECT_ID, skip_verify=True)


Expand Down
4 changes: 3 additions & 1 deletion samples/password_web_sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

PROJECT_ID = ""

# init the DescopeClient
# SECURITY WARNING: skip_verify=True disables TLS certificate verification
# ONLY use this for local development with self-signed certificates
# NEVER use skip_verify=True in production - remove this parameter for production
descope_client = DescopeClient(PROJECT_ID, skip_verify=True)


Expand Down
5 changes: 4 additions & 1 deletion tests/test_jwt_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import warnings

from descope.jwt_common import (
COOKIE_DATA_NAME,
Expand Down Expand Up @@ -58,7 +59,9 @@ def validator(token: str, audience=None):

def test_decode_token_unverified_handles_garbage(self):
# Invalid token strings should not raise and should return empty dict
assert decode_token_unverified("not-a-jwt") == {}
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
assert decode_token_unverified("not-a-jwt") == {}


if __name__ == "__main__":
Expand Down
Loading