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

[SECURITY] substr() is deprecated and is not part of the core JS. #37135

Closed
Pranav-yadav opened this issue Apr 28, 2023 · 0 comments
Closed

[SECURITY] substr() is deprecated and is not part of the core JS. #37135

Pranav-yadav opened this issue Apr 28, 2023 · 0 comments
Labels
Impact: Security If the issue is causes a vulnerability JavaScript Resolution: Fixed A PR that fixes this issue has been merged.

Comments

@Pranav-yadav
Copy link
Contributor

Pranav-yadav commented Apr 28, 2023

substr() is deprecated and is not part of the core JS since ~2018.
No wonder why no one noticed this :)
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

So, I've refactored whole codebase to not use substr() and use slice() instead here:
PR #TBA #37136

Originally posted by @Pranav-yadav in #35993 (comment)

@Pranav-yadav Pranav-yadav added JavaScript Impact: Security If the issue is causes a vulnerability labels Apr 28, 2023
@Pranav-yadav Pranav-yadav added the Resolution: PR Submitted A pull request with a fix has been provided. label Apr 28, 2023
@Pranav-yadav Pranav-yadav changed the title substr() is deprecated and is not part of the core JS. [SECURITY] substr() is deprecated and is not part of the core JS. Apr 28, 2023
@Pranav-yadav Pranav-yadav added Resolution: Fixed A PR that fixes this issue has been merged. and removed Resolution: PR Submitted A pull request with a fix has been provided. labels May 3, 2023
jeongshin pushed a commit to jeongshin/react-native that referenced this issue May 7, 2023
…ook#37136)

Summary:
Fixes: facebook#37135

- `substr()` is not part of the core JS since ~2018
- No wonder why no one noticed this :)
- Though its supported by modern browsers, its deprecated
- Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

### Why `slice()` and not `substring()`?
> Beacuse I like pizza ;) jk

The reason, that I'm not using the most obvious alternative `substring()` is;
- It _swaps the args_ passed, when; `startIndex > endIndex` —which I think is not a property of _good_ fn
  and also does not reflects the same in it's name.
- It _doesn't support negative args_, which I think reduces flexibility to work with it.
- It could lead to more bugs in most of the cases.

### Refecrences:
- Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#differences_between_substring_and_slice
- Ref. for `slice()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
- Ref. for `substring()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

## Changelog:

[GENERAL][FIXED] - Refactor: `substr()` is deprecated, using `slice()` instead across RN codebase

Pull Request resolved: facebook#37136

Test Plan: - `yarn lint && yarn flow && yarn test-ci` --> _should be green_

Reviewed By: christophpurrer

Differential Revision: D45477910

Pulled By: jacdebug

fbshipit-source-id: 96a80893477599b9a549918924157627b9b0c3f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Security If the issue is causes a vulnerability JavaScript Resolution: Fixed A PR that fixes this issue has been merged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant