Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get in touch regarding a security issue #36108

Closed
JamieSlome opened this issue Sep 20, 2021 · 12 comments · Fixed by #38178
Closed

Trying to get in touch regarding a security issue #36108

JamieSlome opened this issue Sep 20, 2021 · 12 comments · Fixed by #38178

Comments

@JamieSlome
Copy link

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

@alanorozco
Copy link
Member

cc @ampproject/wg-security-privacy

@honeybadgerdontcare
Copy link
Contributor

@molnarg fyi

@ready-research
Copy link

@coreymasanto @newmuis @alanorozco Reported a security issue in huntr https://www.huntr.dev/bounties/36577e6a-67e2-4002-9586-007bdf8407d9/ long back, can you please validate this?

template = template.replace(/\${([^}]*)}/g, (_a, b) => {
is using regex which is vulnerable to ReDoS.

@jridgewell
Copy link
Contributor

Hi @ready-research: That regex shouldn't be vulnerable. The * closes over a [^}] (anything but a }), which is disjoint with the required next }. Using the following, we would see a quadratic increase in timing if it were vulnerable:

const regex = /\${([^}]*)}/;

function test(length) {
  const str = '${' + 'a'.repeat(length);
  const now = performance.now();
  regex.test(str);
  return performance.now() - now;
}

for (let i = 0; i < 500; i++) {
  console.log({ length: i, time: test(i) });
}

@ready-research
Copy link

@jridgewell Here is the POC

import {expandTemplate} from './amphtml/src/core/types/string/index.js';
for(var i = 1; i <= 500; i++) {
    var time = Date.now();
    var payload = ""+"${".repeat(i*10000)+"!"
    expandTemplate(payload)
    var stop_time = Date.now() - time;
    console.log("Payload.length:" + payload.length + ": " + stop_time+" ms");
    }

Check the Output:

Payload.length:20001: 198 ms
Payload.length:40001: 775 ms
Payload.length:60001: 1672 ms
Payload.length:80001: 2991 ms
Payload.length:100001: 5029 ms
Payload.length:120001: 7096 ms
Payload.length:140001: 9171 ms
Payload.length:160001: 11837 ms
--
--

@jridgewell
Copy link
Contributor

Ok, so this is the replace iterating until the end of the string, doesn't match, goes to next ${, iterates till end of string, doesn't match, goes to next ${, …

Thankfully, this is pretty slow increase and requires an extremely large string. We could add { to the [^}] to prevent this.

@ready-research
Copy link

Yeah, agrees with you it requires an extremely large string. Security is all about edge cases. So can you please raise a PR for this?

jridgewell added a commit to jridgewell/amphtml that referenced this issue May 10, 2022
If the input string contains many `${` which do not have a closing `}`, the `expandTemplate`'s replace will iterate the entire string at every beginning mark.

Fixes ampproject#36108.
@ready-research
Copy link

@jridgewell Tested the above fix, I can confirm that this resolves the issue. Thanks for the quick response.

Can you please mark this huntr report
https://www.huntr.dev/bounties/36577e6a-67e2-4002-9586-007bdf8407d9/ as valid using Mark as valid? Thanks.

jridgewell added a commit to jridgewell/amphtml that referenced this issue May 10, 2022
If the input string contains many `${` which do not have a closing `}`, the `expandTemplate`'s replace will iterate the entire string at every beginning mark.

Fixes ampproject#36108.
jridgewell added a commit to jridgewell/amphtml that referenced this issue May 10, 2022
If the input string contains many `${` which do not have a closing `}`, the `expandTemplate`'s replace will iterate the entire string at every beginning mark.

Fixes ampproject#36108.
jridgewell added a commit to jridgewell/amphtml that referenced this issue May 10, 2022
If the input string contains many `${` which do not have a closing `}`, the `expandTemplate`'s replace will iterate the entire string at every beginning mark.

Fixes ampproject#36108.
jridgewell added a commit that referenced this issue May 10, 2022
If the input string contains many `${` which do not have a closing `}`, the `expandTemplate`'s replace will iterate the entire string at every beginning mark.

Fixes #36108.
@JamieSlome
Copy link
Author

@jridgewell - thanks for your support here ❤️

Are you able to mark the report as fixed? You just need the commit SHA from the merge and the patched version.

You are welcome to take the reward for fixing it too!

@jridgewell
Copy link
Contributor

Is it possible to send the reward to @ready-research? I'm explicitly disallowed from taking contributions for work.

@JamieSlome
Copy link
Author

JamieSlome commented May 12, 2022

@jridgewell - we can only reward fixes to researchers if they submit patches via the report page. If you are not able to self-reward, you can select no-one as the fixer, and the funds will be returned back to the pool for your repository's future research incentives ❤️

@JamieSlome
Copy link
Author

Just for your reference @jridgewell:

Screenshot 2022-05-12 at 16 23 59

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 a pull request may close this issue.

5 participants