Skip to content

fix(azuresastoken): match SAS tokens regardless of parameter order#5043

Open
genisis0x wants to merge 1 commit into
trufflesecurity:mainfrom
genisis0x:fix-azuresastoken-order-independent
Open

fix(azuresastoken): match SAS tokens regardless of parameter order#5043
genisis0x wants to merge 1 commit into
trufflesecurity:mainfrom
genisis0x:fix-azuresastoken-order-independent

Conversation

@genisis0x

@genisis0x genisis0x commented Jun 16, 2026

Copy link
Copy Markdown

Description:

The azuresastoken detector only matched SAS tokens whose query parameters appeared in one fixed order (sp, st, se, [sip], [spr], sv, sr, sig) and whose timestamps used a literal :.

Real SAS tokens vary. Azure Storage Explorer, for example, emits the parameters in a different order (sv first, sp last) and URL-encodes the : in st/se as %3A:

https://accountname.blob.core.windows.net/sorted?sv=2023-01-03&st=2025-06-18T08%3A45%3A11Z&se=2025-06-19T08%3A45%3A11Z&sr=c&sp=r&sig=ow2a1XbXmD4%2BEv9LBUkek8R%2FrAjvrQFpenUbzztILn8%3D

Tokens like this were silently missed.

Instead of encoding one parameter order in a single regex, the detector now matches a contiguous run of query parameters and validates the SAS-specific parameters (sp, sv, sr, sig, and at least one of st/se, plus an optional sip) in code. This makes detection order-independent and tolerant of URL-encoded values, while preserving the validations the previous regex enforced (permission set, resource type, timestamp shape, and IP format) so the existing false-positive cases still produce no result.

Closes #4732

Tests:

  • Added a case for the Storage-Explorer token above (alternate order + URL-encoded timestamps).
  • Added a non-SAS query string case to confirm it is ignored.
  • All existing positive and negative TestAzureSASToken_Pattern cases still pass.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint)?

Note

Low Risk
Scoped to secret-detection heuristics in one detector; verification behavior is unchanged and existing negative tests are preserved.

Overview
The Azure SAS token detector no longer depends on query parameters appearing in a fixed order or on literal : in timestamps. It now finds contiguous key=value&… runs with a looser regex and confirms SAS shape in keyMatchIsSASToken (sp, sv, sr, sig, at least one of st/se, optional sip), including URL-encoded time and signature values.

This closes gaps for tokens from tools like Azure Storage Explorer (e.g. sv first, %3A in times) while keeping the same field-level checks the old regex enforced. Tests add a Storage-Explorer-style positive case and assert generic blob API query strings (e.g. comp=list) are not treated as SAS.

Reviewed by Cursor Bugbot for commit a245faa. Bugbot is set up for automated code reviews on this repo. Configure here.

The keyPat regex required a fixed parameter order
(sp, st, se, [sip], [spr], sv, sr, sig) and literal ':' in the timestamps.
Real SAS tokens vary: Azure Storage Explorer emits the parameters in a
different order (sv first, sp last) and URL-encodes the ':' in st/se as
%3A, so those tokens were silently missed.

Match a contiguous run of query parameters and validate the SAS-specific
parameters (sp, sv, sr, sig, and st/se, plus optional sip) in code instead.
This makes detection order-independent and tolerant of URL-encoded values
while preserving the previous validations (permission set, resource type,
timestamp shape, IP format) so the existing false-positive cases still
return no result.

Adds test cases for the alternate-order / URL-encoded-timestamp token and
for a non-SAS query string.

Closes trufflesecurity#4732
@genisis0x genisis0x requested a review from a team June 16, 2026 08:00
@genisis0x genisis0x requested a review from a team as a code owner June 16, 2026 08:00
@CLAassistant

CLAassistant commented Jun 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit a245faa. Configure here.

spValuePat = regexp.MustCompile(`^[racwdli]+$`)
svValuePat = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`)
srValuePat = regexp.MustCompile(`^[bcfso]$`)
timeValuePat = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}(?::|%3A)\d{2}(?::|%3A)\d{2}Z$`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

timeValuePat rejects valid lowercase percent-encoded timestamps

Low Severity

The timeValuePat regex only matches uppercase %3A for URL-encoded colons in timestamps, but per RFC 3986, %3a (lowercase hex) is an equally valid encoding. A SAS token with st=2025-06-18T08%3a45%3a11Z (lowercase hex digits) would fail validation and be silently missed, despite being a legitimate URL-encoded timestamp. The PR claims tolerance of URL-encoded values, but this pattern is case-sensitive on the hex digits.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a245faa. Configure here.

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.

Azure sas storage tokens not detected

2 participants