Skip to content

Commit

Permalink
[DEV-1234] Updated lambda checks to prevent .woff2 font requests from…
Browse files Browse the repository at this point in the history
… being modified (#559)
  • Loading branch information
jeremygordillo authored Jan 11, 2024
1 parent 59fe6b0 commit 328df36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eighty-toys-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cloudfront-functions": patch
---

Handle woff2 font request
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('handler', () => {
expect(handler(makeEvent('/page')).uri).toBe('/page.html');
expect(handler(makeEvent('/page/')).uri).toBe('/page/');
expect(handler(makeEvent('/image.jpg')).uri).toBe('/image.jpg');
expect(handler(makeEvent('/font.woff2')).uri).toBe('/font.woff2');
const example0 = '/i-s/g/mo/v1.0/i-p/p-i/v-d';
expect(handler(makeEvent(example0)).uri).toBe(`${example0}.html`);
const example1 = '/i-s/g/mo/v1.0';
Expand Down
8 changes: 7 additions & 1 deletion apps/cloudfront-functions/src/viewer-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ const handler = (

// Check if the uri refers to a gitbook assets
const isGitbookAssets = uri.startsWith('/gitbook/docs');
const isWoff2 = uri.endsWith('.woff2'); // woff2 is a font format

// Add the .html extension if missing
if (!uri.endsWith('/') && !isGitbookAssets && !/\.[a-zA-Z]+$/.test(uri)) {
if (
!uri.endsWith('/') &&
!isGitbookAssets &&
!isWoff2 &&
!/\.[a-zA-Z]+$/.test(uri)
) {
request.uri += '.html';
}

Expand Down

0 comments on commit 328df36

Please sign in to comment.