github.com

age is a simple, modern and secure file encryption tool, format, and Go library. It features small explicit keys, no...

Rails has the handy controller method send_file which lets us download files easily. We can decide whether the file...

It is generally discouraged to load your JavaScript by a tag in the : The reason is that a tag will pause the DOM parser until the script has loaded and executed. This will delay the browser's first contentful paint. A much better default is to load your scripts with a tag: A deferred script has many...

This bookmarklet grabs a PivotalTracker story title, transforms it into a valid git branch name and automatically prepends your initials...

The attached compiler() function below applies JavaScript behavior to matching HTML elements as they enter the DOM. This works like...

Given you have a strict CSP that only allows elements from your own domain: Content-Security-Policy: script-src 'self' This will block JavaScript handlers inlined as attribute into your HTML elements. Clicking on the following link will only log an error with a strict CSP: click me click me Solution 1: Move the handler into your JavaScript The recommended solution is to move the handler from the HTML to the allowed JavaScript file that we loaded via . In the example above we could invent a new [data-alert] attribute with the alert message: click me Then our JavaScript intercepts clicks on elements with that attribute: document.addEventListener('click', function(event) { let link = event.target.closest('[data-alert]') if (link) { let message = link.dataset.alert alert(message) event.preventDefault() } }) Solution 2: Allow that one handler in your CSP Some browsers allow the CSP directive script-src-attr. This lets you allow the hashes of actual JavaScript code. The SHA256 hash of alert('hello') is vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE= (in Base64). We can allow this one event handlers like this: Content-Security-Policy: script-src 'self'; script-src-attr 'unsafe-hashes' 'sha256-vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE=' Note the sha256- prefix. This event handler now works when clicked: click me But any other script will still be blocked: click me Dealing with legacy browsers Currently (November 2023) about 75% of browsers support script-src-attr. Here is a forward-looking compromise that many users use with new CSP features: Have a liberal CSP with old directives supported by all browsers Make your CSP stricter with new, more specific directives for browsers that support it The CSP spec supports that approach in that using newer, more specific directives disable older, more general features. In our case this means: For old browsers, allow all inline scripts For new browsers, disallow inline scripts but allow inline handlers with given hashes Here is a CSP directive that works like this: Content-Security-Policy: script-src 'self' 'unsafe-inline'; script-src-elem 'self'; script-src-attr 'unsafe-hashes' 'sha256-vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE=' Old browsers will only use script-src. New browsers will use script-src-elem (for tags) and script-src-attr (for inline event handlers), which override the more liberal rules from script-src.

Often people need links which are not linked directly, but should trigger execution of JavaScript. ❌ Bad workarounds

maulwuff.de

The linked article provides a description of commonly found problems with TLS and hints on debugging / solving them.

tl;dr: Avoid to memoize methods with default (keyword) arguments! When you are using Memoized with default arguments or default...

makandra dev

The need for clearfix hacks has been greatly reduced since we could layout with Flexbox or CSS Grid.

We had a card that described how to install multiple mysql versions using mysql-sandbox. Nowadays with the wide adoption...

The rubygems binary gem allows to extract a local gem with gem unpack GEMNAME. For more details see the official...

Our gem spreewald supports a few helpers for development. In case you notice errors in your Cucumber tests, you might...

You can scale background images in CSS to the container size using background-size (Demo). Commonly, we use contain or...

When using custom properties in your stylesheets, you may want to set a specific property value to an existing variable...

It seems like changing the HTTP_ACCEPT_LANGUAGE is not possible for a headless chrome. On Ubuntu the headless Chrome...

You can throttle the network in your headless chrome via Selenium. This might be useful for debugging issues with flaky...

I ran into a situation in which I received the yarn integrity check warning when starting the rails console even...

en.wikipedia.org

Formerly 301 (Moved Permanently) and 302 (Found) were used for redirecting. Browsers did implement them in different ways, so since...

When using RestClient to make an HTTP request, it will raise an exception when receiving a non-successful response.

makandra dev
poinz.herokuapp.com

If you are using scrum in a project you might be familiar with planning poker, a playful way to agree...

To start a workflow manually it must have a trigger called workflow_dispatch: --- name: Tests on: push: branches: - master

If you have a flaky command you can use the nick-invision/retry to re-try a failing command, optionally...

After switching a project from Sprockets to Webpack, I started observing a bug that was hard to debug: Our...