Urgent.News

What's breaking now, across thousands of outlets.

Tech

Defining Multiple Security Schemes and When a Client Sends the Wrong One

Quick answer When an API defines more than one security scheme, the client has to choose correctly, and a wrong choice fails in confusing ways. A service that accepts a bearer token on user endpoints but requires an API key or mutual TLS on partner and admin operations is genuinely safer, but if the contract does not make the scheme per operation explicit, a generic client sends the wrong…

When a single API supports multiple security schemes, the client must select the appropriate one, or it can encounter confusing issues. For example, a service might require a JWT for user-facing operations, an API key for partner webhooks, and a client certificate for admin tasks. If the contract does not clearly define which scheme is needed for each operation, generic clients often send the wrong credential, resulting in a 401 error that can be misleading.

The problem arises because the server typically returns a generic 401 or 403, making it unclear whether the issue is a missing or malformed credential or a simple wrong type. The client, seeing only an authentication failure, may rotate credentials without realizing the root cause is that the wrong scheme was sent.

To avoid these issues, it's best to declare the security schemes explicitly at the operation level rather than using a global default. This allows clients to read the contract and know exactly which credential to present for each operation. If an endpoint supports multiple schemes, list them as separate alternatives in the security array, clearly indicating that only one is required.

Hard-coding the Authorization header per request is not recommended, as it bypasses the contract and increases the likelihood of sending the wrong scheme. Instead, configure the generated client with a credential provider for each scheme. This ensures the correct credential is attached automatically based on the operation's security requirement, keeps secrets out of individual call sites, and makes adding new schemes as simple as a configuration change.

To verify that the correct scheme is being used, you can add tests that call each operation with a mock and check that the outgoing request contains the expected credential type and placement. Include negative tests that send the wrong scheme to confirm the 401 error is surfaced with enough context to identify the scheme mismatch. For mTLS routes, verify that the certificate is actually presented during the handshake.

In summary, when a client sends the wrong security scheme, it's almost always because the contract does not explicitly declare the required scheme for each operation. By declaring the schemes once in the components, attaching the exact requirement to each operation, and using the generated client to select credentials, you can avoid this common pitfall and ensure your API is secure and easy to use.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

PHP2Shell, What Was That About?

Recently, about two weeks ago on 21 October 2026, there were two vulnerabilities announcement which shook most of the internet, caused permanent EoS (End of Services) at web based games like World…

  • Two critical PHP vulnerabilities emerged on 21 October 2026
  • Attackers could access web shell via remote code execution
  • Servers urged to upgrade PHP to 8.5.12 or apply patches

HLS vs progressive MP4: what a video downloader actually hands you

When I started building the downloader on ramrom.io, I assumed every video on the internet was an MP4. A URL points at a file, you fetch the bytes, you hand them to the visitor. Simple.

  • Progressive MP4s are single files with clear sizes and headers
  • HLS streams are playlists of segments with no single file size
  • HLS requires either stitching (resource-intensive) or delegation (browser/app handling)

Why does CrUX say no data for my client site?

PageSpeed Insights finishes the Lighthouse half of the report and then leaves the “real users” block empty. The client Slack thread fills with “is CrUX broken?” and someone refreshes the same URL…

  • Chrome UX Report shows no field data for specific site
  • Eligibility issues, not API failure, cause missing data
  • CrUX publishes anonymized data when privacy, quality rules met

More from Tuesday 3 November →