SShortSingh.
Back to feed

Base64URL drops the '=' padding: how to strip and restore it without breaking tokens

0
·7 views

Tokens encoded in standard Base64 often fail when placed in URLs, because '+' turns into a space, '/' can break routing, and '=' gets percent-encoded. Base64URL solves this by swapping '+' and '/' for '-' and '_', as defined in RFC 4648. Omitting the trailing '=' is allowed when the data length is known, and JWT (RFC 7515) requires it. The padding can be restored by computing the remainder of the length divided by 4, adding two or one '=' accordingly, while a remainder of 1 signals a truncated or corrupted string. The article illustrates this with Python and Node.js examples that handle padding correctly.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Blockchain bootcamp chapter 3: running a local node with Ganache

This chapter of a blockchain bootcamp series shows developers how to run a local blockchain node for free, disposable testing. It follows Emma, a front-end engineer tasked with building a block-viewing widget, who struggles with dense documentation and a slow testnet setup. The lesson recommends Ganache, a development tool for Ethereum and similar platforms, and requires Node.js 16 or higher. Readers install Ganache via npm and start a node that provisions pre-funded test accounts. The chapter then moves on to building a short script that connects to the node using the Web3.js library.

0
ProgrammingDEV Community ·

Why Sidebar Icons Look Uneven Even at Identical Sizes

Setting every sidebar icon to the same 24 × 24 dimensions does not ensure they look visually consistent. Icons can differ in internal padding, silhouette shape, and detail density, so some appear heavier or smaller than others. Stroke thickness, corner style, and fill approach also affect how balanced the icons feel side by side. The article recommends auditing the artwork itself before adding CSS overrides, and choosing a single icon family that covers all required navigation concepts. It also offers a sample sidebar component using flex sizing and currentColor to keep icons predictable.

0
ProgrammingDEV Community ·

Managing LLM API Rate Limits: Handling TPM, RPM, Retries and Fallbacks

A DEV Community piece highlights the importance of rate limits when an application works with multiple LLM APIs. It explains that limits on tokens per minute (TPM) and requests per minute (RPM) must be tracked carefully. The article points to retry logic and fallback models as key tools for avoiding failed requests. Properly handling these factors, it argues, helps applications keep running smoothly.

0
ProgrammingDEV Community ·

MCP server publishes failing scores on a public lost-response retry contract

A developer team scored its own MCP server against a public test contract for handling lost responses after mutating tool calls. The contract addresses MCP issue #3394, which reports that retrying a mutating call can re-execute external effects. The scoring was published before the run, and each assertion is graded separately as pass, fail, or unproven, with no aggregate score. The team's own baselines show failures, including a production run that produced two effects for one logical operation and a mismatched-parameter retry that executed as a normal new call. The contract is a draft under joint review with an external collaborator and is designed for independent reproduction by anyone.