Skip to content

--policy-integrity - #28734

Closed
bmeck wants to merge 19 commits into
nodejs:masterfrom
bmeck:policy-integrity
Closed

bmeck wants to merge 19 commits into
nodejs:masterfrom
bmeck:policy-integrity

Conversation

@bmeck

@bmeck bmeck commented Jul 17, 2019

Copy link
Copy Markdown
Member

This allows mitigating if a policy file is changed on disk and prevents node from running with the modified file. An attacker would need to modify the command that runs node in order to escape this mitigation.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@bmeck bmeck added security Issues and PRs related to security. experimental Issues and PRs related to experimental features. labels Jul 17, 2019
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jul 17, 2019
@vsemozhetbyt

This comment has been minimized.

@bmeck

ghost commented Jul 17, 2019

Copy link
Copy Markdown
Member Author

@vsemozhetbyt can do

Bradley Meck and others added 2 commits July 17, 2019 12:18
Comment thread doc/api/cli.md Resolved
Comment thread doc/api/cli.md Outdated
are used to provide a kind of selective "early warning" mechanism that
developers may leverage to detect deprecated API usage.

### `--policy-integrity`

ghost Jul 17, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be --policy-integrity=checksum with some explanation about the expected format of the argument (checksum or a more appropriate word if the argument isn't actually a checksum).

ghost Jul 17, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

well it is an SRI string so we could link to that somewhere but the SRI spec is kind of not great for explaining that, would linking to mdn be fine?

ghost Jul 17, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think linking to mdn should be ok. (and rename my suggested parameter name to sri instead of checksum).

Comment thread doc/node.1 Resolved
Comment thread doc/api/cli.md Resolved
Comment thread doc/node.1 Resolved
Bradley Meck and others added 5 commits July 17, 2019 12:36
Co-Authored-By: Richard Lau <riclau@uk.ibm.com>
Co-Authored-By: mscdex <mscdex@users.noreply.github.com>
Co-Authored-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Co-Authored-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Comment thread doc/node.1 Resolved
Comment thread doc/api/cli.md Resolved
Comment thread doc/api/cli.md Outdated
[experimental ECMAScript Module]: esm.html#esm_resolve_hook
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
[Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity No newline at end of file

This comment was marked as resolved.

ghost Jul 17, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

these don't seem to be in alphabetical order though?

ghost Jul 17, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bottom references are usually sorted in ASCII order, case and punctuation are taken into account.

Comment thread doc/node.1 Outdated
Emit pending deprecation warnings.
.
.It Fl -policy-integrity=sri
Instructs Node.js to error prior to running any code if the policy does not have the specified integrity. It expects a [Subresource Integrity] string as a parameter.

This comment was marked as resolved.

Bradley Meck and others added 3 commits July 17, 2019 13:00
Co-Authored-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Co-Authored-By: Richard Lau <riclau@uk.ibm.com>
@Trott

ghost commented Jul 19, 2019

Copy link
Copy Markdown
Member

Should the flag be explicitly labeled Experimental stability the way (for example) --frozen-intrinsics and others are in cli.md?

@Trott

ghost commented Jul 19, 2019 •

Copy link
Copy Markdown
Member

@bmeck Actually, I wonder if this is showing a potential problem for cross-platform teams using these policy files anyway. Maybe the thing to do is calculate the hash excluding the \r\n converting \r\n to \n first for a cross-platform hash value?

(All this is me assuming the hash value is the problem to begin with and not something else. Feel free to hide my comments if I'm making the wrong assumption.)

@guybedford

ghost commented Jul 19, 2019

Copy link
Copy Markdown
Contributor

Surely the same problem would apply to all files managed by the policy? Such that some time of sanitization in the integrity process might make sense? Eg to define that the integrity in the policy is the integrity of the source with any \r\n characters replaced with \n.

@guybedford

ghost commented Jul 19, 2019

Copy link
Copy Markdown
Contributor

(ah sorry @Trott you beat me to it!)

@bmeck

ghost commented Jul 19, 2019

Copy link
Copy Markdown
Member Author

@Trott

Perhaps the thing to do is to have a separate Windows policy with the hash calculated to take into account the Windows \r\n line endings. Then check common.isWindows and use the appropriate file.

People can generate multiple values and place them into the policy file since SRI allows you to have multiple integrity values. We could do that for these tests or we could swap the policy file we use. I think having the same policy with the multiple integrity values makes more sense.

Actually, I wonder if this is showing a potential problem for cross-platform teams using these policy files anyway. Maybe the thing to do is calculate the hash excluding the \r\n converting \r\n to \n first for a cross-platform hash value?

Anytime someone changes value in a file this is true. If someone converted \t to spaces it is similar in my mind. You shouldn't be changing the file contents if you want them to be the same contents. I don't think \r\n munging is going to break JS but it could change some things that are visible by fs inspection. Cross platform teams can solve this one of 2 ways above if they don't want to enforce stable file contents.

@guybedford

Surely the same problem would apply to all files managed by the policy? Such that some time of sanitization in the integrity process might make sense? Eg to define that the integrity in the policy is the integrity of the source with any \r\n characters replaced with \n.

We don't want to do that to binary files and I'm not keen on even doing this to CJS/JSON. Just add the expected alternative integrity to your policy file. Lack of magic is ideal here. A system altering line endings could have some unknown affect and should be added to the policy as a valid integrity for a resource.

@Trott

ghost commented Jul 19, 2019

Copy link
Copy Markdown
Member

People can generate multiple values and place them into the policy file

@bmeck Ah, yes, that sounds ideal.

@nodejs-github-bot

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Collaborator

@Trott

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Member

Tests now pass on Windows Just a few insignificant JS linting things to tidy in the test and then I think we're good....

@Trott

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Member

Took the liberty of doing the ESLint fixes myself and pushing to the branch. Will run CI again.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Collaborator

@Trott

ghost commented Jul 20, 2019

Copy link
Copy Markdown
Member

Landed in 6c288a7

@Trott Trott closed this Jul 20, 2019
@targos targos added the semver-minor PRs that contain new features and should be released in the next minor version. label Jul 23, 2019
This was referenced Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. experimental Issues and PRs related to experimental features. security Issues and PRs related to security. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants