Skip to content

Fix code scanning alert no. 21: Type confusion through parameter tampering #5

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

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

akaday
Copy link
Owner

@akaday akaday commented Nov 7, 2024

Fixes https://github.com/akaday/react/security/code-scanning/21

To fix the problem, we need to ensure that the req.query.name parameter is a string before using it. If it is not a string, we should handle it appropriately, such as by returning an error response. This can be done by adding a type check for req.query.name and ensuring it is a string before proceeding with the rest of the code.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ering

const express = require('express');
const app = express();

app.get('/source-maps', async function (req, res, next) {
  try {
    res.set('Content-type', 'application/json');
    let requestedFilePath = req.query.name;

    // Validate the input
    if (typeof requestedFilePath !== 'string') {
      throw new Error('Invalid file path');
    }

    let isCompiledOutput = false;
    if (requestedFilePath.startsWith('file://')) {
      isCompiledOutput = true;
    }

    const response = {
      mappings: 'AAAA' + ';AACA'.repeat(lines - 1),
      sourceRoot: '',
      ignoreList: requestedFilePath.includes('node_modules')
        ? [0]
        : undefined,
    };

    res.json(response);
  } catch (error) {
    next(error);
  }
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@akaday akaday marked this pull request as ready for review November 7, 2024 23:56
@akaday akaday merged commit 4912b13 into main Nov 7, 2024
8 of 11 checks passed
akaday added a commit that referenced this pull request Dec 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…ackaging/brunch/prod/fstream-1.0.12

Bump fstream from 1.0.11 to 1.0.12 in /fixtures/packaging/brunch/prod
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.

None yet

1 participant