Skip to content

http: fix validation of "Link" header - #46466

Merged
nodejs-github-bot merged 6 commits into
nodejs:mainfrom
SRHerzog:main
Feb 23, 2023
Merged

http: fix validation of "Link" header#46466
nodejs-github-bot merged 6 commits into
nodejs:mainfrom
SRHerzog:main

Conversation

@SRHerzog

@SRHerzogSRHerzog commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

Updated regex for "Link" header validation to better match the
specification in RFC 8288 section 3. Does not check for valid URI
format but handles the rest of the header more permissively than
before. Alternative to another outstanding PR that disables validation
entirely.

Fixes: #46453
Refs: https://www.rfc-editor.org/rfc/rfc8288.html#section-3
Refs: #46464

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label Feb 1, 2023

@anonriganonrig left a comment

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.

I'm +1 on this. Can you fix the linting issue as well as your commit message?

@SRHerzog

Copy link
Copy Markdown
ContributorAuthor

I'm +1 on this. Can you fix the linting issue as well as your commit message?

I updated the commit message and changed the string from backticks to single quotes with escapes to pass linting. Thanks for the help!

@anonrig

Copy link
Copy Markdown
Member

Can you also add a test?

Comment threadlib/internal/validators.js Outdated
Comment threadlib/internal/validators.js Outdated
@anonriganonrig added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 2, 2023
@anonriganonrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 2, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 2, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadtest/parallel/test-http-early-hints-invalid-argument-value.js Outdated

@mcollinamcollina left a comment

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.

lgtm

@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 3, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 3, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadlib/internal/validators.js Outdated
Comment threadtest/parallel/test-http-early-hints.js Outdated

@jasnelljasnell left a comment

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.

LGTM with a nit about expanding the tests a bit more

Comment threadlib/internal/validators.js Outdated

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.

It probably does not matter as the header is sent by the server but this regex is vulnerable to ReDoS.

@lpincalpincaFeb 8, 2023

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.

FWIW the original is also vulnerable.

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.

I'm not questioning your point, I'm asking as I want to learn on this matter:

  1. How do you know?
  2. How can we fix it?

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.

  1. How do you know?

https://github.com/makenowjust-labs/recheck

  1. How can we fix it?

Usually it is possible to tweak the regex. I'm not sure if it is possible in this case. I did not spend time on it. The input is "trusted" so I think it does not worth the effort.

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.

Thanks for reference.

I also think it's not worth the effort. Shall we just insert a comment for future knowledge?

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.

The input is "trusted" so I think it does not worth the effort.

I'd be concerned that we'd start leveraging this at a future time for something and expose it to end users. There should at least be a comment, IMO.

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.

(To be 100% clear: If we're certain that this is not something that will accept user input, yeah, we don't need to fix it. But let's add a comment explaining.)

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 regex (and the existing one) will fail to do the right thing if a quotation mark is backslash-escaped inside the string, right? (I only skimmed the spec so I apologize if I'm wrong!) Are we doing the whole "using a regexp when a parsing algorithm is what is needed" thing? (This is a question, but not a blocking objection or anything. The current regexp would have the same issue if this one has that issue.)

@lpincalpincaFeb 18, 2023

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.

You could have a for loop that loops backward from the string examining each character. That might actually be more performant than a regex.

It could also start from the beginning of the string, but yes, I think that it would be better.

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.

We can add a TODO comment and do this in a follow-up PR.

Comment threadtest/parallel/test-http-early-hints.js Outdated
@mcollina

Copy link
Copy Markdown
Member

linting is failing

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollina

Copy link
Copy Markdown
Member

@nodejs/build could you take a look? This seems an odd failure: https://ci.nodejs.org/job/node-test-commit/59852/console

@richardlau

Copy link
Copy Markdown
Member

@nodejs/build could you take a look? This seems an odd failure: https://ci.nodejs.org/job/node-test-commit/59852/console

11:18:44 + git rev-parse origin/main11:18:44 + REBASE_ONTO=96c720e98f4ea80103a9d240ae8072190a22672911:18:44 + git rebase --committer-date-is-author-date 96c720e98f4ea80103a9d240ae8072190a22672911:18:45 Rebasing (1/6)Auto-merging lib/internal/validators.js11:18:45 CONFLICT (content): Merge conflict in lib/internal/validators.js11:18:45 error: could not apply 2e6e618a56b... http: fix validation of "Link" header

It has failed to rebase this PR onto main (96c720e at the time). Possibly fe514bf has changed the file enough to confuse git?

@mcollina

Copy link
Copy Markdown
Member

@SRHerzog could you review?

Updated regex for "Link" header validation to better match the
specification in RFC 8288 section 3. Does not check for valid URI
format but handles the rest of the header more permissively than
before. Alternative to another outstanding PR that disables validation
entirely.
Fixes: #46453
Refs: https://www.rfc-editor.org/rfc/rfc8288.html#section-3
Refs: #46464
@SRHerzog

Copy link
Copy Markdown
ContributorAuthor

There was a new comma in validators.js in main. Rebased successfully.

@mcollinamcollina left a comment

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.

lgtm

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 21, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 21, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollinamcollina added commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. labels Feb 23, 2023
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 23, 2023
@nodejs-github-bot
nodejs-github-bot merged commit d0531eb into nodejs:mainFeb 23, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in d0531eb

targos pushed a commit that referenced this pull request Mar 13, 2023
Updated regex for "Link" header validation to better match the
specification in RFC 8288 section 3. Does not check for valid URI
format but handles the rest of the header more permissively than
before. Alternative to another outstanding PR that disables validation
entirely.
Fixes: #46453
Refs: https://www.rfc-editor.org/rfc/rfc8288.html#section-3
Refs: #46464
PR-URL: #46466
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@targostargos mentioned this pull request Mar 14, 2023
danielleadams pushed a commit that referenced this pull request Apr 11, 2023
Updated regex for "Link" header validation to better match the
specification in RFC 8288 section 3. Does not check for valid URI
format but handles the rest of the header more permissively than
before. Alternative to another outstanding PR that disables validation
entirely.
Fixes: #46453
Refs: https://www.rfc-editor.org/rfc/rfc8288.html#section-3
Refs: #46464
PR-URL: #46466
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overzealous link header validation in writeEarlyHints

12 participants

@SRHerzog@anonrig@nodejs-github-bot@mcollina@richardlau@ShogunPanda@bnoordhuis@jasnell@Trott@lpinca@aymen94@climba03003