
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@httpland/authorization-parser
Advanced tools
HTTP Authorization field parser and serializer.
Compliant with RFC 9110, 11.6.2. Authorization.
Parse string into Authorization.
import { parseAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/parse.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const result = parseAuthorization("Basic token68");
assertEquals(parseAuthorization("Basic token68"), {
authScheme: "Basic",
params: "token68",
});
assertEquals(
parseAuthorization(`Bearer realm="example", error="invalid_token"`),
{
authScheme: "Bearer",
params: {
realm: `"example"`,
error: `"invalid_token"`,
},
},
);
In the following cases, throws an error.
If field value has an invalid syntax, it may throw a SyntaxError.
The syntax follows Authorization ABNF.
import { parseAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/parse.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parseAuthorization("<invalid>"));
In case of semantic errors, throw an Error.
import { parseAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/parse.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() =>
parseAuthorization("scheme duplicate=value, Duplicate=value")
);
Serialize Authorization into string.
import { stringifyAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/stringify.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(
stringifyAuthorization({ authScheme: "Basic", params: "token68==" }),
"Basic token68",
);
assertEquals(
stringifyAuthorization({
authScheme: "Bearer",
params: { realm: `"Secure area"`, error: `"invalid_token"` },
}),
`Bearer realm="Secure area", error="invalid_token"`,
);
Throws an error in the following cases:
authScheme is invalid
auth-schemeparams is invalid
token68params key is invalid
tokenparams value is invalid
token or
quoted-stringparams keys(case-insensitive)import { stringifyAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/stringify.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() =>
stringifyAuthorization({ authScheme: "<invalid:auth-scheme>" })
);
assertThrows(() =>
stringifyAuthorization({ authScheme: "<valid>", params: "<invalid:token68>" })
);
assertThrows(() =>
stringifyAuthorization({
authScheme: "<valid>",
params: { "<invalid:token>": "<valid>" },
})
);
assertThrows(() =>
stringifyAuthorization({
authScheme: "<valid>",
params: { "<valid>": "<invalid:token|quoted-string>" },
})
);
assertThrows(() =>
stringifyAuthorization({
authScheme: "<valid>",
params: { "<duplicate>": "<valid>", "<DUPLICATE>": "<valid>" },
})
);
Authorization is following structure:
| Name | Type | Description |
|---|---|---|
| authScheme | string | Authentication scheme. |
| params | Token68 | AuthParams | null | token68 or auth-param. |
It is the same as string.
The token68 syntax allows the 66 unreserved URI characters, plus a few others, so that it can hold a base64, base64url (URL and filename safe alphabet), base32, or base16 (hex) encoding, with or without padding, but excluding whitespace.
It is name/value pairs.
interface AuthParams {
readonly [k: string]: string;
}
parser and serializer are compatible with RFC 9110, 11.3. Challenge and Response and RFC 9110, 11.4. Credentials syntax and can be used in the same way.
All APIs can be found in the deno doc.
Copyright © 2023-present httpland.
Released under the MIT license
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.