Skip to content

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.

…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
…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.

2 participants