https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • n

    Nicolaas

    03/03/2023, 1:17 PM
    Also just to clarify. We are hosting our api's on AWS. So the typical flow would be: Make request via CF domain -> Resolves to our Cloudfront CDN -> Trigger API on server. What we want to prevent is that an attacker could some how get ahold of our Cloudfront URL and bypass cloudflare. So we need a way to protect the API's for requests coming directly from the Cloudfront URL.
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:21 PM
    Hey all -- getting this error when trying to convert a arrayBuffer of the Response from downloading an image to Uint8Array
    Copy code
    ts
    const hexBuffer = await r.arrayBuffer()    
    let bytes = new Uint8Array(hexBuffer as ArrayBuffer)
    recursive use of an object detected which would lead to unsafe aliasing in rust
    looks like a worker runtime thing. note that only one image is doing this. image is downloaded fine
  • k

    kian

    03/03/2023, 1:30 PM
    I don't see it thrown from the runtime - that looks like it's thrown by wasm-bindgen
  • k

    kian

    03/03/2023, 1:31 PM
    Unless it's just thrown by V8 itself, which would be odd
  • k

    kian

    03/03/2023, 1:34 PM
  • k

    kian

    03/03/2023, 1:34 PM
    Yeah, that's wasm-bindgen
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:37 PM
    during wasm warm up or executing a method from the binding?
  • k

    kian

    03/03/2023, 1:37 PM
    wasm-bindgen isn't something that is included in workerd
  • k

    kian

    03/03/2023, 1:38 PM
    Are you using WASM in your Worker?
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:39 PM
    we do this but not seeing specific error because
    (warn) Trace resource limit exceeded; subsequent logs not recorded.
    Copy code
    ts
     await initialize(wasm).catch((e: Error) => {
        //We don't log the expected error
        if (!e.message.startsWith('Already initialized.')) console.error(e)
      })
      const ogImage = await svg2png(svg)
  • k

    kian

    03/03/2023, 1:47 PM
    Is the image that fails larger than the rest?
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:47 PM
    smaller acutally
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:47 PM
    so naied it down to
    svg2png
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:52 PM
    nvm
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:52 PM
    sometimes initialize thows that recursive exception
  • k

    kian

    03/03/2023, 1:53 PM
    I'd have a global variable of
    initialized
    and only init inside an if check
  • k

    kian

    03/03/2023, 1:54 PM
    Copy code
    ts
    import esbuild from "esbuild-wasm";
    import wasm from "../node_modules/esbuild-wasm/esbuild.wasm";
    
    let initialised = false;
    globalThis.performance = Date;
    
    export default {
        async fetch(): Promise<Response> {
            if (!initialised) {
                await esbuild.initialize({
                    wasmModule: wasm,
                    worker: false,
                });
                initialised = true;
            }
            return new Response("Hello World");
        },
    };
    Example from
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 1:59 PM
    this helped stablize things
  • k

    Kavatch

    03/03/2023, 2:00 PM
    It sounds like what you want is something along the lines of this here: https://developers.cloudflare.com/ssl/origin-configuration/origin-ca/#4-required-for-some-add-cloudflare-origin-ca-root-certificates With that you can edit the configuration on your server to validate the certificate from cloudflare before accepting the request and thus preventing anyone from sending request not though cloudflare. For example in Nginx you would add something like this to the server configuration:
    Copy code
    ssl_client_certificate /etc/ssl/certs/cloudflare-origin.pem;
    ssl_verify_client on;
    About all of this there is also this excellent blog post: https://blog.jfx.ac/securing-nginx-origin-with-cloudflare.html
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 2:03 PM
    some progress made.
    Copy code
    ts
    let ogImage = null
      try {
        if (!initialized) {
          await initialize(wasm).catch((e: Error) => {
            //We don't log the expected error
            console.debug("Couldn't initialize wasm", e)
            if (!e.message.startsWith('Already initialized.')) console.error(e)
          })
        }
        console.debug('initialized wasm')
        initialized = true
        ogImage = await svg2png(svg)
      } catch (e) {
        console.error('Failed to convert svg to png')
        console.error(e)
        return ''
      }
    in some instances however now we are getting
    ✘ [ERROR]   Error: Promise will never complete.
  • k

    kian

    03/03/2023, 2:05 PM
    Bleh, might not work with svg2png then.
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 2:05 PM
    works sometimes tho 😦
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 2:09 PM
    cf images doesn't do svg to png iirc?
  • d

    dale

    03/03/2023, 2:19 PM
    I experience some problems with cron triggers. The worker is unable to make a request to a non standard http port to a external service on the same domain (no-proxy DNS). Getting 404 if the worker is triggered with a cron event. It do work though if I trigger the same worker with a fetch request instead.
  • d

    dale

    03/03/2023, 2:19 PM
    I then created a port proxy worker that proxies between the non standard http port and 443 in the same zone. As a result the reverse is true: the cron trigger works but not the worker triggered by an fetch event! I assume the fetch worker can't communicate with the port proxy directly because it's in the same zone. But it seems the cron triggered worker i able.
  • d

    dale

    03/03/2023, 2:26 PM
    So it seems like the cron triggered worker is running in another zone
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 3:08 PM
    trying something new. so, workerd won't support something like this?
    Copy code
    ts
    return WebAssembly.instantiate(
        wasmModule,
        imports
      )
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 3:10 PM
    (this works in wrangler2 but not deployed)
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 3:11 PM
    [object WebAssembly.Instance] { memory: {} }
    (error) RuntimeError: unreachable
  • a

    Adrian (Launchpad Cohort)

    03/03/2023, 3:22 PM
    in other words, exports attached to mem locally but not on CF 😦
1...231623172318...2509Latest