Skip to content

Comments

refactor: Make signed request the final transformation#556

Merged
mergify[bot] merged 4 commits intomasterfrom
paulliu/auth-transform
Apr 11, 2020
Merged

refactor: Make signed request the final transformation#556
mergify[bot] merged 4 commits intomasterfrom
paulliu/auth-transform

Conversation

@ninegua
Copy link
Member

@ninegua ninegua commented Apr 10, 2020

Upgrading to replica v0.5.4 broke userlib/js (#552), partly because content field was made explicit in http_handler. This PR fixes this problem by introducing HttpAgentRequest -> SignedHttpAgentRequest as the last step of transform pipeline. I think this makes sense because we don't want to accidentally modify the content after signing.

I'm putting it out as a draft to seek opinions. Manually testing hello canister from browser seems to work fine. But I've no idea why previous e2e test didn't catch the breakage introduced in #552.

@chenyan-dfinity
Copy link
Contributor

In the hello canister, after entering the name, you should get back the alert window again with the name. I don't see the second alert window, and replica shows the following error:

Apr 10 00:51:03.621 INFO Failed to authenticate request 0x0bba898cc27a8845064f268ad2ccac4143e3494bdcff871ea6ae39a2bdadd4fa, Application: Http Handler

@ninegua
Copy link
Member Author

ninegua commented Apr 10, 2020

It works for me now. However I'm getting the following errors in (firefox) JS console, despite that the dialog box popping up correctly showing the name I typed.

JavaScript warning: http://127.0.0.1:8080/index.js, line 2: TypeError: asm.js type error: expecting argument type declaration for 't' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
JavaScript error: http://127.0.0.1:8080/index.js, line 2: Error: Invalid text argument: "null"
JavaScript warning: http://127.0.0.1:8080/index.js, line 2: TypeError: asm.js type error: expecting argument type declaration for 't' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
JavaScript warning: http://127.0.0.1:8080/index.js, line 2: TypeError: asm.js type error: expecting argument type declaration for 't' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
JavaScript error: http://127.0.0.1:8080/index.js, line 2: Error: Invalid text argument: "null"

Is this something that I should be concerned with?

@ninegua ninegua marked this pull request as ready for review April 10, 2020 03:49
@ninegua ninegua requested a review from a team as a code owner April 10, 2020 03:49
Copy link
Contributor

@chenyan-dfinity chenyan-dfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! I tried a bunch of canisters, they all work well! The asm.js warning is always there, I don't know where they come from.

@hansl
Copy link
Contributor

hansl commented Apr 10, 2020

They come from TweetNACL which has some unformed ASM.js.

There was a discussion when the pipeline was implemented to have the auth like you said. I made the case here for keeping the pipeline as is: #273 (review)

Long story short; it's better to leave the constructor of http_agent be flexible, and there are plenty of cases where we want transforms AFTER the signature. E.g. logging or breakpoint or splitting the request to a different backend, ....

So I would keep the pipeline as a list of steps and auth being one of them. There could be a warning that having auth not be the last step is risky (I think there's already a comment).

const {body, ...fields } = r;
const requestId = await requestIdOf(body);
return { ...fields,
body: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing. Not sure why prettier didn't catch this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which prettier was used? I'd like to set it up in my editor too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, found npx prettier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to run on CI too and fail if you didn't run it. Dunno why it didn't run :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line npx prettier --check src/**/*.ts bootstrap/**/*.ts in package.json is wrong:

[nix-shell:~/dfinity/sdk/src/userlib/js]$ ls src/**/*ts
src/candid/candid-core.d.ts  src/candid/candid-ui.d.ts  src/utils/hash.d.ts       src/utils/hash.test.ts  src/utils/leb128.d.ts       src/utils/leb128.test.ts
src/candid/candid-core.ts    src/candid/candid-ui.ts    src/utils/hash.test.d.ts  src/utils/hash.ts       src/utils/leb128.test.d.ts  src/utils/leb128.ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the problem is that shopt -s globstar has to be enabled before we use **

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I will fix it in #558

@ninegua
Copy link
Member Author

ninegua commented Apr 10, 2020

So I would keep the pipeline as a list of steps and auth being one of them.

I tried to keep it that way but due to the changes in data type, namely pubkey/signature now have to exist at an outer level, I couldn't find a clean approach to allow HttpAgentRequestTransformFn process both signed and unsigned requests. You are welcome to give it a try.

@ninegua
Copy link
Member Author

ninegua commented Apr 10, 2020

there are plenty of cases where we want transforms AFTER the signature

If we keep things typed as signed vs. unsigned, then there are three stages:

1. HttpAgentRequest -> HttpAgentRequest
2. HttpAgentRequest -> SignedHttpAgentRequest
3. SignedHttpAgentRequest -> SignedHttpAgentRequest

We can use function composition to connect the pipeline, instead of setting priorities.

@hansl
Copy link
Contributor

hansl commented Apr 10, 2020

Yeah I think we should use a function composition. I can take care of it later. LGTM for now.

@mergify mergify bot merged commit 5b0b82a into master Apr 11, 2020
@lwshang lwshang deleted the paulliu/auth-transform branch July 29, 2022 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants