放大和分析安全问题



我正试图弄清楚cognito是否需要放大才能与前端一起工作,或者是否有更安全的设置方法。我之所以这么问,是因为我有一个解决方案,可以使用cognito、amplifier和angular登录我的应用程序,但为了让它发挥作用,我必须将userPoolId和userPoolWebClientId之类的东西放在我的auth.service.ts文件中。从安全的角度来看,我觉得这是一件非常糟糕的事情。通常我会认为这种敏感信息会存储在后端,但我还没有看到不这样做的解决方案。

我的angular应用程序在auth.service.ts 中有这样的设置

Amplify.configure({
Auth: {
region: 'us-east-1',
userPoolId: '<my user pool id was here. Seems insecure>',
userPoolWebClientId: '<my user pool id was here. Seems insecure>',
mandatorySignIn: false,
oauth: {
domain: 'mysite.auth.us-east-1.amazoncognito.com',
scope: ['email', 'profile', 'openid'],
redirectSignIn: 'http://localhost:4200/',
redirectSignOut: 'http://localhost:4200/',
responseType: 'code'
}
}
});

const POOL_DATA = {
UserPoolId: '<my user pool id was here. Seems insecure>',
ClientId: '<my client id was here. Seems insecure>'
};
const userPool = new CognitoUserPool(POOL_DATA);
...

我有什么东西不见了吗。有没有更安全的方法在前端实现这一点?

在没有池id的情况下,没有在前端使用AWS Cognito的选项;web客户端id。

我建议您将凭据保存在environment.ts文件中,而不是保存在服务文件中。

  1. 将凭据添加到环境.ts

    export const environment = {
    production: false,
    envName: 'dev',
    cognitoUserPoolId: <secure credential>,
    cognitoClientId: <secure credential>
    }
    
  2. 创建一个config.ts文件作为抽象层。

    import { environment } from '<your folder path>/environments/environment';
    export const CONFIG = {
    UserPoolId: environment.cognitoUserPoolId,
    ClientId: environment.cognitoClientId,
    }
    
  3. 在auth.service.ts 中导入配置文件

    import { CONFIG } from '<your folder path>/config';
    Amplify.configure({
    Auth: {
    region: 'us-east-1',
    userPoolId: CONFIG.UserPoolId,
    userPoolWebClientId: CONFIG.ClientId,
    mandatorySignIn: false
    }
    });
    

这样凭据就不会暴露在外部世界。希望这是有道理的。

您有权质疑您在前端输入的所有内容,但这些ID并不敏感。如果我想通过您的申请进行身份验证,我仍然需要向您选择的身份提供者之一证明我的身份声明。

想想其他web应用程序的实现。您可以有一个后端REST端点,它接受包含身份验证凭据的post请求。事实上,我可以看到javascript代码并提取登录端点的url,这并没有使其不安全。

使用授权控制在后端保护您的敏感数据。然后,您应该(相对(安全地假设,虽然每个人都可以加载前端代码资源,但除非具有适当的有效令牌,否则他们对后端资源的任何请求都将被拒绝。

本问答内容更为详细。

最新更新